Skip to content

Commit e42e3e9

Browse files
authored
use FlatESLint in integration tests (#1326)
1 parent 58253bf commit e42e3e9

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

packages/plugin/tests/rules.spec.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,51 @@
1-
import { ESLint } from 'eslint';
1+
import eslintExperimentalApis from 'eslint/use-at-your-own-risk';
2+
import { describe, it, expect } from 'vitest';
3+
import { rules, parseForESLint } from '@graphql-eslint/eslint-plugin';
24
import { ParserOptions } from '../src';
5+
import schemaAllConfig from '../src/configs/schema-all.json';
6+
import operationsAllConfig from '../src/configs/operations-all.json';
7+
import relayConfig from '../src/configs/relay.json';
38

4-
function getESLintWithConfig(
5-
configName: 'schema-all' | 'operations-all' | 'relay',
6-
parserOptions?: ParserOptions,
7-
): ESLint {
8-
return new ESLint({
9-
useEslintrc: false,
10-
baseConfig: {
11-
overrides: [
12-
{
13-
files: '*.graphql',
14-
extends: `plugin:@graphql-eslint/${configName}`,
9+
const { FlatESLint } = eslintExperimentalApis;
10+
11+
function getESLintWithConfig(config: any, parserOptions?: Omit<ParserOptions, 'filePath'>) {
12+
return new FlatESLint({
13+
overrideConfigFile: true,
14+
overrideConfig: [
15+
{
16+
files: ['*.graphql'],
17+
languageOptions: {
18+
parser: { parseForESLint },
1519
parserOptions: {
1620
schema: 'type Query { foo: Int }',
1721
skipGraphQLConfig: true,
1822
...parserOptions,
1923
},
2024
},
21-
],
22-
},
25+
plugins: {
26+
'@graphql-eslint': { rules },
27+
},
28+
rules: config.rules,
29+
},
30+
],
2331
});
2432
}
2533

26-
describe.skip('Rules', () => {
34+
describe('Rules', () => {
2735
it('should load all rules properly from `schema-all` config', async () => {
28-
const eslint = getESLintWithConfig('schema-all');
36+
const eslint = getESLintWithConfig(schemaAllConfig);
2937
const results = await eslint.lintText('{ foo }', { filePath: 'foo.graphql' });
3038
expect(results).toHaveLength(1);
3139
});
3240

3341
it('should load all rules properly from `operations-all` config', async () => {
34-
const eslint = getESLintWithConfig('operations-all', { operations: '{ foo }' });
42+
const eslint = getESLintWithConfig(operationsAllConfig, { operations: '{ foo }' });
3543
const results = await eslint.lintText('{ foo }', { filePath: 'foo.graphql' });
3644
expect(results).toHaveLength(1);
3745
});
3846

3947
it('should load all rules properly from `relay` config', async () => {
40-
const eslint = getESLintWithConfig('relay', { operations: '{ foo }' });
48+
const eslint = getESLintWithConfig(relayConfig, { operations: '{ foo }' });
4149
const results = await eslint.lintText('{ foo }', { filePath: 'foo.graphql' });
4250
expect(results).toHaveLength(1);
4351
});

vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { defineConfig } from 'vitest/config';
2+
import tsconfig from './tsconfig.json';
23

34
export default defineConfig({
45
test: {
56
globals: true,
67
resolveSnapshotPath: testPath =>
78
testPath.replace('tests/', 'tests/__snapshots__/').replace(/\.ts$/, '.md'),
89
setupFiles: ['./serializer.js'],
10+
// @ts-expect-error -- It just works
11+
alias: tsconfig.compilerOptions.paths,
912
},
1013
});

0 commit comments

Comments
 (0)