Skip to content

Commit

Permalink
Update: Testing configurations to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
DHedgecock committed Oct 15, 2023
1 parent b0e006e commit 705e642
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 238 deletions.
19 changes: 10 additions & 9 deletions README.md
Expand Up @@ -216,7 +216,7 @@ This means linting related to code quality is always surfaced as a priority, but
during development non critical feedback related to code style and formatting is
moderated.

#### Linting philosphy
#### Linting philosophy

In general, the Eloquence ruleset tries to encourage these coding practices:

Expand Down Expand Up @@ -293,19 +293,20 @@ executed by Node.js.
This package will automatically include all of the packages needed to run
ESLint. Projects should allow this package to "own" the dependency management
for packages related to ESLint. _(When possible ensure that the only version of
`eslint` and `babel-eslint` included in a project are the versions specified by
this package.)_
`eslint` included in a project is the versions specified by this package.)_

#### Included dependencies:

- [`eslint`][]
- [`babel-eslint`][]
- [`@typescript-eslint/eslint-plugin`][]
- [`@typescript-eslint/parser`][]
- [`eslint-config-prettier`][]
- [`eslint-plugin-cypress`][]
- [`eslint-plugin-import`][]
- [`eslint-plugin-jest][]
- [`eslint-plugin-jest`][]
- [`eslint-plugin-jest-dom`][]
- [`eslint-plugin-jest-formatting][]
- [`eslint-plugin-jest-extended`][]
- [`eslint-plugin-jest-formatting`][]
- [`eslint-plugin-jsx-a11y`][]
- [`eslint-plugin-prettier`][]
- [`eslint-plugin-react`][]
Expand All @@ -332,12 +333,12 @@ everyone 🎉. <br /> Please read the [Code of Conduct](./CODE_OF_CONDUCT.md) an
[`babel-eslint`]:https://github.com/babel/babel-eslint
[`eslint-config-prettier`]:https://github.com/prettier/eslint-config-prettier
[`eslint-formatter-pretty`]:https://github.com/sindresorhus/eslint-formatter-pretty
[`eslint-import-resolver-webpack`]:https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers/webpack
[`eslint-plugin-cypress`]:https://github.com/cypress-io/eslint-plugin-cypress
[`eslint-plugin-import`]:https://github.com/benmosher/eslint-plugin-import
[`eslint-plugin-jest]:https://github.com/jest-community/eslint-plugin-jest
[`eslint-plugin-jest`]:https://github.com/jest-community/eslint-plugin-jest
[`eslint-plugin-jest-dom`]:https://github.com/testing-library/eslint-plugin-jest-dom
[`eslint-plugin-jest-formatting]:https://github.com/dangreenisrael/eslint-plugin-jest-formatting
[`eslint-plugin-jest-extended`]:https://github.com/jest-community/eslint-plugin-jest-extended
[`eslint-plugin-jest-formatting`]:https://github.com/dangreenisrael/eslint-plugin-jest-formatting
[`eslint-plugin-jsx-a11y`]:https://github.com/evcohen/eslint-plugin-jsx-a11y
[`eslint-plugin-prettier`]:https://github.com/prettier/eslint-plugin-prettier
[`eslint-plugin-react`]:https://github.com/yannickcr/eslint-plugin-react
Expand Down
23 changes: 11 additions & 12 deletions node.js
Expand Up @@ -20,8 +20,6 @@ const corePossibleErrors = require('./src/rules/core-possible-errors')
const coreStylisticIssues = require('./src/rules/core-stylistic-issues')
const coreVariables = require('./src/rules/core-variables')
const pluginImport = require('./src/rules/plugin-import')
const pluginJest = require('./src/rules/plugin-jest')
const pluginJestFormatting = require('./src/rules/plugin-jest-formatting')
const pluginNode = require('./src/rules/plugin-node')
const pluginTypescript = require('./src/rules/plugin-typescript')

Expand Down Expand Up @@ -52,7 +50,7 @@ module.exports = {
ecmaFeatures: {},
},

plugins: ['@typescript-eslint', 'import', 'jest', 'jest-formatting', 'prettier'],
plugins: ['@typescript-eslint', 'import', 'prettier'],

