Skip to content

Commit edd395a

Browse files
manovotnyijjk
andauthored
Adds tests to ensure eslint-plugin-next's available rules are properly exported and recommended rules are correctly defined. (vercel#38183)
* Adds tests to ensure `eslint-plugin-next`'s available rules are properly exported and recommended rules are defined correctly. * Condenses imports. * Sets default recommended value. * replace Object.hasOwn for node 14 Co-authored-by: JJ Kasper <[email protected]>
1 parent ab31460 commit edd395a

File tree

7 files changed

+166
-0
lines changed

7 files changed

+166
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
"is-animated": "2.0.2",
145145
"isomorphic-unfetch": "3.0.0",
146146
"jest": "27.0.6",
147+
"jest-extended": "1.2.1",
147148
"ky": "0.19.1",
148149
"ky-universal": "0.6.0",
149150
"lerna": "4.0.0",

packages/eslint-plugin-next/lib/rules/no-title-in-document-head.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
docs: {
66
description:
77
'Prevent usage of `<title>` with `Head` component from `next/document`.',
8+
recommended: true,
89
url,
910
},
1011
},

pnpm-lock.yaml

+131
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/jest-setup-after-env.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as matchers from 'jest-extended'
2+
expect.extend(matchers)
3+
14
// A default max-timeout of 90 seconds is allowed
25
// per test we should aim to bring this down though
36
jest.setTimeout((process.platform === 'win32' ? 180 : 90) * 1000)

test/jest.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'jest-extended'
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { basename } from 'path'
2+
import glob from 'glob'
3+
import index from '@next/eslint-plugin-next'
4+
5+
const getRuleNameFromRulePath = (path) => basename(path, '.js')
6+
const rulePaths = glob.sync('packages/eslint-plugin-next/lib/rules/*js', {
7+
absolute: true,
8+
})
9+
10+
describe('@next/eslint-plugin-next index', () => {
11+
it('should include all defined rules and no extra / undefined rules', () => {
12+
const rules = rulePaths.map((rulePath) => getRuleNameFromRulePath(rulePath))
13+
14+
expect(index.rules).toContainAllKeys(rules)
15+
})
16+
17+
rulePaths.forEach((rulePath) => {
18+
const rule = require(rulePath)
19+
const ruleName = getRuleNameFromRulePath(rulePath)
20+
const { recommended = false } = rule.meta.docs
21+
22+
it(`${ruleName}: recommend should be \`${recommended}\``, () => {
23+
expect(`@next/next/${ruleName}` in index.configs.recommended.rules).toBe(
24+
recommended
25+
)
26+
})
27+
})
28+
})

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
}
1919
},
2020
"include": [
21+
"test/jest.d.ts",
2122
"test/**/*.test.ts",
2223
"test/**/*.test.tsx",
2324
"test/**/test/*",

0 commit comments

Comments
 (0)