jest-preset-stylelint 6.3.2 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -7
- package/getTestRule.js +7 -5
- package/getTestRuleConfigs.js +3 -3
- package/index.d.ts +1 -1
- package/package.json +30 -18
package/README.md
CHANGED
|
@@ -22,16 +22,21 @@ Add the preset to your `jest.config.js` or `jest` field in `package.json`:
|
|
|
22
22
|
}
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
### Adjust setup globally
|
|
26
|
+
|
|
25
27
|
Optionally, you can avoid specifying `plugins` in every schema by defining your own setup file to configure the `testRule`/`testRuleConfigs` functions.
|
|
26
28
|
This is useful if you have many tests. There are two additional steps to do this:
|
|
27
29
|
|
|
28
30
|
1. Create `jest.setup.js` in the root of your project. Provide `plugins` option to `getTestRule`/`getTestRuleConfigs`:
|
|
29
31
|
|
|
30
32
|
```js
|
|
31
|
-
|
|
33
|
+
import { getTestRule, getTestRuleConfigs } from "jest-preset-stylelint";
|
|
34
|
+
import myPlugin from "./my-plugin.js";
|
|
35
|
+
|
|
36
|
+
const plugins = [myPlugin];
|
|
32
37
|
|
|
33
|
-
global.testRule = getTestRule({ plugins
|
|
34
|
-
global.testRuleConfigs = getTestRuleConfigs({ plugins
|
|
38
|
+
global.testRule = getTestRule({ plugins });
|
|
39
|
+
global.testRuleConfigs = getTestRuleConfigs({ plugins });
|
|
35
40
|
```
|
|
36
41
|
|
|
37
42
|
2. Add `jest.setup.js` to your `jest.config.js` or `jest` field in `package.json`:
|
|
@@ -39,10 +44,21 @@ This is useful if you have many tests. There are two additional steps to do this
|
|
|
39
44
|
```json
|
|
40
45
|
{
|
|
41
46
|
"preset": "jest-preset-stylelint",
|
|
42
|
-
"setupFiles": ["jest.setup.js"]
|
|
47
|
+
"setupFiles": ["<rootDir>/jest.setup.js"]
|
|
43
48
|
}
|
|
44
49
|
```
|
|
45
50
|
|
|
51
|
+
### Prevent segmentation fault
|
|
52
|
+
|
|
53
|
+
If you get a segmentation fault while running the preset on Node.js 18, you can use [jest-light-runner](https://www.npmjs.com/package/jest-light-runner):
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"preset": "jest-preset-stylelint",
|
|
58
|
+
"runner": "jest-light-runner"
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
46
62
|
## Usage
|
|
47
63
|
|
|
48
64
|
This preset exposes the following global functions as a helper.
|
|
@@ -57,10 +73,16 @@ For example, we can test a plugin that enforces and autofixes kebab-case class s
|
|
|
57
73
|
|
|
58
74
|
```js
|
|
59
75
|
// my-plugin.test.js
|
|
60
|
-
|
|
76
|
+
import myPlugin from "./my-plugin.js";
|
|
77
|
+
|
|
78
|
+
const plugins = [myPlugin];
|
|
79
|
+
const {
|
|
80
|
+
ruleName,
|
|
81
|
+
rule: { messages }
|
|
82
|
+
} = myPlugin;
|
|
61
83
|
|
|
62
84
|
testRule({
|
|
63
|
-
plugins
|
|
85
|
+
plugins,
|
|
64
86
|
ruleName,
|
|
65
87
|
config: [true, { type: "kebab" }],
|
|
66
88
|
fix: true,
|
|
@@ -120,7 +142,7 @@ For example:
|
|
|
120
142
|
|
|
121
143
|
```js
|
|
122
144
|
testRuleConfigs({
|
|
123
|
-
plugins
|
|
145
|
+
plugins,
|
|
124
146
|
ruleName,
|
|
125
147
|
|
|
126
148
|
accept: [
|
package/getTestRule.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { inspect } = require('node:util');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {import('.').TestCase} TestCase
|
|
@@ -11,9 +11,11 @@ const util = require('util');
|
|
|
11
11
|
module.exports = function getTestRule(options = {}) {
|
|
12
12
|
return function testRule(schema) {
|
|
13
13
|
const loadLint =
|
|
14
|
-
schema.loadLint ||
|
|
14
|
+
schema.loadLint ||
|
|
15
|
+
options.loadLint ||
|
|
16
|
+
(() => import('stylelint').then((m) => m.default.lint)); // eslint-disable-line n/no-unpublished-import -- Avoid auto-install of `stylelint` peer dependency.
|
|
15
17
|
|
|
16
|
-
/** @type {import('stylelint').lint} */
|
|
18
|
+
/** @type {import('stylelint').PublicApi['lint']} */
|
|
17
19
|
let lint;
|
|
18
20
|
|
|
19
21
|
beforeAll(async () => {
|
|
@@ -177,8 +179,8 @@ function setupTestCases({ name, cases, schema, comparisons }) {
|
|
|
177
179
|
if (testCase) {
|
|
178
180
|
const spec = testCase.only ? it.only : testCase.skip ? it.skip : it;
|
|
179
181
|
|
|
180
|
-
describe(`${
|
|
181
|
-
describe(`${
|
|
182
|
+
describe(`${inspect(schema.config)}`, () => {
|
|
183
|
+
describe(`${inspect(testCase.code)}`, () => {
|
|
182
184
|
spec(testCase.description || 'no description', comparisons(testCase));
|
|
183
185
|
});
|
|
184
186
|
});
|
package/getTestRuleConfigs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { inspect } = require('util');
|
|
3
|
+
const { inspect } = require('node:util');
|
|
4
4
|
|
|
5
5
|
/** @type {import('.').getTestRuleConfigs} */
|
|
6
6
|
module.exports = function getTestRuleConfigs(options = {}) {
|
|
@@ -18,9 +18,9 @@ module.exports = function getTestRuleConfigs(options = {}) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const loadLint =
|
|
21
|
-
schemaLoadLint || options.loadLint || (() =>
|
|
21
|
+
schemaLoadLint || options.loadLint || (() => import('stylelint').then((m) => m.default.lint)); // eslint-disable-line n/no-unpublished-import -- Avoid auto-install of `stylelint` peer dependency.
|
|
22
22
|
|
|
23
|
-
/** @type {import('stylelint').lint} */
|
|
23
|
+
/** @type {import('stylelint').PublicApi['lint']} */
|
|
24
24
|
let lint;
|
|
25
25
|
|
|
26
26
|
beforeAll(async () => {
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-preset-stylelint",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Jest preset for Stylelint plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"stylelint",
|
|
@@ -9,6 +9,16 @@
|
|
|
9
9
|
"preset"
|
|
10
10
|
],
|
|
11
11
|
"repository": "stylelint/jest-preset-stylelint",
|
|
12
|
+
"funding": [
|
|
13
|
+
{
|
|
14
|
+
"type": "opencollective",
|
|
15
|
+
"url": "https://opencollective.com/stylelint"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"type": "github",
|
|
19
|
+
"url": "https://github.com/sponsors/stylelint"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
12
22
|
"license": "MIT",
|
|
13
23
|
"author": "stylelint",
|
|
14
24
|
"main": "index.js",
|
|
@@ -30,9 +40,9 @@
|
|
|
30
40
|
"lint:types": "tsc",
|
|
31
41
|
"release": "np --no-release-draft",
|
|
32
42
|
"pretest": "npm run lint",
|
|
33
|
-
"test": "jest",
|
|
34
|
-
"watch": "
|
|
35
|
-
"prepare": "husky
|
|
43
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
44
|
+
"watch": "npm --ignore-scripts test -- --watch",
|
|
45
|
+
"prepare": "husky"
|
|
36
46
|
},
|
|
37
47
|
"lint-staged": {
|
|
38
48
|
"*.js": "eslint --cache --fix",
|
|
@@ -58,29 +68,31 @@
|
|
|
58
68
|
},
|
|
59
69
|
"jest": {
|
|
60
70
|
"preset": "./jest-preset.js",
|
|
61
|
-
"
|
|
71
|
+
"runner": "jest-light-runner",
|
|
72
|
+
"testRegex": ".*\\.test\\.m?js$"
|
|
62
73
|
},
|
|
63
74
|
"devDependencies": {
|
|
64
75
|
"@stylelint/prettier-config": "^3.0.0",
|
|
65
|
-
"@stylelint/remark-preset": "^5.
|
|
66
|
-
"@types/jest": "^29.5.
|
|
67
|
-
"eslint": "^8.
|
|
68
|
-
"eslint-config-stylelint": "^
|
|
69
|
-
"eslint-plugin-jest": "^
|
|
70
|
-
"husky": "^
|
|
76
|
+
"@stylelint/remark-preset": "^5.1.0",
|
|
77
|
+
"@types/jest": "^29.5.12",
|
|
78
|
+
"eslint": "^8.57.0",
|
|
79
|
+
"eslint-config-stylelint": "^21.0.0",
|
|
80
|
+
"eslint-plugin-jest": "^28.5.0",
|
|
81
|
+
"husky": "^9.0.11",
|
|
71
82
|
"jest": "^29.7.0",
|
|
72
|
-
"
|
|
73
|
-
"
|
|
83
|
+
"jest-light-runner": "^0.6.0",
|
|
84
|
+
"lint-staged": "^15.2.5",
|
|
85
|
+
"np": "^10.0.5",
|
|
74
86
|
"npm-run-all": "^4.1.5",
|
|
75
|
-
"prettier": "^3.0
|
|
76
|
-
"remark-cli": "^12.0.
|
|
77
|
-
"stylelint": "^
|
|
78
|
-
"typescript": "^5.
|
|
87
|
+
"prettier": "^3.3.0",
|
|
88
|
+
"remark-cli": "^12.0.1",
|
|
89
|
+
"stylelint": "^16.6.1",
|
|
90
|
+
"typescript": "^5.4.5"
|
|
79
91
|
},
|
|
80
92
|
"peerDependencies": {
|
|
81
93
|
"jest": "^29.0.2"
|
|
82
94
|
},
|
|
83
95
|
"engines": {
|
|
84
|
-
"node": "
|
|
96
|
+
"node": ">=18.12.0"
|
|
85
97
|
}
|
|
86
98
|
}
|