Skip to content

Commit e272823

Browse files
committed
refactor test
1 parent 9680b06 commit e272823

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/execution/__tests__/stream-test.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ async function complete(document) {
131131
return result;
132132
}
133133

134+
async function completeAsync(document, numCalls) {
135+
const schema = new GraphQLSchema({ query });
136+
137+
const result = await execute({ schema, document, rootValue: {} });
138+
139+
if (isAsyncIterable(result)) {
140+
const promises = [];
141+
for (let i = 0; i < numCalls; i++) {
142+
promises.push(result.next());
143+
}
144+
return Promise.all(promises);
145+
}
146+
return result;
147+
}
148+
134149
describe('Execute: stream directive', () => {
135150
it('Can stream a list field', async () => {
136151
const document = parse('{ scalarList @stream(initialCount: 1) }');
@@ -398,22 +413,8 @@ describe('Execute: stream directive', () => {
398413
}
399414
}
400415
`);
401-
const schema = new GraphQLSchema({ query });
402-
403-
const result = await execute({ schema, document, rootValue: {} });
404-
405-
const results = [];
406-
if (isAsyncIterable(result)) {
407-
const asyncResults = await Promise.all([
408-
result.next(),
409-
result.next(),
410-
result.next(),
411-
result.next(),
412-
]);
413-
results.push(...asyncResults);
414-
}
415-
416-
expect(results).to.deep.equal([
416+
const result = await completeAsync(document, 4);
417+
expect(result).to.deep.equal([
417418
{
418419
done: false,
419420
value: {

0 commit comments

Comments
 (0)