Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit a8ac0c1

Browse files
committed
test(iterators): Fix test wait. Remove console.log.
1 parent a5d8d52 commit a8ac0c1

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

test/unit/iterators.test.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const WAIT = 20
1111
async function* generate(items = expected, waitTime = WAIT) {
1212
await wait(waitTime * 0.1)
1313
for await (const item of items) {
14-
console.log('next', item)
1514
await wait(waitTime * 0.1)
1615
yield item
1716
await wait(waitTime * 0.1)
@@ -671,34 +670,29 @@ describe('Iterator Utils', () => {
671670
})
672671

673672
it('can handle errs when queued next calls', async () => {
674-
const done = Defer()
675673
const expectedError = new Error('expected')
676-
try {
677-
const itr = CancelableGenerator((async function* Gen() {
678-
yield* generate(expected, 1000)
679-
}()), onFinally, {
680-
timeout: WAIT,
681-
})
674+
const itr = CancelableGenerator((async function* Gen() {
675+
yield* generate(expected, 1000)
676+
}()), onFinally, {
677+
timeout: WAIT,
678+
})
682679

683-
const tasks = expected.map(async () => itr.next())
684-
await wait(100)
685-
await itr.cancel(expectedError)
686-
const result = Promise.allSettled(tasks)
687-
// first is error
688-
expect(result[0]).toEqual({ status: 'rejected', reason: expectedError })
689-
// rest is undefined result
690-
// not sure what good behaviour should be in this case
691-
expect(result.slice(1)).toEqual(result.slice(1).map(() => ({
692-
status: 'fulfilled',
693-
value: {
694-
value: undefined,
695-
done: true
696-
}
697-
})))
698-
expect(itr.isCancelled()).toEqual(true)
699-
} finally {
700-
await done
701-
}
680+
const tasks = expected.map(async () => itr.next())
681+
await wait(100)
682+
await itr.cancel(expectedError)
683+
const result = await Promise.allSettled(tasks)
684+
// first is error
685+
expect(result[0]).toEqual({ status: 'rejected', reason: expectedError })
686+
// rest is undefined result
687+
// not sure what good behaviour should be in this case
688+
expect(result.slice(1)).toEqual(result.slice(1).map(() => ({
689+
status: 'fulfilled',
690+
value: {
691+
value: undefined,
692+
done: true
693+
}
694+
})))
695+
expect(itr.isCancelled()).toEqual(true)
702696
}, 10000)
703697

704698
it('can handle queued next calls resolving out of order', async () => {

0 commit comments

Comments
 (0)