Skip to content

Commit e1cb754

Browse files
authored
polish: clean up stream tests (#4695)
These tests are deterministic => they should act like it.
1 parent c4d3573 commit e1cb754

2 files changed

Lines changed: 12 additions & 38 deletions

File tree

src/execution/incremental/__tests__/stream-test.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3851,25 +3851,12 @@ describe('Execute: stream directive (cancellation)', () => {
38513851
abortController.abort();
38523852
await resolveOnNextTick();
38533853

3854-
let firstResult:
3855-
| IteratorResult<SubsequentIncrementalExecutionResult>
3856-
| undefined;
3857-
try {
3858-
firstResult =
3859-
(await nextResultPromise) as IteratorResult<SubsequentIncrementalExecutionResult>;
3860-
} catch (error) {
3861-
expect(error).to.be.instanceOf(Error);
3862-
expect((error as Error).message).to.equal('This operation was aborted');
3863-
}
3864-
if (firstResult && !firstResult.done) {
3865-
try {
3866-
const followUp = await iterator.next();
3867-
expect(followUp.done).to.equal(true);
3868-
} catch (error) {
3869-
expect(error).to.be.instanceOf(Error);
3870-
expect((error as Error).message).to.equal('This operation was aborted');
3871-
}
3872-
}
3854+
await expectPromise(nextResultPromise).toRejectWith(
3855+
'This operation was aborted',
3856+
);
3857+
await resolveOnNextTick();
3858+
const followUp = await iterator.next();
3859+
expect(followUp.done).to.equal(true);
38733860
expect(streamReturnCount).to.equal(1);
38743861

38753862
const priorStreamReturnCount = streamReturnCount;

src/execution/legacyIncremental/__tests__/legacy-stream-test.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,25 +3640,12 @@ describe('Execute: stream directive (legacy cancellation)', () => {
36403640
abortController.abort();
36413641
await resolveOnNextTick();
36423642

3643-
let firstResult:
3644-
| IteratorResult<LegacySubsequentIncrementalExecutionResult>
3645-
| undefined;
3646-
try {
3647-
firstResult =
3648-
(await nextResultPromise) as IteratorResult<LegacySubsequentIncrementalExecutionResult>;
3649-
} catch (error) {
3650-
expect(error).to.be.instanceOf(Error);
3651-
expect((error as Error).message).to.equal('This operation was aborted');
3652-
}
3653-
if (firstResult && !firstResult.done) {
3654-
try {
3655-
const followUp = await iterator.next();
3656-
expect(followUp.done).to.equal(true);
3657-
} catch (error) {
3658-
expect(error).to.be.instanceOf(Error);
3659-
expect((error as Error).message).to.equal('This operation was aborted');
3660-
}
3661-
}
3643+
await expectPromise(nextResultPromise).toRejectWith(
3644+
'This operation was aborted',
3645+
);
3646+
await resolveOnNextTick();
3647+
const followUp = await iterator.next();
3648+
expect(followUp.done).to.equal(true);
36623649
expect(streamReturnCount).to.equal(1);
36633650

36643651
const priorStreamReturnCount = streamReturnCount;

0 commit comments

Comments
 (0)