Skip to content

Commit 9f52921

Browse files
committed
Replace jest with the node built-in test runner
1 parent 35ac519 commit 9f52921

File tree

7 files changed

+57
-1669
lines changed

7 files changed

+57
-1669
lines changed

.eslintrc.cjs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,4 @@ module.exports = {
1818
{ignores: ['dynamicImport']},
1919
],
2020
},
21-
overrides: [
22-
{
23-
files: ['**/*.test.js'],
24-
env: {jest: true},
25-
globals: {testRule: true},
26-
},
27-
],
2821
};

.github/CONTRIBUTING.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ yarn run test
1818

1919
This is a [Stylelint](https://stylelint.io/) plugin. Documentation for the APIs that it uses can be found on Stylelint's [Writing Plugins](https://stylelint.io/developer-guide/plugins/) page.
2020

21-
Linting is ran as part of `yarn run test`. The build will fail if there are any linting errors. You can run `yarn run lint --fix` to fix some linting errors (including formatting to match prettier's expectations). To run the tests without linting run `yarn run jest`.
22-
23-
This plugin is used to lint itself. The style is checked when `npm test` is run, and the build will fail if there are any linting errors. You can use `npm run lint -- --fix` to fix some linting errors. To run the tests without running the linter, you can use `node_modules/.bin/mocha`.
21+
Linting is ran as part of `yarn run test`. The build will fail if there are any linting errors. You can run `yarn run lint --fix` to fix some linting errors (including formatting to match prettier's expectations). To run the tests without linting run `node --test test/*.test.js`.
2422

2523
### End to end tests
2624

jest-setup.js

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

package.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"scripts": {
2323
"lint": "eslint .",
24-
"test": "yarn run lint && node --experimental-vm-modules node_modules/jest/bin/jest.js",
24+
"test": "yarn run lint && node --test test/*.test.js",
2525
"format": "yarn run prettier '**/*.{js,json,md}' --write && yarn run lint --fix"
2626
},
2727
"repository": {
@@ -44,8 +44,6 @@
4444
"eslint-config-prettier": "^9.0.0",
4545
"eslint-plugin-n": "^15.7.0",
4646
"eslint-plugin-prettier": "^5.0.0",
47-
"jest": "^29.6.1",
48-
"jest-preset-stylelint": "^7.0.0",
4947
"postcss": "^8.4.25",
5048
"postcss-html": "^1.5.0",
5149
"postcss-markdown": "^1.2.0",
@@ -57,18 +55,12 @@
5755
"prettier-plugin-svelte": "^3.0.0",
5856
"strip-ansi": "^6.0.0",
5957
"stylelint": "^16.0.1",
58+
"stylelint-test-rule-node": "^0.2.0",
6059
"svelte": "^4.1.0",
6160
"typescript": "5.3.2"
6261
},
6362
"engines": {
6463
"node": ">=18.12.0"
6564
},
66-
"jest": {
67-
"preset": "jest-preset-stylelint",
68-
"transform": {},
69-
"setupFiles": [
70-
"./jest-setup.js"
71-
]
72-
},
7365
"license": "MIT"
7466
}

test/stylelint-prettier-e2e.test.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {describe, test} from 'node:test';
2+
import assert from 'node:assert/strict';
13
import {spawnSync} from 'node:child_process';
24
import {resolve, dirname} from 'node:path';
35
import {fileURLToPath} from 'node:url';
@@ -22,9 +24,9 @@ check.invalid.css
2224
1 problem (1 error, 0 warnings)
2325
`.trim();
2426

25-
expect(result.output).toEqual('');
26-
expect(result.error).toEqual(expectedResult);
27-
expect(result.status).toEqual(2);
27+
assert.strictEqual(result.output, '');
28+
assert.strictEqual(result.error, expectedResult);
29+
assert.strictEqual(result.status, 2);
2830
});
2931

3032
test('SCSS files', () => {
@@ -38,9 +40,9 @@ check.invalid.scss
3840
2 problems (2 errors, 0 warnings)
3941
`.trim();
4042

41-
expect(result.output).toEqual('');
42-
expect(result.error).toEqual(expectedResult);
43-
expect(result.status).toEqual(2);
43+
assert.strictEqual(result.output, '');
44+
assert.strictEqual(result.error, expectedResult);
45+
assert.strictEqual(result.status, 2);
4446
});
4547

