Skip to content

Commit 0180818

Browse files
committed
improve parser test coverage, rm no longer needed check in getVisitFn
1 parent e019307 commit 0180818

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/language/__tests__/parser.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,35 @@ import { readFileSync } from 'fs';
1616
import { join } from 'path';
1717

1818
describe('Parser', () => {
19+
20+
it('accepts option to not include source', () => {
21+
expect(parse(`{ field }`, { noSource: true })).to.deep.equal({
22+
kind: 'Document',
23+
loc: { start: 0, end: 9 },
24+
definitions:
25+
[ { kind: 'OperationDefinition',
26+
loc: { start: 0, end: 9 },
27+
operation: 'query',
28+
name: null,
29+
variableDefinitions: null,
30+
directives: [],
31+
selectionSet: {
32+
kind: 'SelectionSet',
33+
loc: { start: 0, end: 9 },
34+
selections:
35+
[ { kind: 'Field',
36+
loc: { start: 2, end: 7 },
37+
alias: null,
38+
name:
39+
{ kind: 'Name',
40+
loc: { start: 2, end: 7 },
41+
value: 'field' },
42+
arguments: [],
43+
directives: [],
44+
selectionSet: null } ] } } ]
45+
});
46+
});
47+
1948
it('parse provides useful errors', () => {
2049

2150
expect(
@@ -81,16 +110,7 @@ fragment MissingOn Type
81110
);
82111

83112
it('parses kitchen sink', () => {
84-
85-
expect(() => {
86-
try {
87-
parse(kitchenSink);
88-
} catch (e) {
89-
console.log(e.stack);
90-
throw e;
91-
}
92-
}).to.not.throw();
93-
113+
expect(() => parse(kitchenSink)).to.not.throw();
94114
});
95115

96116
it('parse creates ast', () => {

src/language/visitor.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,6 @@ function isNode(maybeNode) {
251251
}
252252

253253
export function getVisitFn(visitor, isLeaving, kind) {
254-
if (!visitor) {
255-
return;
256-
}
257254
var kindVisitor = visitor[kind];
258255
if (kindVisitor) {
259256
if (!isLeaving && typeof kindVisitor === 'function') {

0 commit comments

Comments
 (0)