Skip to content

Commit c316040

Browse files
authored
test: change test runner to vitest (#525)
* test: change test runner to vitest This change moves the test runner from `mocha` + `nyc` to `vitest`. In order to import `vitest` the tests had to be in esm, so I checked out everything under the `tests` folder from #516 (leaving the source as it was). I also moved the `eslint-rule-tester` out of the `tests/lib` folder and into its own `utils` folder. That way vitest didn't treat it as a test. Note: rather than using `vitest`'s preferred `v8` coverage reporter, I used the `istanbul` one, to ensure the coverages between old and new were the same. I did notice that when I tried the `v8` coverage reporter, the coverage numbers were much less. Something to consider as a follow-up change. The v8 reporter *should* be more accurate, so the coverage may not be as high as it seems. I'd recommend moving up to the `v8` reporter after the esm branch lands. * test: update fixtures tsconfig to use wildcard * build: remove `globals` and packageManager config
1 parent 41a9166 commit c316040

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+146
-186
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.idea
2-
.nyc_output
2+
coverage
33
.vscode
44
node_modules/
55
npm-debug.log

eslint.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const js = require('@eslint/js');
44
const { FlatCompat } = require('@eslint/eslintrc');
5-
const globals = require('globals');
65
const markdown = require('eslint-plugin-markdown');
76
const pluginN = require('eslint-plugin-n');
87
const eslintPluginConfig = require('eslint-plugin-eslint-plugin/configs/all');
@@ -54,7 +53,7 @@ module.exports = [
5453
},
5554
{
5655
files: ['tests/**/*.js'],
57-
languageOptions: { globals: globals.mocha },
56+
languageOptions: { sourceType: 'module' },
5857
},
5958
{
6059
files: ['**/*.md'],

package.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"lint:js-docs": "eslint --no-inline-config \"**/*.md\"",
1919
"lint:package-json": "npmPkgJsonLint .",
2020
"release": "release-it",
21-
"test": "nyc --all --check-coverage --include lib mocha tests --recursive",
21+
"test": "vitest run --coverage",
2222
"test:remote": "eslint-remote-tester -c ./eslint-remote-tester.config.mjs",
2323
"update:eslint-docs": "eslint-doc-generator"
2424
},
@@ -43,12 +43,6 @@
4343
"@eslint-community/eslint-utils": "^4.4.0",
4444
"estraverse": "^5.3.0"
4545
},
46-
"nyc": {
47-
"branches": 95,
48-
"functions": 99,
49-
"lines": 99,
50-
"statements": 99
51-
},
5246
"devDependencies": {
5347
"@commitlint/cli": "^19.6.0",
5448
"@commitlint/config-conventional": "^19.6.0",
@@ -60,7 +54,7 @@
6054
"@types/estree": "^1.0.8",
6155
"@typescript-eslint/parser": "^8.34.1",
6256
"@typescript-eslint/utils": "^8.34.1",
63-
"chai": "^4.5.0",
57+
"@vitest/coverage-istanbul": "^3.2.4",
6458
"eslint": "^9.16.0",
6559
"eslint-config-not-an-aardvark": "^2.1.0",
6660
"eslint-config-prettier": "^9.1.0",
@@ -73,17 +67,15 @@
7367
"eslint-remote-tester": "^4.0.1",
7468
"eslint-scope": "^8.0.1",
7569
"espree": "^10.0.1",
76-
"globals": "^15.13.0",
7770
"husky": "^9.1.7",
7871
"lodash": "^4.17.21",
7972
"markdownlint-cli": "^0.43.0",
80-
"mocha": "^11.0.0",
8173
"npm-package-json-lint": "^8.0.0",
8274
"npm-run-all2": "^7.0.1",
83-
"nyc": "^17.1.0",
8475
"prettier": "^3.4.1",
8576
"release-it": "^17.2.0",
86-
"typescript": "^5.8.3"
77+
"typescript": "^5.8.3",
78+
"vitest": "^3.2.4"
8779
},
8880
"peerDependencies": {
8981
"eslint": ">=8.23.0"

tests/lib/eslint-rule-tester.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/lib/fixtures/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
33
"moduleResolution": "NodeNext"
4-
}
4+
},
5+
"include": ["*.ts"]
56
}

tests/lib/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
'use strict';
1+
import { assert, describe, it } from 'vitest';
22

3-
const assert = require('chai').assert;
4-
const plugin = require('../..');
3+
import plugin from '../../lib/index.js';
54

65
const RULE_NAMES = Object.keys(plugin.rules);
76

tests/lib/rule-setup.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
'use strict';
1+
import { readdirSync, readFileSync } from 'node:fs';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
24

