|
1 | 1 | import '../../../testing/to-be-similar-gql-doc'; |
2 | 2 | import { processImport, VisitedFilesMap } from '../../src'; |
3 | 3 | import { print } from 'graphql'; |
4 | | -import { relative } from 'path' |
| 4 | +import { relative } from 'path'; |
5 | 5 |
|
6 | 6 | const importDocuments = (documentPath: string) => print(processImport(documentPath, __dirname)); |
7 | 7 |
|
8 | 8 | describe('import in documents', () => { |
9 | | - it('should get documents with default imports properly', async () => { |
10 | | - const document = importDocuments('./import-test/default/a.graphql'); |
| 9 | + it('should get documents with default imports properly', () => { |
| 10 | + const document = importDocuments('./import-test/default/a.graphql'); |
11 | 11 |
|
12 | | - expect(document).toBeSimilarGqlDoc(/* GraphQL */` |
13 | | - query FooQuery { |
14 | | - foo { |
15 | | - ...FooFragment |
16 | | - } |
17 | | - } |
| 12 | + expect(document).toBeSimilarGqlDoc(/* GraphQL */ ` |
| 13 | + query FooQuery { |
| 14 | + foo { |
| 15 | + ...FooFragment |
| 16 | + } |
| 17 | + } |
18 | 18 |
|
19 | | - fragment FooFragment on Foo { |
20 | | - bar { |
21 | | - ...BarFragment |
22 | | - } |
23 | | - } |
| 19 | + fragment FooFragment on Foo { |
| 20 | + bar { |
| 21 | + ...BarFragment |
| 22 | + } |
| 23 | + } |
24 | 24 |
|
25 | | - fragment BarFragment on Bar { |
26 | | - baz |
27 | | - } |
28 | | - `); |
29 | | - }); |
| 25 | + fragment BarFragment on Bar { |
| 26 | + baz |
| 27 | + } |
| 28 | + `); |
| 29 | + }); |
30 | 30 |
|
31 | | - it('should get documents with specific imports properly', async () => { |
32 | | - const document = importDocuments('./import-test/specific/a.graphql'); |
| 31 | + it('should get documents with default imports properly with comments', () => { |
| 32 | + const document = importDocuments('./import-test/default/with-comments.graphql'); |
| 33 | + expect(document).toBeSimilarGqlDoc( |
| 34 | + /* GraphQL */ ` |
| 35 | + # eslint-disable-next-line |
| 36 | + query Foo { |
| 37 | + ...BarFragment |
| 38 | + } |
33 | 39 |
|
34 | | - expect(document).toBeSimilarGqlDoc(/* GraphQL */` |
35 | | - query FooQuery { |
36 | | - foo { |
37 | | - ...FooFragment |
38 | | - } |
| 40 | + fragment BarFragment on Bar { |
| 41 | + baz |
39 | 42 | } |
| 43 | + `, |
| 44 | + { skipComments: false } |
| 45 | + ); |
| 46 | + }); |
40 | 47 |
|
41 | | - fragment FooFragment on Foo { |
42 | | - bar { |
43 | | - ...BarFragment |
44 | | - } |
| 48 | + it('should get documents with specific imports properly', () => { |
| 49 | + const document = importDocuments('./import-test/specific/a.graphql'); |
| 50 | + |
| 51 | + expect(document).toBeSimilarGqlDoc(/* GraphQL */ ` |
| 52 | + query FooQuery { |
| 53 | + foo { |
| 54 | + ...FooFragment |
45 | 55 | } |
| 56 | + } |
46 | 57 |
|
47 | | - fragment BarFragment on Bar { |
48 | | - baz |
| 58 | + fragment FooFragment on Foo { |
| 59 | + bar { |
| 60 | + ...BarFragment |
49 | 61 | } |
50 | | - `); |
51 | | - }); |
| 62 | + } |
| 63 | +
|
| 64 | + fragment BarFragment on Bar { |
| 65 | + baz |
| 66 | + } |
| 67 | + `); |
| 68 | + }); |
52 | 69 |
|
53 | | - it('should accept a map as fourth argument for users to get visited file paths with details', () => { |
54 | | - const visitedFiles: VisitedFilesMap = new Map(); |
55 | | - processImport('./import-test/default/a.graphql', __dirname, undefined, visitedFiles); |
56 | | - const relativePaths = Array.from(visitedFiles.keys()) |
57 | | - .map(absPath => relative(__dirname, absPath)) |
58 | | - .map(relPath => relPath.replace(/\\/g, '\/')) |
59 | | - expect(relativePaths).toStrictEqual([ |
60 | | - "import-test/default/a.graphql", |
61 | | - "import-test/default/b.graphql", |
62 | | - "import-test/default/c.graphql" |
63 | | - ]); |
64 | | - }) |
| 70 | + it('should accept a map as fourth argument for users to get visited file paths with details', () => { |
| 71 | + const visitedFiles: VisitedFilesMap = new Map(); |
| 72 | + processImport('./import-test/default/a.graphql', __dirname, undefined, visitedFiles); |
| 73 | + const relativePaths = Array.from(visitedFiles.keys()) |
| 74 | + .map(absPath => relative(__dirname, absPath)) |
| 75 | + .map(relPath => relPath.replace(/\\/g, '\/')); |
| 76 | + expect(relativePaths).toStrictEqual([ |
| 77 | + 'import-test/default/a.graphql', |
| 78 | + 'import-test/default/b.graphql', |
| 79 | + 'import-test/default/c.graphql', |
| 80 | + ]); |
| 81 | + }); |
65 | 82 | }); |
0 commit comments