|
1 |
| -import { join } from 'node:path'; |
2 |
| -import { CWD } from '@/utils.js'; |
| 1 | +import path from 'node:path'; |
3 | 2 | import { ParserOptionsForTests, ruleTester } from '../../../__tests__/test-utils.js';
|
4 | 3 | import { rule } from './index.js';
|
5 | 4 |
|
6 |
| -function withMocks({ name, filename, errors }: { name: string; filename: string; errors?: any }) { |
| 5 | +function withMocks({ |
| 6 | + name, |
| 7 | + filename, |
| 8 | + errors, |
| 9 | + only = false, |
| 10 | +}: { |
| 11 | + name: string; |
| 12 | + filename: string; |
| 13 | + errors?: any; |
| 14 | + only?: boolean; |
| 15 | +}) { |
7 | 16 | return {
|
8 | 17 | name,
|
9 | 18 | filename,
|
10 | 19 | code: ruleTester.fromMockFile(filename.split('mocks')[1]),
|
11 | 20 | parserOptions: {
|
12 | 21 | graphQLConfig: {
|
13 |
| - documents: [ |
14 |
| - filename, |
15 |
| - join(CWD, '__tests__', 'mocks', 'import-fragments', 'foo-fragment.gql'), |
16 |
| - join(CWD, '__tests__', 'mocks', 'import-fragments', 'bar-fragment.gql'), |
17 |
| - ], |
| 22 | + documents: [filename, './__tests__/mocks/import-fragments/fragments/**/*.gql'], |
18 | 23 | },
|
19 | 24 | } satisfies ParserOptionsForTests,
|
20 | 25 | errors,
|
| 26 | + only, |
21 | 27 | };
|
22 | 28 | }
|
23 |
| - |
24 | 29 | ruleTester.run('require-import-fragment', rule, {
|
25 | 30 | valid: [
|
26 | 31 | withMocks({
|
27 | 32 | name: 'should not report with named import',
|
28 |
| - filename: join(CWD, '__tests__', 'mocks', 'import-fragments', 'valid-query.gql'), |
| 33 | + filename: path.resolve('__tests__', 'mocks', 'import-fragments', 'valid-query.gql'), |
29 | 34 | }),
|
30 | 35 | withMocks({
|
31 | 36 | name: 'should not report with default import',
|
32 |
| - filename: join(CWD, '__tests__', 'mocks', 'import-fragments', 'valid-query-default.gql'), |
| 37 | + filename: path.resolve('__tests__', 'mocks', 'import-fragments', 'valid-query-default.gql'), |
33 | 38 | }),
|
34 | 39 | withMocks({
|
35 | 40 | name: 'should not report fragments from the same file',
|
36 |
| - filename: join(CWD, '__tests__', 'mocks', 'import-fragments', 'same-file.gql'), |
| 41 | + filename: path.resolve('__tests__', 'mocks', 'import-fragments', 'same-file.gql'), |
37 | 42 | }),
|
38 | 43 | ],
|
39 | 44 | invalid: [
|
40 | 45 | withMocks({
|
41 | 46 | name: 'should report with named import',
|
42 |
| - filename: join(CWD, '__tests__', 'mocks', 'import-fragments', 'invalid-query.gql'), |
| 47 | + filename: path.resolve('__tests__', 'mocks', 'import-fragments', 'invalid-query.gql'), |
43 | 48 | errors: [{ message: 'Expected "FooFields" fragment to be imported.' }],
|
44 | 49 | }),
|
45 | 50 | withMocks({
|
46 | 51 | name: 'should report with default import',
|
47 |
| - filename: join(CWD, '__tests__', 'mocks', 'import-fragments', 'invalid-query-default.gql'), |
| 52 | + filename: path.resolve('__tests__', 'mocks', 'import-fragments', 'invalid-query-default.gql'), |
48 | 53 | errors: [{ message: 'Expected "FooFields" fragment to be imported.' }],
|
49 | 54 | }),
|
50 | 55 | withMocks({
|
51 | 56 | name: 'should report fragments when there are no import expressions',
|
52 |
| - filename: join(CWD, '__tests__', 'mocks', 'import-fragments', 'missing-import.gql'), |
| 57 | + filename: path.resolve('__tests__', 'mocks', 'import-fragments', 'missing-import.gql'), |
53 | 58 | errors: [{ message: 'Expected "FooFields" fragment to be imported.' }],
|
54 | 59 | }),
|
55 | 60 | ],
|
|
0 commit comments