Skip to content

Commit

Permalink
[Tests] re-enable tests disabled for the eslint 8 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 22, 2021
1 parent c05ffb2 commit 371537f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 42 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,12 @@ jobs:
matrix:
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
eslint:
- 8
- 7
# - 6
# - 5
package:
- eslint-config-airbnb
react-hooks:
- ''
# - 3 # TODO: re-enable these once the react config uses eslint 8
# - 2.3
# - 1.7
- 4

defaults:
run:
Expand Down Expand Up @@ -131,16 +127,12 @@ jobs:
fail-fast: false
matrix:
eslint:
- 8
- 7
# - 6
# - 5
package:
- eslint-config-airbnb
react-hooks:
- ''
# - 3 # TODO: re-enable these once the react config uses eslint 8
# - 2.3
# - 1.7
- 4

defaults:
run:
Expand Down
54 changes: 24 additions & 30 deletions packages/eslint-config-airbnb/test/test-react-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import eslintrc from '..';
import reactRules from '../rules/react';
import reactA11yRules from '../rules/react-a11y';

const rules = {
// It is okay to import devDependencies in tests.
'import/no-extraneous-dependencies': [2, { devDependencies: true }],
// this doesn't matter for tests
'lines-between-class-members': 0,
// otherwise we need some junk in our fixture code
'react/no-unused-class-component-methods': 0,
};
const cli = new (CLIEngine || ESLint)({
useEslintrc: false,
baseConfig: eslintrc,

rules: {
// It is okay to import devDependencies in tests.
'import/no-extraneous-dependencies': [2, { devDependencies: true }],
// this doesn't matter for tests
'lines-between-class-members': 0,
// otherwise we need some junk in our fixture code
'react/no-unused-class-component-methods': 0,
},
...(CLIEngine ? { rules } : { overrideConfig: { rules } }),
});

function lint(text) {
async function lint(text) {
// @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles
// @see https://eslint.org/docs/developer-guide/nodejs-api.html#executeontext
const linter = CLIEngine ? cli.executeOnText(text) : cli.lintText(text);
return linter.results[0];
const linter = CLIEngine ? cli.executeOnText(text) : await cli.lintText(text);
return (CLIEngine ? linter.results : linter)[0];
}

function wrapComponent(body) {
Expand All @@ -42,9 +42,8 @@ test('validate react methods order', (t) => {
t.deepEqual(reactA11yRules.plugins, ['jsx-a11y', 'react']);
});

t.test('passes a good component', (t) => {
t.plan(3);
const result = lint(wrapComponent(`
t.test('passes a good component', async (t) => {
const result = await lint(wrapComponent(`
componentDidMount() {}
handleSubmit() {}
onButtonAClick() {}
Expand All @@ -61,9 +60,8 @@ test('validate react methods order', (t) => {
t.notOk(result.errorCount, 'no errors');
});

t.test('order: when random method is first', (t) => {
t.plan(2);
const result = lint(wrapComponent(`
t.test('order: when random method is first', async (t) => {
const result = await lint(wrapComponent(`
someMethod() {}
componentDidMount() {}
setFoo() {}
Expand All @@ -77,9 +75,8 @@ test('validate react methods order', (t) => {
t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort');
});

t.test('order: when random method after lifecycle methods', (t) => {
t.plan(2);
const result = lint(wrapComponent(`
t.test('order: when random method after lifecycle methods', async (t) => {
const result = await lint(wrapComponent(`
componentDidMount() {}
someMethod() {}
setFoo() {}
Expand All @@ -93,9 +90,8 @@ test('validate react methods order', (t) => {
t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort');
});

t.test('order: when handler method with `handle` prefix after method with `on` prefix', (t) => {
t.plan(2);
const result = lint(wrapComponent(`
t.test('order: when handler method with `handle` prefix after method with `on` prefix', async (t) => {
const result = await lint(wrapComponent(`
componentDidMount() {}
onButtonAClick() {}
handleSubmit() {}
Expand All @@ -108,9 +104,8 @@ test('validate react methods order', (t) => {
t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort');
});

t.test('order: when lifecycle methods after event handler methods', (t) => {
t.plan(2);
const result = lint(wrapComponent(`
t.test('order: when lifecycle methods after event handler methods', async (t) => {
const result = await lint(wrapComponent(`
handleSubmit() {}
componentDidMount() {}
setFoo() {}
Expand All @@ -122,9 +117,8 @@ test('validate react methods order', (t) => {
t.deepEqual(result.messages.map((msg) => msg.ruleId), ['react/sort-comp'], 'fails due to sort');
});

t.test('order: when event handler methods after getters and setters', (t) => {
t.plan(2);
const result = lint(wrapComponent(`
t.test('order: when event handler methods after getters and setters', async (t) => {
const result = await lint(wrapComponent(`
componentDidMount() {}
setFoo() {}
getFoo() {}
Expand Down

0 comments on commit 371537f

Please sign in to comment.