Skip to content

Commit a36d01a

Browse files
committed
✨ add jest eslint conf
1 parent 537e85d commit a36d01a

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

eslint-config-jest/base.yaml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
plugins:
2-
- 'jest'
3-
env:
4-
jest/globals: yes
1+
# extends:
2+
# - 'plugin:jest/recommended'
3+
4+
overrides:
5+
- files:
6+
- 'test/**'
7+
- '__test__/**'
8+
- '*.test.*'
9+
- '*.spec.*'
10+
- '*.unit.*'
11+
- '*.e2e.*'
12+
extends:
13+
- 'plugin:jest/recommended'
14+
settings:
15+
jest:
16+
version: 'detect'
17+
18+
rules:
19+
# prevent return statements in tests
20+
jest/no-test-return-statement: 'error'
21+
22+
# use jest comparators instead of comparing booleans
23+
jest/prefer-comparison-matcher: 'error'
24+
jest/prefer-equality-matcher: 'error'
25+
26+
# require hooks to be inside a describe
27+
jest/require-top-level-describe: 'error'

eslint-config-jest/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"license": "MIT",
1919
"main": "base.yaml",
2020
"scripts": {
21-
"test": "echo 'No tests'; exit 0"
21+
"test": "node --require ts-node/register --test test/index.ts"
2222
},
2323
"dependencies": {
24-
"@shopify/eslint-plugin": "^43.0.0"
24+
"eslint-plugin-jest": "^27.4.0"
2525
},
2626
"peerDependencies": {
2727
"@dudeofawesome/eslint-config": "^1.3.0",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
root: true
2+
extends:
3+
- '@dudeofawesome'
4+
- '@dudeofawesome/jest'
5+
parserOptions:
6+
ecmaVersion: 2022

eslint-config-jest/test/index.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { describe, it } from 'node:test';
2+
import { ESLint } from 'eslint';
3+
import {
4+
testRuleFail,
5+
testNoFail,
6+
defaultTestSet,
7+
} from '../../utils/testing/eslint';
8+
9+
const linter = new ESLint({ cwd: __dirname });
10+
11+
describe('eslint-config-node', () => {
12+
defaultTestSet(linter);
13+
14+
describe('passes', () => {
15+
it(`should have jest globals in test file`, () =>
16+
testNoFail({
17+
linter,
18+
code: `describe('test', () => {});\n`,
19+
file_path: 'test/thing.js',
20+
}));
21+
});
22+
23+
describe('fails', () => {
24+
it(`should not have jest globals in non-test file`, () =>
25+
testRuleFail({
26+
linter,
27+
code: `describe('test', () => {});\n`,
28+
ruleId: 'no-undef',
29+
}));
30+
});
31+
});

0 commit comments

Comments
 (0)