Skip to content

Commit c0c2c01

Browse files
committed
test: get linter#verify cases passing
1 parent 1dca0a2 commit c0c2c01

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

src/rules/__tests__/no-deprecated-functions.test.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
type JestVersion,
55
detectJestVersion,
66
} from '../utils/detectJestVersion';
7-
import { FlatCompatRuleTester } from './test-utils';
7+
import { FlatCompatRuleTester, usingFlatConfig } from './test-utils';
88

99
jest.mock('../utils/detectJestVersion');
1010

@@ -159,6 +159,20 @@ describe('the rule', () => {
159159
expect(() => {
160160
const linter = new TSESLint.Linter();
161161

162+
/* istanbul ignore if */
163+
if (usingFlatConfig()) {
164+
linter.verify('jest.resetModuleRegistry()', [
165+
{
166+
plugins: {
167+
jest: { rules: { 'no-deprecated-functions': rule } },
168+
},
169+
rules: { 'jest/no-deprecated-functions': 'error' },
170+
},
171+
]);
172+
173+
return;
174+
}
175+
162176
linter.defineRule('no-deprecated-functions', rule);
163177

164178
linter.verify('jest.resetModuleRegistry()', {

src/rules/__tests__/no-large-snapshots.test.ts

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { TSESLint } from '@typescript-eslint/utils';
22
import dedent from 'dedent';
33
import rule from '../no-large-snapshots';
4-
import { FlatCompatRuleTester, espreeParser } from './test-utils';
4+
import {
5+
FlatCompatRuleTester,
6+
espreeParser,
7+
usingFlatConfig,
8+
} from './test-utils';
59

610
const ruleTester = new FlatCompatRuleTester({
711
parser: espreeParser,
@@ -267,6 +271,34 @@ describe('no-large-snapshots', () => {
267271
expect(() => {
268272
const linter = new TSESLint.Linter();
269273

274+
/* istanbul ignore if */
275+
if (usingFlatConfig()) {
276+
linter.verify(
277+
'console.log()',
278+
[
279+
{
280+
files: ['*.snap'],
281+
plugins: {
282+
jest: { rules: { 'no-large-snapshots': rule } },
283+
},
284+
rules: {
285+
'jest/no-large-snapshots': [
286+
'error',
287+
{
288+
allowedSnapshots: {
289+
'mock-component.jsx.snap': [/a big component \d+/u],
290+
},
291+
},
292+
],
293+
},
294+
},
295+
],
296+
'mock-component.jsx.snap',
297+
);
298+
299+
return;
300+
}
301+
270302
linter.defineRule('no-large-snapshots', rule);
271303

272304
linter.verify(

src/rules/__tests__/test-utils.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const eslintRequire = createRequire(require.resolve('eslint'));
88

99
export const espreeParser = eslintRequire.resolve('espree');
1010

11+
export const usingFlatConfig = () => semver.major(eslintVersion) >= 9;
12+
1113
export class FlatCompatRuleTester extends TSESLint.RuleTester {
1214
public constructor(testerConfig?: TSESLint.RuleTesterConfig) {
1315
super(FlatCompatRuleTester._flatCompat(testerConfig));
@@ -35,11 +37,7 @@ export class FlatCompatRuleTester extends TSESLint.RuleTester {
3537
| TSESLint.ValidTestCase<unknown[]>
3638
| TSESLint.InvalidTestCase<string, unknown[]>,
3739
>(config: T): T {
38-
if (
39-
!config ||
40-
semver.major(eslintVersion) < 9 ||
41-
typeof config === 'string'
42-
) {
40+
if (!config || !usingFlatConfig() || typeof config === 'string') {
4341
return config;
4442
}
4543

0 commit comments

Comments
 (0)