/
printLocation-test.js
78 lines (68 loc) · 2.57 KB
/
printLocation-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// @flow strict
import { expect } from 'chai';
import { describe, it } from 'mocha';
import dedent from '../../jsutils/dedent';
import { Source } from '../../language';
import { printSourceLocation } from '../printLocation';
describe('printSourceLocation', () => {
it('prints minified documents', () => {
const minifiedSource = new Source(
'query SomeMiniFiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String){someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD...on THIRD_ERROR_HERE}}}',
);
const firstLocation = printSourceLocation(minifiedSource, {
line: 1,
column: minifiedSource.body.indexOf('FIRST_ERROR_HERE') + 1,
});
expect(firstLocation + '\n').to.equal(dedent`
GraphQL request:1:53
1 | query SomeMiniFiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String)
| ^
| {someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD.
`);
const secondLocation = printSourceLocation(minifiedSource, {
line: 1,
column: minifiedSource.body.indexOf('SECOND_ERROR_HERE') + 1,
});
expect(secondLocation + '\n').to.equal(dedent`
GraphQL request:1:114
1 | query SomeMiniFiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String)
| {someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD.
| ^
| ..on THIRD_ERROR_HERE}}}
`);
const thirdLocation = printSourceLocation(minifiedSource, {
line: 1,
column: minifiedSource.body.indexOf('THIRD_ERROR_HERE') + 1,
});
expect(thirdLocation + '\n').to.equal(dedent`
GraphQL request:1:166
1 | query SomeMiniFiedQueryWithErrorInside($foo:String!=FIRST_ERROR_HERE$bar:String)
| {someField(foo:$foo bar:$bar baz:SECOND_ERROR_HERE){fieldA fieldB{fieldC fieldD.
| ..on THIRD_ERROR_HERE}}}
| ^
`);
});
it('prints single digit line number with no padding', () => {
const result = printSourceLocation(
new Source('*', 'Test', { line: 9, column: 1 }),
{ line: 1, column: 1 },
);
expect(result + '\n').to.equal(dedent`
Test:9:1
9 | *
| ^
`);
});
it('prints an line numbers with correct padding', () => {
const result = printSourceLocation(
new Source('*\n', 'Test', { line: 9, column: 1 }),
{ line: 1, column: 1 },
);
expect(result + '\n').to.equal(dedent`
Test:9:1
9 | *
| ^
10 |
`);
});
});