settings: {
// Assumes tools like eslint-loader aren't used
Expand Down Expand Up @@ -136,17 +134,18 @@ module.exports = {
// --- ✅ Test files --------------------------
{
files: ['*.spec.js'],

env: { jest: true },

extends: [
'plugin:jest-formatting/strict',
'plugin:jest/all',
'plugin:jest-extended/all',
],
plugins: ['jest', 'jest-extended', 'jest-formatting'],
rules: {
// In Jest test files allow defining `jest.mock()` calls before imports
// Under the hood Jest hoists these to the top of the file and it helps
// visually distinguish modules that are being replaced with mocks
'import/first': 'off',
...pluginJest,
...pluginJestFormatting,
'jest/unbound-method': 'off', // requires addl ts configs to enable
'jest/prefer-expect-assertions': 'off', // just a little toooo opinionated
},

env: { jest: true },
},

// --- 💾 CommonJS files --------------------------
Expand Down
130 changes: 130 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -44,6 +44,7 @@
"eslint-plugin-import": "2.28.1",
"eslint-plugin-jest": "27.4.2",
"eslint-plugin-jest-dom": "5.1.0",
"eslint-plugin-jest-extended": "2.0.0",
"eslint-plugin-jest-formatting": "3.1.0",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-node": "11.1.0",
Expand Down
37 changes: 19 additions & 18 deletions react.js
Expand Up @@ -10,13 +10,9 @@ const coreStylisticIssues = require('./src/rules/core-stylistic-issues')
const coreVariables = require('./src/rules/core-variables')
const pluginCypress = require('./src/rules/plugin-cypress')
const pluginImport = require('./src/rules/plugin-import')
const pluginJest = require('./src/rules/plugin-jest')
const pluginJestDom = require('./src/rules/plugin-jest-dom')
const pluginJestFormatting = require('./src/rules/plugin-jest-formatting')
const pluginReact = require('./src/rules/plugin-react')
const pluginReactA11y = require('./src/rules/plugin-react-a11y')
const pluginReactHooks = require('./src/rules/plugin-react-hooks')
const pluginTestingLibrary = require('./src/rules/plugin-testing-library')
const pluginTypescript = require('./src/rules/plugin-typescript')

const { NODE_ENV } = process.env
Expand Down Expand Up @@ -49,14 +45,10 @@ module.exports = {
'@typescript-eslint',
'cypress',
'import',
'jest',
'jest-dom',
'jest-formatting',
'jsx-a11y',
'prettier',
'react',
'react-hooks',
'testing-library',
],

settings: {
Expand Down Expand Up @@ -148,23 +140,32 @@ module.exports = {
},
},

// --- ✅ Unit+Component test files --------------------------
// --- ✅ Jest tests --------------------------
{
files: ['src/**/*.spec.js'],
extends: [
'plugin:jest-formatting/strict',
'plugin:jest/all',
'plugin:jest-extended/all',
'plugin:jest-dom/recommended',
'plugin:testing-library/react',
],
plugins: [
'jest',
'jest-dom',
'jest-extended',
'jest-formatting',
'testing-library',
],
env: { jest: true },
rules: {
// In Jest test files allow defining `jest.mock()` calls before imports
// Under the hood Jest hoists these to the top of the file and it helps
// visually distinguish modules that are being replaced with mocks
'import/first': 'off',
...pluginJest,
...pluginJestDom,
...pluginJestFormatting,
...pluginTestingLibrary,
'jest/unbound-method': 'off', // requires addl ts configs to enable
'jest/prefer-expect-assertions': 'off', // just a little toooo opinionated
'testing-library/prefer-user-event': 'error', // opt in to stricter user-event
},
},

// --- 🌲 Cypress directory --------------------------
// --- 🌲 Cypress tests --------------------------
{
files: ['cypress/**/*'],
env: { 'cypress/globals': true },
Expand Down
10 changes: 5 additions & 5 deletions src/rule-severities.spec.js
Expand Up @@ -2,20 +2,20 @@

const ruleSeverities = require('./rule-severities')

describe('ruleSeverities', () => {
it('Rules are not downgraded in test', () => {
describe('ruleSeverities()', () => {
it('rules are not downgraded in test', () => {
const rules = ruleSeverities('test', { 'no-unused-vars': 'error' })

expect(rules['no-unused-vars']).toBe('error')
})

it('String value rules are downgraded', () => {
it('string value rules are downgraded', () => {
const rules = ruleSeverities('development', { 'no-unused-vars': 'error' })

expect(rules['no-unused-vars']).toBe('warn')
})

it('Array value rules are downgraded', () => {
it('array value rules are downgraded', () => {
const rules = ruleSeverities('development', {
'no-unused-vars': [
'error',
Expand All @@ -29,7 +29,7 @@ describe('ruleSeverities', () => {
])
})

it('Disabled rules stay disabled', () => {
it('disabled rules stay disabled', () => {
const rules = ruleSeverities('development', { 'no-unused-vars': 'off' })

expect(rules['no-unused-vars']).toBe('off')
Expand Down
21 changes: 2 additions & 19 deletions src/rules/plugin-cypress.js
Expand Up @@ -25,23 +25,6 @@ module.exports = {
// help encourage test resiliency
'cypress/require-data-selectors': 'error',

// --- ⬆️ Rule overrides ---

// Allow using `function () {}` instead of arrow funcs to support accessing
// `this` inside of tests, where an arrow function will bind `this` to the
// incorrect scope:
//
// beforeEach(function () {
// cy.get('button').invoke('text').as('text')
// })
//
// it('has access to text', function () {
// this.text
// })
// TODO: verify that arrow funcs do indeed break this
'func-names': 'off',

// Allow triple slash type directives in order to include TypeScript
// <reference types="Cypress" /> directives
'spaced-comment': 'off',
// Disallow unsafe cy.*() commands that can hang the Cypress runner
'cypress/unsafe-to-chain-command': 'error',
}

0 comments on commit 705e642

Please sign in to comment.