Skip to content

Commit d15f113

Browse files
committed
fixes failing test
1 parent 372924d commit d15f113

1 file changed

Lines changed: 40 additions & 20 deletions

File tree

src/execution/__tests__/execute-diagnostics-test.ts

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { expect } from 'chai';
1+
import { assert, expect } from 'chai';
22
import { afterEach, describe, it } from 'mocha';
33

44
import {
55
collectEvents,
66
getTracingChannel,
77
} from '../../__testUtils__/diagnosticsTestUtils.js';
88

9+
import { isAsyncIterable } from '../../jsutils/isAsyncIterable.js';
10+
911
import { parse } from '../../language/parser.js';
1012

1113
import { buildSchema } from '../../utilities/buildASTSchema.js';
1214

13-
import type { ExecutionArgs } from '../execute.js';
1415
import {
1516
execute,
1617
executeIgnoringIncremental,
17-
executeSubscriptionEvent,
1818
executeSync,
19-
validateExecutionArgs,
19+
subscribe,
2020
} from '../execute.js';
2121

2222
const schema = buildSchema(`
@@ -109,30 +109,50 @@ describe('execute diagnostics channel', () => {
109109
]);
110110
});
111111

112-
it('emits for each executeSubscriptionEvent call with resolved operation ctx', () => {
113-
const args: ExecutionArgs = {
114-
schema,
115-
document: parse('query Q { sync }'),
116-
rootValue,
117-
};
118-
const validated = validateExecutionArgs(args);
119-
if (!('schema' in validated)) {
120-
throw new Error('unexpected validation failure');
112+
it('emits for each subscription event with resolved operation ctx', async () => {
113+
const subscriptionSchema = buildSchema(`
114+
type Query {
115+
dummy: String
116+
}
117+
118+
type Subscription {
119+
tick: String
120+
}
121+
`);
122+
123+
async function* tickGenerator() {
124+
await Promise.resolve();
125+
yield { tick: 'one' };
126+
yield { tick: 'two' };
121127
}
122128

129+
const document = parse('subscription S { tick }');
130+
123131
active = collectEvents(executeChannel);
124132

125-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
126-
executeSubscriptionEvent(validated);
127-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
128-
executeSubscriptionEvent(validated);
133+
const subscription = await subscribe({
134+
schema: subscriptionSchema,
135+
document,
136+
rootValue: { tick: tickGenerator },
137+
});
138+
assert(isAsyncIterable(subscription));
139+
140+
expect(await subscription.next()).to.deep.equal({
141+
done: false,
142+
value: { data: { tick: 'one' } },
143+
});
144+
expect(await subscription.next()).to.deep.equal({
145+
done: false,
146+
value: { data: { tick: 'two' } },
147+
});
129148

130149
const starts = active.events.filter((e) => e.kind === 'start');
131150
expect(starts.length).to.equal(2);
132151
for (const ev of starts) {
133-
expect(ev.ctx.operationType).to.equal('query');
134-
expect(ev.ctx.operationName).to.equal('Q');
135-
expect(ev.ctx.schema).to.equal(schema);
152+
expect(ev.ctx.operationType).to.equal('subscription');
153+
expect(ev.ctx.operationName).to.equal('S');
154+
expect(ev.ctx.operation).to.equal(document.definitions[0]);
155+
expect(ev.ctx.schema).to.equal(subscriptionSchema);
136156
}
137157
});
138158

0 commit comments

Comments
 (0)