Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds tests to ensure eslint-plugin-next's available rules are properly exported and recommended rules are correctly defined. #38183

Merged
merged 5 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"is-animated": "2.0.2",
"isomorphic-unfetch": "3.0.0",
"jest": "27.0.6",
"jest-extended": "1.2.1",
"ky": "0.19.1",
"ky-universal": "0.6.0",
"lerna": "4.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
docs: {
description:
'Prevent usage of `<title>` with `Head` component from `next/document`.',
recommended: true,
url,
},
},
Expand Down
131 changes: 131 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/jest-setup-after-env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import * as matchers from 'jest-extended'
expect.extend(matchers)

// A default max-timeout of 90 seconds is allowed
// per test we should aim to bring this down though
jest.setTimeout((process.platform === 'win32' ? 180 : 90) * 1000)
1 change: 1 addition & 0 deletions test/jest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'jest-extended'
28 changes: 28 additions & 0 deletions test/unit/eslint-plugin-next/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { basename } from 'path'
import glob from 'glob'
import index from '@next/eslint-plugin-next'

const getRuleNameFromRulePath = (path) => basename(path, '.js')
const rulePaths = glob.sync('packages/eslint-plugin-next/lib/rules/*js', {
absolute: true,
})

describe('@next/eslint-plugin-next index', () => {
it('should include all defined rules and no extra / undefined rules', () => {
const rules = rulePaths.map((rulePath) => getRuleNameFromRulePath(rulePath))

expect(index.rules).toContainAllKeys(rules)
})

rulePaths.forEach((rulePath) => {
const rule = require(rulePath)
const ruleName = getRuleNameFromRulePath(rulePath)
const { recommended = false } = rule.meta.docs

it(`${ruleName}: recommend should be \`${recommended}\``, () => {
expect(`@next/next/${ruleName}` in index.configs.recommended.rules).toBe(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijjk good thinking! 👍

recommended
)
})
})
})
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}
},
"include": [
"test/jest.d.ts",
"test/**/*.test.ts",
"test/**/*.test.tsx",
"test/**/test/*",
Expand Down