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 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
- const { getTestRule, getTestRuleConfigs } = require("jest-preset-stylelint");
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
- const { messages, ruleName } = require(".");
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 util = require('util');
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 || options.loadLint || (() => Promise.resolve(require('stylelint').lint)); // eslint-disable-line n/no-unpublished-require -- Avoid auto-install of `stylelint` peer dependency.
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(`${util.inspect(schema.config)}`, () => {
181
- describe(`${util.inspect(testCase.code)}`, () => {
182
+ describe(`${inspect(schema.config)}`, () => {
183
+ describe(`${inspect(testCase.code)}`, () => {
182
184
  spec(testCase.description || 'no description', comparisons(testCase));
183
185
  });
184
186
  });
@@ -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 || (() => Promise.resolve(require('stylelint').lint)); // eslint-disable-line n/no-unpublished-require -- Avoid auto-install of `stylelint` peer dependency.
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
@@ -115,7 +115,7 @@ export type TestSchema = {
115
115
  *
116
116
  * @see https://stylelint.io/user-guide/configure#plugins
117
117
  */
118
- plugins?: string | string[];
118
+ plugins?: import('stylelint').Config['plugins'];
119
119
 
120
120
  /**
121
121
  * Maps to Stylelint's `customSyntax` option.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-preset-stylelint",
3
- "version": "6.3.2",
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": "jest --watch",
35
- "prepare": "husky install"
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
- "testRegex": ".*\\.test\\.js$"
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.0.0",
66
- "@types/jest": "^29.5.6",
67
- "eslint": "^8.52.0",
68
- "eslint-config-stylelint": "^20.0.0",
69
- "eslint-plugin-jest": "^27.6.0",
70
- "husky": "^8.0.3",
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
- "lint-staged": "^14.0.1",
73
- "np": "^8.0.4",
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.3",
76
- "remark-cli": "^12.0.0",
77
- "stylelint": "^15.11.0",
78
- "typescript": "^5.2.2"
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": "^14.15.0 || >=16.10.0"
96
+ "node": ">=18.12.0"
85
97
  }
86
98
  }