Skip to content

Commit 367e307

Browse files
IvanGoncharovleebyron
authored andcommitted
Test: Cleanup unneeded returns and async/await (#1310)
* Remove excessive 'return' from tests * Remove unneeded async/await
1 parent 4d2438a commit 367e307

File tree

7 files changed

+90
-139
lines changed

7 files changed

+90
-139
lines changed

src/execution/__tests__/executor-test.js

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Execute: Handles basic execution tasks', () => {
4141
).to.throw('Expected undefined to be a GraphQL schema.');
4242
});
4343

44-
it('accepts an object with named properties as arguments', async () => {
44+
it('accepts an object with named properties as arguments', () => {
4545
const doc = 'query Example { a }';
4646

4747
const data = 'rootValue';
@@ -60,7 +60,7 @@ describe('Execute: Handles basic execution tasks', () => {
6060
}),
6161
});
6262

63-
const result = await execute({
63+
const result = execute({
6464
schema,
6565
document: parse(doc),
6666
rootValue: data,
@@ -215,7 +215,7 @@ describe('Execute: Handles basic execution tasks', () => {
215215
).to.deep.equal(expected);
216216
});
217217

218-
it('merges parallel fragments', async () => {
218+
it('merges parallel fragments', () => {
219219
const ast = parse(`
220220
{ a, ...FragOne, ...FragTwo }
221221
@@ -241,7 +241,7 @@ describe('Execute: Handles basic execution tasks', () => {
241241
});
242242
const schema = new GraphQLSchema({ query: Type });
243243

244-
expect(await execute(schema, ast)).to.deep.equal({
244+
expect(execute(schema, ast)).to.deep.equal({
245245
data: {
246246
a: 'Apple',
247247
b: 'Banana',
@@ -258,7 +258,7 @@ describe('Execute: Handles basic execution tasks', () => {
258258
});
259259
});
260260

261-
it('provides info about current execution state', async () => {
261+
it('provides info about current execution state', () => {
262262
const ast = parse('query ($var: String) { result: test }');
263263

264264
let info;
@@ -279,7 +279,7 @@ describe('Execute: Handles basic execution tasks', () => {
279279

280280
const rootValue = { root: 'val' };
281281

282-
await execute(schema, ast, rootValue, null, { var: 123 });
282+
execute(schema, ast, rootValue, null, { var: 123 });
283283

284284
expect(Object.keys(info)).to.deep.equal([
285285
'fieldName',
@@ -307,7 +307,7 @@ describe('Execute: Handles basic execution tasks', () => {
307307
expect(info.variableValues).to.deep.equal({ var: '123' });
308308
});
309309

310-
it('threads root value context correctly', async () => {
310+
it('threads root value context correctly', () => {
311311
const doc = 'query Example { a }';
312312

313313
const data = {
@@ -330,12 +330,12 @@ describe('Execute: Handles basic execution tasks', () => {
330330
}),
331331
});
332332

333-
await execute(schema, parse(doc), data);
333+
execute(schema, parse(doc), data);
334334

335335
expect(resolvedRootValue.contextThing).to.equal('thing');
336336
});
337337

338-
it('correctly threads arguments', async () => {
338+
it('correctly threads arguments', () => {
339339
const doc = `
340340
query Example {
341341
b(numArg: 123, stringArg: "foo")
@@ -362,7 +362,7 @@ describe('Execute: Handles basic execution tasks', () => {
362362
}),
363363
});
364364

365-
await execute(schema, parse(doc));
365+
execute(schema, parse(doc));
366366

367367
expect(resolvedArgs.numArg).to.equal(123);
368368
expect(resolvedArgs.stringArg).to.equal('foo');
@@ -603,7 +603,7 @@ describe('Execute: Handles basic execution tasks', () => {
603603
});
604604
});
605605

606-
it('Full response path is included for non-nullable fields', async () => {
606+
it('Full response path is included for non-nullable fields', () => {
607607
const A = new GraphQLObjectType({
608608
name: 'A',
609609
fields: () => ({
@@ -650,7 +650,7 @@ describe('Execute: Handles basic execution tasks', () => {
650650
}
651651
`;
652652

653-
const result = await execute(schema, parse(query));
653+
const result = execute(schema, parse(query));
654654
expect(result).to.deep.equal({
655655
data: {
656656
nullableA: {
@@ -667,7 +667,7 @@ describe('Execute: Handles basic execution tasks', () => {
667667
});
668668
});
669669

670-
it('uses the inline operation if no operation name is provided', async () => {
670+
it('uses the inline operation if no operation name is provided', () => {
671671
const doc = '{ a }';
672672
const data = { a: 'b' };
673673
const ast = parse(doc);
@@ -680,12 +680,12 @@ describe('Execute: Handles basic execution tasks', () => {
680680
}),
681681
});
682682

683-
const result = await execute(schema, ast, data);
683+
const result = execute(schema, ast, data);
684684

685685
expect(result).to.deep.equal({ data: { a: 'b' } });
686686
});
687687

688-
it('uses the only operation if no operation name is provided', async () => {
688+
it('uses the only operation if no operation name is provided', () => {
689689
const doc = 'query Example { a }';
690690
const data = { a: 'b' };
691691
const ast = parse(doc);
@@ -698,12 +698,12 @@ describe('Execute: Handles basic execution tasks', () => {
698698
}),
699699
});
700700

701-
const result = await execute(schema, ast, data);
701+
const result = execute(schema, ast, data);
702702

703703
expect(result).to.deep.equal({ data: { a: 'b' } });
704704
});
705705

706-
it('uses the named operation if operation name is provided', async () => {
706+
it('uses the named operation if operation name is provided', () => {
707707
const doc = 'query Example { first: a } query OtherExample { second: a }';
708708
const data = { a: 'b' };
709709
const ast = parse(doc);
@@ -716,12 +716,12 @@ describe('Execute: Handles basic execution tasks', () => {
716716
}),
717717
});
718718

719-
const result = await execute(schema, ast, data, null, null, 'OtherExample');
719+
const result = execute(schema, ast, data, null, null, 'OtherExample');
720720

721721
expect(result).to.deep.equal({ data: { second: 'b' } });
722722
});
723723

724-
it('provides error if no operation is provided', async () => {
724+
it('provides error if no operation is provided', () => {
725725
const doc = 'fragment Example on Type { a }';
726726
const data = { a: 'b' };
727727
const ast = parse(doc);
@@ -734,13 +734,13 @@ describe('Execute: Handles basic execution tasks', () => {
734734
}),
735735
});
736736

737-
const result = await execute(schema, ast, data);
737+
const result = execute(schema, ast, data);
738738
expect(result).to.deep.equal({
739739
errors: [{ message: 'Must provide an operation.' }],
740740
});
741741
});
742742

743-
it('errors if no op name is provided with multiple operations', async () => {
743+
it('errors if no op name is provided with multiple operations', () => {
744744
const doc = 'query Example { a } query OtherExample { a }';
745745
const data = { a: 'b' };
746746
const ast = parse(doc);
@@ -753,7 +753,7 @@ describe('Execute: Handles basic execution tasks', () => {
753753
}),
754754
});
755755

756-
const result = await execute(schema, ast, data);
756+
const result = execute(schema, ast, data);
757757
expect(result).to.deep.equal({
758758
errors: [
759759
{
@@ -764,7 +764,7 @@ describe('Execute: Handles basic execution tasks', () => {
764764
});
765765
});
766766

767-
it('errors if unknown operation name is provided', async () => {
767+
it('errors if unknown operation name is provided', () => {
768768
const doc = 'query Example { a } query OtherExample { a }';
769769
const ast = parse(doc);
770770
const schema = new GraphQLSchema({
@@ -776,7 +776,7 @@ describe('Execute: Handles basic execution tasks', () => {
776776
}),
777777
});
778778

779-
const result = await execute({
779+
const result = execute({
780780
schema,
781781
document: ast,
782782
operationName: 'UnknownExample',
@@ -786,7 +786,7 @@ describe('Execute: Handles basic execution tasks', () => {
786786
});
787787
});
788788

789-
it('uses the query schema for queries', async () => {
789+
it('uses the query schema for queries', () => {
790790
const doc = 'query Q { a } mutation M { c } subscription S { a }';
791791
const data = { a: 'b', c: 'd' };
792792
const ast = parse(doc);
@@ -811,12 +811,12 @@ describe('Execute: Handles basic execution tasks', () => {
811811
}),
812812
});
813813

814-
const queryResult = await execute(schema, ast, data, null, {}, 'Q');
814+
const queryResult = execute(schema, ast, data, null, {}, 'Q');
815815

816816
expect(queryResult).to.deep.equal({ data: { a: 'b' } });
817817
});
818818

819-
it('uses the mutation schema for mutations', async () => {
819+
it('uses the mutation schema for mutations', () => {
820820
const doc = 'query Q { a } mutation M { c }';
821821
const data = { a: 'b', c: 'd' };
822822
const ast = parse(doc);
@@ -835,12 +835,12 @@ describe('Execute: Handles basic execution tasks', () => {
835835
}),
836836
});
837837

838-
const mutationResult = await execute(schema, ast, data, null, {}, 'M');
838+
const mutationResult = execute(schema, ast, data, null, {}, 'M');
839839

840840
expect(mutationResult).to.deep.equal({ data: { c: 'd' } });
841841
});
842842

843-
it('uses the subscription schema for subscriptions', async () => {
843+
it('uses the subscription schema for subscriptions', () => {
844844
const doc = 'query Q { a } subscription S { a }';
845845
const data = { a: 'b', c: 'd' };
846846
const ast = parse(doc);
@@ -859,7 +859,7 @@ describe('Execute: Handles basic execution tasks', () => {
859859
}),
860860
});
861861

862-
const subscriptionResult = await execute(schema, ast, data, null, {}, 'S');
862+
const subscriptionResult = execute(schema, ast, data, null, {}, 'S');
863863

864864
expect(subscriptionResult).to.deep.equal({ data: { a: 'b' } });
865865
});
@@ -920,7 +920,7 @@ describe('Execute: Handles basic execution tasks', () => {
920920
expect(Object.keys(result.data)).to.deep.equal(['a', 'b', 'c', 'd', 'e']);
921921
});
922922

923-
it('Avoids recursion', async () => {
923+
it('Avoids recursion', () => {
924924
const doc = `
925925
query Q {
926926
a
@@ -944,12 +944,12 @@ describe('Execute: Handles basic execution tasks', () => {
944944
}),
945945
});
946946

947-
const queryResult = await execute(schema, ast, data, null, {}, 'Q');
947+
const queryResult = execute(schema, ast, data, null, {}, 'Q');
948948

949949
expect(queryResult).to.deep.equal({ data: { a: 'b' } });
950950
});
951951

952-
it('does not include illegal fields in output', async () => {
952+
it('does not include illegal fields in output', () => {
953953
const doc = `mutation M {
954954
thisIsIllegalDontIncludeMe
955955
}`;
@@ -969,14 +969,14 @@ describe('Execute: Handles basic execution tasks', () => {
969969
}),
970970
});
971971

972-
const mutationResult = await execute(schema, ast);
972+
const mutationResult = execute(schema, ast);
973973

974974
expect(mutationResult).to.deep.equal({
975975
data: {},
976976
});
977977
});
978978

979-
it('does not include arguments that were not set', async () => {
979+
it('does not include arguments that were not set', () => {
980980
const schema = new GraphQLSchema({
981981
query: new GraphQLObjectType({
982982
name: 'Type',
@@ -997,7 +997,7 @@ describe('Execute: Handles basic execution tasks', () => {
997997
});
998998

999999
const query = parse('{ field(a: true, c: false, e: 0) }');
1000-
const result = await execute(schema, query);
1000+
const result = execute(schema, query);
10011001

10021002
expect(result).to.deep.equal({
10031003
data: {
@@ -1006,7 +1006,7 @@ describe('Execute: Handles basic execution tasks', () => {
10061006
});
10071007
});
10081008

1009-
it('fails when an isTypeOf check is not met', async () => {
1009+
it('fails when an isTypeOf check is not met', () => {
10101010
class Special {
10111011
constructor(value) {
10121012
this.value = value;
@@ -1045,7 +1045,7 @@ describe('Execute: Handles basic execution tasks', () => {
10451045
const value = {
10461046
specials: [new Special('foo'), new NotSpecial('bar')],
10471047
};
1048-
const result = await execute(schema, query, value);
1048+
const result = execute(schema, query, value);
10491049

10501050
expect(result).to.deep.equal({
10511051
data: {
@@ -1062,7 +1062,7 @@ describe('Execute: Handles basic execution tasks', () => {
10621062
});
10631063
});
10641064

1065-
it('executes ignoring invalid non-executable definitions', async () => {
1065+
it('executes ignoring invalid non-executable definitions', () => {
10661066
const query = parse(`
10671067
{ foo }
10681068
@@ -1078,16 +1078,16 @@ describe('Execute: Handles basic execution tasks', () => {
10781078
}),
10791079
});
10801080

1081-
const result = await execute(schema, query);
1081+
const result = execute(schema, query);
10821082
expect(result).to.deep.equal({
10831083
data: {
10841084
foo: null,
10851085
},
10861086
});
10871087
});
10881088

1089-
it('uses a custom field resolver', async () => {
1090-
const query = parse('{ foo }');
1089+
it('uses a custom field resolver', () => {
1090+
const document = parse('{ foo }');
10911091

10921092
const schema = new GraphQLSchema({
10931093
query: new GraphQLObjectType({
@@ -1103,15 +1103,7 @@ describe('Execute: Handles basic execution tasks', () => {
11031103
return info.fieldName;
11041104
}
11051105

1106-
const result = await execute(
1107-
schema,
1108-
query,
1109-
null,
1110-
null,
1111-
null,
1112-
null,
1113-
customResolver,
1114-
);
1106+
const result = execute({ schema, document, fieldResolver: customResolver });
11151107

11161108
expect(result).to.deep.equal({ data: { foo: 'foo' } });
11171109
});

src/execution/__tests__/mutations-test.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,13 @@ describe('Execute: Handles mutation execution ordering', () => {
122122

123123
const mutationResult = await execute(schema, parse(doc), new Root(6));
124124

125-
return expect(mutationResult).to.deep.equal({
125+
expect(mutationResult).to.deep.equal({
126126
data: {
127-
first: {
128-
theNumber: 1,
129-
},
130-
second: {
131-
theNumber: 2,
132-
},
133-
third: {
134-
theNumber: 3,
135-
},
136-
fourth: {
137-
theNumber: 4,
138-
},
139-
fifth: {
140-
theNumber: 5,
141-
},
127+
first: { theNumber: 1 },
128+
second: { theNumber: 2 },
129+
third: { theNumber: 3 },
130+
fourth: { theNumber: 4 },
131+
fifth: { theNumber: 5 },
142132
},
143133
});
144134
});

0 commit comments

Comments
 (0)