Skip to content

Commit

Permalink
fix(prefer-importing-jest-globals): support typescript-eslint parser (#…
Browse files Browse the repository at this point in the history
…1639)

* fix(prefer-importing-jest-globals): support new config

* fix(prefer-importing-jest-globals): tests, broken due to types

* fix(prefer-importing-jest-globals): update tests

* fix(prefer-importing-jest-globals): include valid tests

* fix(prefer-importing-jest-globals): split typescript tests

---------

Co-authored-by: Erin Zimmer <ezimmer@atlassian.com>
  • Loading branch information
ejzimmer and ezimmer-atlassian authored Aug 29, 2024
1 parent 267702d commit 307f6a7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
58 changes: 58 additions & 0 deletions src/rules/__tests__/prefer-importing-jest-globals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,61 @@ ruleTester.run('prefer-importing-jest-globals', rule, {
},
],
});

new RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
}).run('prefer-importing-jest-globals: typescript edition', rule, {
valid: [],
invalid: [
{
code: dedent`
import describe from '@jest/globals';
describe("suite", () => {
test("foo");
expect(true).toBeDefined();
})
`,
output: dedent`
import { describe, expect, test } from '@jest/globals';
describe("suite", () => {
test("foo");
expect(true).toBeDefined();
})
`,
parserOptions: { sourceType: 'module' },
errors: [
{
endColumn: 7,
column: 3,
line: 3,
messageId: 'preferImportingJestGlobal',
},
],
},
{
code: dedent`
const {describe} = require('@jest/globals');
describe("suite", () => {
test("foo");
expect(true).toBeDefined();
})
`,
output: dedent`
const { describe, expect, test } = require('@jest/globals');
describe("suite", () => {
test("foo");
expect(true).toBeDefined();
})
`,
parserOptions: { sourceType: 'script' },
errors: [
{
endColumn: 7,
column: 3,
line: 3,
messageId: 'preferImportingJestGlobal',
},
],
},
],
});
4 changes: 3 additions & 1 deletion src/rules/prefer-importing-jest-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export default createRule({
return;
}

const isModule = context.parserOptions.sourceType === 'module';
const isModule =
context.parserOptions.sourceType === 'module' ||
context.languageOptions?.sourceType === 'module';

context.report({
node: reportingNode,
Expand Down

0 comments on commit 307f6a7

Please # to comment.