rsnext/test/unit/eslint-plugin-next/index.test.ts
Michael Novotny edd395a7d3
Adds tests to ensure eslint-plugin-next's available rules are properly exported and recommended rules are correctly defined. (#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 <jj@jjsweb.site>
2022-06-30 11:31:33 -05:00

28 lines
901 B
TypeScript

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(
recommended
)
})
})
})