3-
const { readdirSync, readFileSync } = require('fs');
4-
const path = require('path');
5-
const assert = require('chai').assert;
6-
const plugin = require('../..');
5+
import { assert, describe, it } from 'vitest';
6+
7+
import plugin from '../../lib/index.js';
78

89
const RULE_NAMES = Object.keys(plugin.rules);
10+
const dirname = path.dirname(fileURLToPath(import.meta.url));
911

1012
describe('rule setup is correct', () => {
1113
it('should have a list of exported rules and rules directory that match', () => {
12-
const filePath = path.join(__dirname, '..', 'lib', 'rules');
14+
const filePath = path.join(dirname, '..', 'lib', 'rules');
1315
const files = readdirSync(filePath);
1416

1517
assert.deepStrictEqual(
@@ -34,7 +36,7 @@ describe('rule setup is correct', () => {
3436

3537
it('should have the right contents', () => {
3638
const filePath = path.join(
37-
__dirname,
39+
dirname,
3840
'..',
3941
'..',
4042
'lib',
@@ -53,7 +55,7 @@ describe('rule setup is correct', () => {
5355
});
5456

5557
it('should have tests for all rules', () => {
56-
const filePath = path.join(__dirname, 'rules');
58+
const filePath = path.join(dirname, 'rules');
5759
const files = readdirSync(filePath);
5860

5961
assert.deepStrictEqual(
@@ -65,7 +67,7 @@ describe('rule setup is correct', () => {
6567
});
6668

6769
it('should have documentation for all rules', () => {
68-
const filePath = path.join(__dirname, '..', '..', 'docs', 'rules');
70+
const filePath = path.join(dirname, '..', '..', 'docs', 'rules');
6971
const files = readdirSync(filePath);
7072

7173
assert.deepStrictEqual(

tests/lib/rules/consistent-output.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
* @author Teddy Katz
44
*/
55

6-
'use strict';
7-
86
// ------------------------------------------------------------------------------
97
// Requirements
108
// ------------------------------------------------------------------------------
119

12-
const rule = require('../../../lib/rules/consistent-output');
13-
const RuleTester = require('../eslint-rule-tester').RuleTester;
10+
import rule from '../../../lib/rules/consistent-output.js';
11+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
1412

1513
const ERROR = { messageId: 'missingOutput', type: 'ObjectExpression' };
1614

tests/lib/rules/fixer-return.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
* @author 薛定谔的猫<[email protected]>
44
*/
55

6-
'use strict';
7-
86
// ------------------------------------------------------------------------------
97
// Requirements
108
// ------------------------------------------------------------------------------
119

12-
const rule = require('../../../lib/rules/fixer-return');
13-
const RuleTester = require('../eslint-rule-tester').RuleTester;
10+
import rule from '../../../lib/rules/fixer-return.js';
11+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
1412

1513
// ------------------------------------------------------------------------------
1614
// Tests

tests/lib/rules/meta-property-ordering.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
* @fileoverview Enforces the order of meta properties
33
*/
44

5-
'use strict';
6-
75
// ------------------------------------------------------------------------------
86
// Requirements
97
// ------------------------------------------------------------------------------
108

11-
const rule = require('../../../lib/rules/meta-property-ordering');
12-
const RuleTester = require('../eslint-rule-tester').RuleTester;
9+
import rule from '../../../lib/rules/meta-property-ordering.js';
10+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
1311

1412
// ------------------------------------------------------------------------------
1513
// Tests

tests/lib/rules/no-deprecated-context-methods.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
* @author Teddy Katz
44
*/
55

6-
'use strict';
7-
86
// ------------------------------------------------------------------------------
97
// Requirements
108
// ------------------------------------------------------------------------------
119

12-
const rule = require('../../../lib/rules/no-deprecated-context-methods');
13-
const RuleTester = require('../eslint-rule-tester').RuleTester;
10+
import rule from '../../../lib/rules/no-deprecated-context-methods.js';
11+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
1412

1513
// ------------------------------------------------------------------------------
1614
// Tests

tests/lib/rules/no-deprecated-report-api.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
* @author Teddy Katz
44
*/
55

6-
'use strict';
7-
86
// ------------------------------------------------------------------------------
97
// Requirements
108
// ------------------------------------------------------------------------------
119

12-
const rule = require('../../../lib/rules/no-deprecated-report-api');
13-
const RuleTester = require('../eslint-rule-tester').RuleTester;
10+
import rule from '../../../lib/rules/no-deprecated-report-api.js';
11+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
1412

1513
// ------------------------------------------------------------------------------
1614
// Tests

tests/lib/rules/no-identical-tests.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
* @author 薛定谔的猫<[email protected]>
44
*/
55

6-
'use strict';
7-
86
// ------------------------------------------------------------------------------
97
// Requirements
108
// ------------------------------------------------------------------------------
119

12-
const rule = require('../../../lib/rules/no-identical-tests');
13-
const RuleTester = require('../eslint-rule-tester').RuleTester;
10+
import rule from '../../../lib/rules/no-identical-tests.js';
11+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
1412

1513
const ERROR_OBJECT_TEST = { messageId: 'identical', type: 'ObjectExpression' };
1614
const ERROR_STRING_TEST = { messageId: 'identical', type: 'Literal' };

tests/lib/rules/no-meta-replaced-by.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
* @fileoverview Disallows the usage of `meta.replacedBy` property
33
*/
44

5-
'use strict';
6-
75
// ------------------------------------------------------------------------------
86
// Requirements
97
// ------------------------------------------------------------------------------
108

11-
const rule = require('../../../lib/rules/no-meta-replaced-by');
12-
const RuleTester = require('../eslint-rule-tester').RuleTester;
9+
import rule from '../../../lib/rules/no-meta-replaced-by.js';
10+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
1311

1412
// ------------------------------------------------------------------------------
1513
// Tests

tests/lib/rules/no-meta-schema-default.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
'use strict';
2-
31
// ------------------------------------------------------------------------------
42
// Requirements
53
// ------------------------------------------------------------------------------
64

7-
const rule = require('../../../lib/rules/no-meta-schema-default');
8-
const RuleTester = require('../eslint-rule-tester').RuleTester;
5+
import rule from '../../../lib/rules/no-meta-schema-default.js';
6+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
97

108
// ------------------------------------------------------------------------------
119
// Tests

tests/lib/rules/no-missing-message-ids.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
'use strict';
2-
31
// ------------------------------------------------------------------------------
42
// Requirements
53
// ------------------------------------------------------------------------------
64

7-
const rule = require('../../../lib/rules/no-missing-message-ids');
8-
const RuleTester = require('../eslint-rule-tester').RuleTester;
5+
import rule from '../../../lib/rules/no-missing-message-ids.js';
6+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
97

108
// ------------------------------------------------------------------------------
119
// Tests

tests/lib/rules/no-missing-placeholders.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
* @author Teddy Katz
44
*/
55

6-
'use strict';
7-
86
// ------------------------------------------------------------------------------
97
// Requirements
108
// ------------------------------------------------------------------------------
119

12-
const rule = require('../../../lib/rules/no-missing-placeholders');
13-
const RuleTester = require('../eslint-rule-tester').RuleTester;
10+
import rule from '../../../lib/rules/no-missing-placeholders.js';
11+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
1412

1513
/**
1614
* Create an error for the given key

tests/lib/rules/no-only-tests.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
'use strict';
2-
31
// ------------------------------------------------------------------------------
42
// Requirements
53
// ------------------------------------------------------------------------------
64

7-
const rule = require('../../../lib/rules/no-only-tests');
8-
const RuleTester = require('../eslint-rule-tester').RuleTester;
5+
import rule from '../../../lib/rules/no-only-tests.js';
6+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
97

108
// ------------------------------------------------------------------------------
119
// Tests

tests/lib/rules/no-property-in-node.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
'use strict';
2-
3-
const RuleTester = require('../eslint-rule-tester').RuleTester;
4-
const path = require('path');
5-
const rule = require('../../../lib/rules/no-property-in-node');
1+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
2+
import path from 'path';
3+
import rule from '../../../lib/rules/no-property-in-node.js';
4+
import parser from '@typescript-eslint/parser';
65

76
const ruleTester = new RuleTester({
87
languageOptions: {
9-
parser: require('@typescript-eslint/parser'),
8+
parser,
109
parserOptions: {
1110
projectService: {
1211
defaultProject: 'tsconfig.json',

tests/lib/rules/no-unused-message-ids.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
'use strict';
2-
31
// ------------------------------------------------------------------------------
42
// Requirements
53
// ------------------------------------------------------------------------------
64

7-
const rule = require('../../../lib/rules/no-unused-message-ids');
8-
const RuleTester = require('../eslint-rule-tester').RuleTester;
5+
import rule from '../../../lib/rules/no-unused-message-ids.js';
6+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
97

108
// ------------------------------------------------------------------------------
119
// Tests

tests/lib/rules/no-unused-placeholders.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
* @author 薛定谔的猫<[email protected]>
44
*/
55

6-
'use strict';
7-
86
// ------------------------------------------------------------------------------
97
// Requirements
108
// ------------------------------------------------------------------------------
119

12-
const rule = require('../../../lib/rules/no-unused-placeholders');
13-
const RuleTester = require('../eslint-rule-tester').RuleTester;
10+
import rule from '../../../lib/rules/no-unused-placeholders.js';
11+
import { RuleTester } from '../../utils/eslint-rule-tester.js';
1412

1513
/**
1614
* Create an error for the given key

0 commit comments

Comments
 (0)