Skip to content

Commit

Permalink
Replace jest with the node built-in test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
BPScott committed Dec 10, 2023
1 parent 35ac519 commit 9f52921
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 1,669 deletions.
7 changes: 0 additions & 7 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@ module.exports = {
{ignores: ['dynamicImport']},
],
},
overrides: [
{
files: ['**/*.test.js'],
env: {jest: true},
globals: {testRule: true},
},
],
};
4 changes: 1 addition & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ yarn run test

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.

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`.

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`.
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`.

### End to end tests

Expand Down
3 changes: 0 additions & 3 deletions jest-setup.js

This file was deleted.

12 changes: 2 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"scripts": {
"lint": "eslint .",
"test": "yarn run lint && node --experimental-vm-modules node_modules/jest/bin/jest.js",
"test": "yarn run lint && node --test test/*.test.js",
"format": "yarn run prettier '**/*.{js,json,md}' --write && yarn run lint --fix"
},
"repository": {
Expand All @@ -44,8 +44,6 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.6.1",
"jest-preset-stylelint": "^7.0.0",
"postcss": "^8.4.25",
"postcss-html": "^1.5.0",
"postcss-markdown": "^1.2.0",
Expand All @@ -57,18 +55,12 @@
"prettier-plugin-svelte": "^3.0.0",
"strip-ansi": "^6.0.0",
"stylelint": "^16.0.1",
"stylelint-test-rule-node": "^0.2.0",
"svelte": "^4.1.0",
"typescript": "5.3.2"
},
"engines": {
"node": ">=18.12.0"
},
"jest": {
"preset": "jest-preset-stylelint",
"transform": {},
"setupFiles": [
"./jest-setup.js"
]
},
"license": "MIT"
}
26 changes: 14 additions & 12 deletions test/stylelint-prettier-e2e.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {describe, test} from 'node:test';
import assert from 'node:assert/strict';
import {spawnSync} from 'node:child_process';
import {resolve, dirname} from 'node:path';
import {fileURLToPath} from 'node:url';
Expand All @@ -22,9 +24,9 @@ check.invalid.css
1 problem (1 error, 0 warnings)
`.trim();

expect(result.output).toEqual('');
expect(result.error).toEqual(expectedResult);
expect(result.status).toEqual(2);
assert.strictEqual(result.output, '');
assert.strictEqual(result.error, expectedResult);
assert.strictEqual(result.status, 2);
});

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

expect(result.output).toEqual('');
expect(result.error).toEqual(expectedResult);
expect(result.status).toEqual(2);
assert.strictEqual(result.output, '');
assert.strictEqual(result.error, expectedResult);
assert.strictEqual(result.status, 2);
});

/**
Expand All @@ -52,9 +54,9 @@ check.invalid.scss

const expectedResult = ``;

expect(result.output).toEqual('');
expect(result.error).toEqual(expectedResult);
expect(result.status).toEqual(0);
assert.strictEqual(result.output, '');
assert.strictEqual(result.error, expectedResult);
assert.strictEqual(result.status, 0);
});

/**
Expand All @@ -66,9 +68,9 @@ check.invalid.scss

const expectedResult = ``;

expect(result.output).toEqual('');
expect(result.error).toEqual(expectedResult);
expect(result.status).toEqual(0);
assert.strictEqual(result.output, '');
assert.strictEqual(result.error, expectedResult);
assert.strictEqual(result.status, 0);
});
});

Expand Down
38 changes: 23 additions & 15 deletions test/stylelint-prettier.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {describe, it, beforeEach, afterEach, mock} from 'node:test';
import assert from 'node:assert/strict';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import stylelint from 'stylelint';
import {testRule} from 'stylelint-test-rule-node';
import plugin from '../index.js';

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

// Reading from default .prettierrc
testRule({
plugins,
ruleName,
config: true,
codeFilename: filename('default'),
Expand Down Expand Up @@ -56,6 +61,7 @@ testRule({

// Reading from custom .prettierrc
testRule({
plugins,
ruleName,
config: true,
codeFilename: filename('custom'),
Expand Down Expand Up @@ -104,6 +110,7 @@ testRule({

// Merging options from config into .prettierrc
testRule({
plugins,
ruleName,
config: [true, {tabWidth: 8}],
codeFilename: filename('default'),
Expand Down Expand Up @@ -152,6 +159,7 @@ testRule({

// Use the css parser if no filename was specified
testRule({
plugins,
ruleName,
config: true,
fix: true,
Expand All @@ -178,6 +186,7 @@ testRule({

// Use the parser specified in overrides in .prettierrc
testRule({
plugins,
ruleName,
config: true,
customSyntax: 'postcss',
Expand All @@ -204,6 +213,7 @@ testRule({

// Ignoring files in .prettierignore
testRule({
plugins,
ruleName,
config: true,
codeFilename: filename('default', 'ignore-me.css'),
Expand All @@ -217,6 +227,7 @@ testRule({

// Testing Comments
testRule({
plugins,
ruleName,
config: [true, {endOfLine: 'auto'}],
codeFilename: filename('default'),
Expand Down Expand Up @@ -338,6 +349,7 @@ const stressTestCssExpected = `.foo {
`;

testRule({
plugins,
ruleName,
config: true,
codeFilename: filename('default'),
Expand Down Expand Up @@ -573,6 +585,7 @@ $pip-animation: (
`;

testRule({
plugins,
ruleName,
config: true,
codeFilename: filename('default', 'dummy.scss'),
Expand Down Expand Up @@ -620,6 +633,7 @@ testRule({

// Test trailing commas in near-empty scss files
testRule({
plugins,
ruleName,
config: [true, {trailingComma: 'all'}],
codeFilename: filename('default', 'dummy.scss'),
Expand Down Expand Up @@ -648,6 +662,7 @@ testRule({

// Passing a syntax works
testRule({
plugins,
ruleName,
config: [true, {parser: 'scss', trailingComma: 'all'}],
customSyntax: 'postcss-scss',
Expand All @@ -674,6 +689,7 @@ testRule({

// EOL Tests
testRule({
plugins,
ruleName,
config: [true, {endOfLine: 'auto'}],
fix: true,
Expand Down Expand Up @@ -714,15 +730,15 @@ testRule({
describe('stylelint configurations', () => {
const oldWarn = console.warn;
beforeEach(() => {
console.warn = jest.fn(console.warn);
console.warn = mock.fn(console.warn);
});

afterEach(() => {
console.warn = oldWarn;
});

it("doesn't raise prettier warnings on `message`", () => {
const linted = stylelint.lint({
it("doesn't raise prettier warnings on `message`", async () => {
await stylelint.lint({
code: ``,
config: {
plugins: ['./'],
Expand All @@ -732,15 +748,11 @@ describe('stylelint configurations', () => {
},
});

return linted.then(() => {
expect(console.warn).not.toHaveBeenCalledWith(
expect.stringMatching(/ignored unknown option.+message/i)
);
});
assert.strictEqual(console.warn.mock.calls.length, 0);
});

it("doesn't raise prettier warnings on `severity`", () => {
const linted = stylelint.lint({
it("doesn't raise prettier warnings on `severity`", async () => {
await stylelint.lint({
code: ``,
config: {
plugins: ['./'],
Expand All @@ -750,11 +762,7 @@ describe('stylelint configurations', () => {
},
});

return linted.then(() => {
expect(console.warn).not.toHaveBeenCalledWith(
expect.stringMatching(/ignored unknown option.+severity/i)
);
});
assert.strictEqual(console.warn.mock.calls.length, 0);
});
});

Expand Down
Loading

0 comments on commit 9f52921

Please sign in to comment.