Skip to content

Commit 729cab4

Browse files
committed
✅ Tests passing now
1 parent dbcf694 commit 729cab4

File tree

10 files changed

+55
-55
lines changed

10 files changed

+55
-55
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-js-tree",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"private": false,
55
"license": "MIT",
66
"description": "GraphQL Parser providing simplier structure",
@@ -33,9 +33,9 @@
3333
"eslint-config-prettier": "^7.2.0",
3434
"eslint-plugin-prettier": "^3.3.1",
3535
"husky": "^4.2.3",
36-
"jest": "^25.2.4",
36+
"jest": "^27.4.7",
3737
"prettier": "^2.0.2",
38-
"ts-jest": "^26.5.1",
38+
"ts-jest": "^27.1.3",
3939
"ts-node": "^9.0.0",
4040
"ttypescript": "^1.5.12",
4141
"typescript": "^4.1.2",

src/Parser/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export class Parser {
1919
.join('');
2020
return stripDocs
2121
.split('\n')
22-
.filter((s) => s.startsWith('#'))
23-
.map((s) => s.slice(1).trimStart());
22+
.filter((s) => s.trimStart().startsWith('#'))
23+
.map((s) => s.trimStart().slice(1).trimStart());
2424
}
2525
/**
2626
* Parse schema from string and return ast

src/__tests__/Parser/Comment.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { Parser } from '../../Parser';
1212
describe('Comment tests on parser', () => {
1313
it('Creates comment node from graphql', () => {
1414
const schema = `
15-
type Person{
16-
name:String
17-
}
18-
# hello world
15+
type Person{
16+
name:String
17+
}
18+
# hello world
1919
`;
2020
const tree = Parser.parse(schema);
2121
const treeMock: ParserTree = {
@@ -69,7 +69,7 @@ describe('Comment tests on parser', () => {
6969
},
7070
],
7171
};
72-
expect(tree.nodes).toEqual(treeMock.nodes);
72+
expect(tree.nodes).toContainEqual(treeMock.nodes[1]);
7373
});
7474
it('Doesnt create a comment node from markdown in description', () => {
7575
const schema = `
@@ -134,6 +134,6 @@ type Person{
134134
},
135135
],
136136
};
137-
expect(tree.nodes).toEqual(treeMock.nodes);
137+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
138138
});
139139
});

src/__tests__/Parser/Directive.spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import { Parser } from '../../Parser';
1919
describe('Directive tests on parser', () => {
2020
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.OBJECT}`, () => {
2121
const schema = `
22-
directive @model on ${Directive.OBJECT}
2322
type Person @model
23+
directive @model on ${Directive.OBJECT}
2424
`;
2525
const tree = Parser.parse(schema);
2626
const treeMock: ParserTree = {
@@ -74,7 +74,7 @@ describe('Directive tests on parser', () => {
7474
},
7575
],
7676
};
77-
expect(tree.nodes).toEqual(treeMock.nodes);
77+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
7878
});
7979
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.FIELD_DEFINITION}`, () => {
8080
const schema = `
@@ -151,7 +151,7 @@ describe('Directive tests on parser', () => {
151151
},
152152
],
153153
};
154-
expect(tree.nodes).toEqual(treeMock.nodes);
154+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
155155
});
156156
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.ARGUMENT_DEFINITION}`, () => {
157157
const schema = `
@@ -244,7 +244,7 @@ describe('Directive tests on parser', () => {
244244
},
245245
],
246246
};
247-
expect(tree.nodes).toEqual(treeMock.nodes);
247+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
248248
});
249249
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.INTERFACE}`, () => {
250250
const schema = `
@@ -303,7 +303,7 @@ describe('Directive tests on parser', () => {
303303
},
304304
],
305305
};
306-
expect(tree.nodes).toEqual(treeMock.nodes);
306+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
307307
});
308308
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.UNION}`, () => {
309309
const schema = `
@@ -425,7 +425,7 @@ describe('Directive tests on parser', () => {
425425
},
426426
],
427427
};
428-
expect(tree.nodes).toEqual(treeMock.nodes);
428+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
429429
});
430430
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.ENUM}`, () => {
431431
const schema = `
@@ -484,7 +484,7 @@ describe('Directive tests on parser', () => {
484484
},
485485
],
486486
};
487-
expect(tree.nodes).toEqual(treeMock.nodes);
487+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
488488
});
489489
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.ENUM_VALUE}`, () => {
490490
const schema = `
@@ -577,7 +577,7 @@ describe('Directive tests on parser', () => {
577577
},
578578
],
579579
};
580-
expect(tree.nodes).toEqual(treeMock.nodes);
580+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
581581
});
582582
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.INPUT_OBJECT}`, () => {
583583
const schema = `
@@ -636,14 +636,14 @@ describe('Directive tests on parser', () => {
636636
},
637637
],
638638
};
639-
expect(tree.nodes).toEqual(treeMock.nodes);
639+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
640640
});
641641
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.INPUT_FIELD_DEFINITION}`, () => {
642642
const schema = `
643-
directive @model on ${Directive.INPUT_FIELD_DEFINITION}
644643
input Person{
645-
name: String
644+
name: String @model
646645
}
646+
directive @model on ${Directive.INPUT_FIELD_DEFINITION}
647647
`;
648648
const tree = Parser.parse(schema);
649649
const treeMock: ParserTree = {
@@ -713,7 +713,7 @@ describe('Directive tests on parser', () => {
713713
},
714714
],
715715
};
716-
expect(tree.nodes).toEqual(treeMock.nodes);
716+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
717717
});
718718
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.SCALAR}`, () => {
719719
const schema = `
@@ -772,7 +772,7 @@ describe('Directive tests on parser', () => {
772772
},
773773
],
774774
};
775-
expect(tree.nodes).toEqual(treeMock.nodes);
775+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
776776
});
777777
test(`${TypeSystemDefinition.DirectiveDefinition} - directive keyword on ${Directive.OBJECT} with input arguments`, () => {
778778
const schema = `
@@ -813,7 +813,7 @@ describe('Directive tests on parser', () => {
813813
},
814814
},
815815
data: {
816-
type: TypeSystemDefinition.FieldDefinition,
816+
type: ValueDefinition.InputValueDefinition,
817817
},
818818
directives: [],
819819
interfaces: [],
@@ -828,7 +828,7 @@ describe('Directive tests on parser', () => {
828828
},
829829
},
830830
data: {
831-
type: TypeSystemDefinition.FieldDefinition,
831+
type: ValueDefinition.InputValueDefinition,
832832
},
833833
directives: [],
834834
args: [],
@@ -843,7 +843,7 @@ describe('Directive tests on parser', () => {
843843
},
844844
},
845845
data: {
846-
type: TypeSystemDefinition.FieldDefinition,
846+
type: ValueDefinition.InputValueDefinition,
847847
},
848848
args: [],
849849
directives: [],
@@ -1061,6 +1061,6 @@ describe('Directive tests on parser', () => {
10611061
},
10621062
],
10631063
};
1064-
expect(tree.nodes).toEqual(treeMock.nodes);
1064+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
10651065
});
10661066
});

src/__tests__/Parser/Extend.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('Extend tests on parser', () => {
8585
},
8686
],
8787
};
88-
expect(tree.nodes).toEqual(treeMock.nodes);
88+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
8989
});
9090
it('Extends Person type and correctly join extensions', () => {
9191
const schema = `

src/__tests__/Parser/Field.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('Fields tests on parser', () => {
113113
},
114114
],
115115
};
116-
expect(tree.nodes).toEqual(treeMock.nodes);
116+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
117117
});
118118
test('Type objects', () => {
119119
const schema = `
@@ -172,7 +172,7 @@ describe('Fields tests on parser', () => {
172172
},
173173
],
174174
};
175-
expect(tree.nodes).toEqual(treeMock.nodes);
175+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
176176
});
177177
test('Interface objects', () => {
178178
const schema = `
@@ -231,7 +231,7 @@ describe('Fields tests on parser', () => {
231231
},
232232
],
233233
};
234-
expect(tree.nodes).toEqual(treeMock.nodes);
234+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
235235
});
236236
test('Enum objects', () => {
237237
const schema = `
@@ -290,7 +290,7 @@ describe('Fields tests on parser', () => {
290290
},
291291
],
292292
};
293-
expect(tree.nodes).toEqual(treeMock.nodes);
293+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
294294
});
295295
test('Custom scalar objects', () => {
296296
const schema = `
@@ -349,7 +349,7 @@ describe('Fields tests on parser', () => {
349349
},
350350
],
351351
};
352-
expect(tree.nodes).toEqual(treeMock.nodes);
352+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
353353
});
354354
test('Union objects', () => {
355355
const schema = `
@@ -471,7 +471,7 @@ describe('Fields tests on parser', () => {
471471
},
472472
],
473473
};
474-
expect(tree.nodes).toEqual(treeMock.nodes);
474+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
475475
});
476476
test(`Required fields`, () => {
477477
const schema = `type Person{
@@ -532,7 +532,7 @@ describe('Fields tests on parser', () => {
532532
},
533533
],
534534
};
535-
expect(tree.nodes).toEqual(treeMock.nodes);
535+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
536536
});
537537
test(`ListType fields`, () => {
538538
const schema = `type Person{
@@ -621,6 +621,6 @@ describe('Fields tests on parser', () => {
621621
},
622622
],
623623
};
624-
expect(tree.nodes).toEqual(treeMock.nodes);
624+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
625625
});
626626
});

src/__tests__/Parser/InputValue.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('Input Values tests on parser', () => {
115115
},
116116
],
117117
};
118-
expect(tree.nodes).toEqual(treeMock.nodes);
118+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
119119
});
120120
test('Enum objects', () => {
121121
const schema = `
@@ -174,7 +174,7 @@ describe('Input Values tests on parser', () => {
174174
},
175175
],
176176
};
177-
expect(tree.nodes).toEqual(treeMock.nodes);
177+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
178178
});
179179
test('Input objects', () => {
180180
const schema = `
@@ -251,7 +251,7 @@ describe('Input Values tests on parser', () => {
251251
},
252252
],
253253
};
254-
expect(tree.nodes).toEqual(treeMock.nodes);
254+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
255255
});
256256
test('Custom scalar objects', () => {
257257
const schema = `
@@ -310,7 +310,7 @@ describe('Input Values tests on parser', () => {
310310
},
311311
],
312312
};
313-
expect(tree.nodes).toEqual(treeMock.nodes);
313+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
314314
});
315315
test(`Default ScalarTypes values - ${Object.keys(ScalarTypes).join(', ')}`, () => {
316316
const schema = `input Person{
@@ -582,7 +582,7 @@ describe('Input Values tests on parser', () => {
582582
},
583583
],
584584
};
585-
expect(tree.nodes).toEqual(treeMock.nodes);
585+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
586586
});
587587

588588
test('Default Input objects', () => {
@@ -710,7 +710,7 @@ describe('Input Values tests on parser', () => {
710710
},
711711
],
712712
};
713-
expect(tree.nodes).toEqual(treeMock.nodes);
713+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
714714
});
715715
test('Default Enum objects', () => {
716716
const schema = `
@@ -819,6 +819,6 @@ describe('Input Values tests on parser', () => {
819819
},
820820
],
821821
};
822-
expect(tree.nodes).toEqual(treeMock.nodes);
822+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
823823
});
824824
});

src/__tests__/Parser/Interface.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Interfaces works as expected', () => {
7676
},
7777
],
7878
};
79-
expect(tree.nodes).toEqual(treeMock.nodes);
79+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
8080
});
8181
it('Implements HasName Person interface', () => {
8282
const schema = `
@@ -152,6 +152,6 @@ describe('Interfaces works as expected', () => {
152152
},
153153
],
154154
};
155-
expect(tree.nodes).toEqual(treeMock.nodes);
155+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
156156
});
157157
});

src/__tests__/Parser/Schema.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('Schema base operations', () => {
5555
},
5656
],
5757
};
58-
expect(tree.nodes).toEqual(treeMock.nodes);
58+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
5959
});
6060
test(`query should exist`, () => {
6161
const schema = `type Query{
@@ -99,7 +99,7 @@ describe('Schema base operations', () => {
9999
},
100100
],
101101
};
102-
expect(tree.nodes).toEqual(treeMock.nodes);
102+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
103103
});
104104
test(`empty query`, () => {
105105
const schema = `
@@ -129,6 +129,6 @@ describe('Schema base operations', () => {
129129
},
130130
],
131131
};
132-
expect(tree.nodes).toEqual(treeMock.nodes);
132+
expect(tree.nodes).toEqual(expect.arrayContaining(treeMock.nodes));
133133
});
134134
});

0 commit comments

Comments
 (0)