Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Mar 21, 2021
1 parent 9680b06 commit e272823
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/execution/__tests__/stream-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ async function complete(document) {
return result;
}

async function completeAsync(document, numCalls) {
const schema = new GraphQLSchema({ query });

const result = await execute({ schema, document, rootValue: {} });

if (isAsyncIterable(result)) {
const promises = [];
for (let i = 0; i < numCalls; i++) {
promises.push(result.next());
}
return Promise.all(promises);
}
return result;
}

describe('Execute: stream directive', () => {
it('Can stream a list field', async () => {
const document = parse('{ scalarList @stream(initialCount: 1) }');
Expand Down Expand Up @@ -398,22 +413,8 @@ describe('Execute: stream directive', () => {
}
}
`);
const schema = new GraphQLSchema({ query });

const result = await execute({ schema, document, rootValue: {} });

const results = [];
if (isAsyncIterable(result)) {
const asyncResults = await Promise.all([
result.next(),
result.next(),
result.next(),
result.next(),
]);
results.push(...asyncResults);
}

expect(results).to.deep.equal([
const result = await completeAsync(document, 4);
expect(result).to.deep.equal([
{
done: false,
value: {
Expand Down

0 comments on commit e272823

Please sign in to comment.