4648
/**
@@ -52,9 +54,9 @@ check.invalid.scss
5254

5355
const expectedResult = ``;
5456

55-
expect(result.output).toEqual('');
56-
expect(result.error).toEqual(expectedResult);
57-
expect(result.status).toEqual(0);
57+
assert.strictEqual(result.output, '');
58+
assert.strictEqual(result.error, expectedResult);
59+
assert.strictEqual(result.status, 0);
5860
});
5961

6062
/**
@@ -66,9 +68,9 @@ check.invalid.scss
6668

6769
const expectedResult = ``;
6870

69-
expect(result.output).toEqual('');
70-
expect(result.error).toEqual(expectedResult);
71-
expect(result.status).toEqual(0);
71+
assert.strictEqual(result.output, '');
72+
assert.strictEqual(result.error, expectedResult);
73+
assert.strictEqual(result.status, 0);
7274
});
7375
});
7476

test/stylelint-prettier.test.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
import {describe, it, beforeEach, afterEach, mock} from 'node:test';
2+
import assert from 'node:assert/strict';
13
import path from 'node:path';
24
import {fileURLToPath} from 'node:url';
35
import stylelint from 'stylelint';
6+
import {testRule} from 'stylelint-test-rule-node';
47
import plugin from '../index.js';
58

69
const __dirname = path.dirname(fileURLToPath(import.meta.url));
10+
const plugins = [plugin];
711
const {ruleName} = plugin;
812

913
// Reading from default .prettierrc
1014
testRule({
15+
plugins,
1116
ruleName,
1217
config: true,
1318
codeFilename: filename('default'),
@@ -56,6 +61,7 @@ testRule({
5661

5762
// Reading from custom .prettierrc
5863
testRule({
64+
plugins,
5965
ruleName,
6066
config: true,
6167
codeFilename: filename('custom'),
@@ -104,6 +110,7 @@ testRule({
104110

105111
// Merging options from config into .prettierrc
106112
testRule({
113+
plugins,
107114
ruleName,
108115
config: [true, {tabWidth: 8}],
109116
codeFilename: filename('default'),
@@ -152,6 +159,7 @@ testRule({
152159

153160
// Use the css parser if no filename was specified
154161
testRule({
162+
plugins,
155163
ruleName,
156164
config: true,
157165
fix: true,
@@ -178,6 +186,7 @@ testRule({
178186

179187
// Use the parser specified in overrides in .prettierrc
180188
testRule({
189+
plugins,
181190
ruleName,
182191
config: true,
183192
customSyntax: 'postcss',
@@ -204,6 +213,7 @@ testRule({
204213

205214
// Ignoring files in .prettierignore
206215
testRule({
216+
plugins,
207217
ruleName,
208218
config: true,
209219
codeFilename: filename('default', 'ignore-me.css'),
@@ -217,6 +227,7 @@ testRule({
217227

218228
// Testing Comments
219229
testRule({
230+
plugins,
220231
ruleName,
221232
config: [true, {endOfLine: 'auto'}],
222233
codeFilename: filename('default'),
@@ -338,6 +349,7 @@ const stressTestCssExpected = `.foo {
338349
`;
339350

340351
testRule({
352+
plugins,
341353
ruleName,
342354
config: true,
343355
codeFilename: filename('default'),
@@ -573,6 +585,7 @@ $pip-animation: (
573585
`;
574586

575587
testRule({
588+
plugins,
576589
ruleName,
577590
config: true,
578591
codeFilename: filename('default', 'dummy.scss'),
@@ -620,6 +633,7 @@ testRule({
620633

621634
// Test trailing commas in near-empty scss files
622635
testRule({
636+
plugins,
623637
ruleName,
624638
config: [true, {trailingComma: 'all'}],
625639
codeFilename: filename('default', 'dummy.scss'),
@@ -648,6 +662,7 @@ testRule({
648662

649663
// Passing a syntax works
650664
testRule({
665+
plugins,
651666
ruleName,
652667
config: [true, {parser: 'scss', trailingComma: 'all'}],
653668
customSyntax: 'postcss-scss',
@@ -674,6 +689,7 @@ testRule({
674689

675690
// EOL Tests
676691
testRule({
692+
plugins,
677693
ruleName,
678694
config: [true, {endOfLine: 'auto'}],
679695
fix: true,
@@ -714,15 +730,15 @@ testRule({
714730
describe('stylelint configurations', () => {
715731
const oldWarn = console.warn;
716732
beforeEach(() => {
717-
console.warn = jest.fn(console.warn);
733+
console.warn = mock.fn(console.warn);
718734
});
719735

720736
afterEach(() => {
721737
console.warn = oldWarn;
722738
});
723739

724-
it("doesn't raise prettier warnings on `message`", () => {
725-
const linted = stylelint.lint({
740+
it("doesn't raise prettier warnings on `message`", async () => {
741+
await stylelint.lint({
726742
code: ``,
727743
config: {
728744
plugins: ['./'],
@@ -732,15 +748,11 @@ describe('stylelint configurations', () => {
732748
},
733749
});
734750

735-
return linted.then(() => {
736-
expect(console.warn).not.toHaveBeenCalledWith(
737-
expect.stringMatching(/ignored unknown option.+message/i)
738-
);
739-
});
751+
assert.strictEqual(console.warn.mock.calls.length, 0);
740752
});
741753

742-
it("doesn't raise prettier warnings on `severity`", () => {
743-
const linted = stylelint.lint({
754+
it("doesn't raise prettier warnings on `severity`", async () => {
755+
await stylelint.lint({
744756
code: ``,
745757
config: {
746758
plugins: ['./'],
@@ -750,11 +762,7 @@ describe('stylelint configurations', () => {
750762
},
751763
});
752764

753-
return linted.then(() => {
754-
expect(console.warn).not.toHaveBeenCalledWith(
755-
expect.stringMatching(/ignored unknown option.+severity/i)
756-
);
757-
});
765+
assert.strictEqual(console.warn.mock.calls.length, 0);
758766
});
759767
});
760768

0 commit comments

Comments
 (0)