jest-preset-stylelint 7.0.1 → 7.1.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/getTestRule.js CHANGED
@@ -39,10 +39,10 @@ module.exports = function getTestRule(options = {}) {
39
39
  code: testCase.code,
40
40
  config: stylelintConfig,
41
41
  customSyntax: schema.customSyntax,
42
- codeFilename: schema.codeFilename,
42
+ codeFilename: testCase.codeFilename || schema.codeFilename,
43
43
  };
44
44
 
45
- const output = await lint(stylelintOptions);
45
+ const output = await lint(stylelintOptions).catch(formatExceptions);
46
46
 
47
47
  expect(output.results[0].warnings).toEqual([]);
48
48
  expect(output.results[0].parseErrors).toEqual([]);
@@ -51,7 +51,9 @@ module.exports = function getTestRule(options = {}) {
51
51
  if (!schema.fix) return;
52
52
 
53
53
  // Check that --fix doesn't change code
54
- const outputAfterFix = await lint({ ...stylelintOptions, fix: true });
54
+ const outputAfterFix = await lint({ ...stylelintOptions, fix: true }).catch(
55
+ formatExceptions,
56
+ );
55
57
  const fixedCode = getOutputCss(outputAfterFix);
56
58
 
57
59
  expect(fixedCode).toBe(testCase.code);
@@ -67,10 +69,10 @@ module.exports = function getTestRule(options = {}) {
67
69
  code: testCase.code,
68
70
  config: stylelintConfig,
69
71
  customSyntax: schema.customSyntax,
70
- codeFilename: schema.codeFilename,
72
+ codeFilename: testCase.codeFilename || schema.codeFilename,
71
73
  };
72
74
 
73
- const outputAfterLint = await lint(stylelintOptions);
75
+ const outputAfterLint = await lint(stylelintOptions).catch(formatExceptions);
74
76
 
75
77
  const actualWarnings = [
76
78
  ...outputAfterLint.results[0].invalidOptionWarnings,
@@ -111,7 +113,9 @@ module.exports = function getTestRule(options = {}) {
111
113
  );
112
114
  }
113
115
 
114
- const outputAfterFix = await lint({ ...stylelintOptions, fix: true });
116
+ const outputAfterFix = await lint({ ...stylelintOptions, fix: true }).catch(
117
+ formatExceptions,
118
+ );
115
119
 
116
120
  const fixedCode = getOutputCss(outputAfterFix);
117
121
 
@@ -132,7 +136,7 @@ module.exports = function getTestRule(options = {}) {
132
136
  ...stylelintOptions,
133
137
  code: fixedCode,
134
138
  fix: testCase.unfixable,
135
- });
139
+ }).catch(formatExceptions);
136
140
 
137
141
  expect(outputAfterLintOnFixedCode.results[0]).toMatchObject({
138
142
  warnings: outputAfterFix.results[0].warnings,
@@ -203,3 +207,19 @@ function getOutputCss(output) {
203
207
 
204
208
  throw new TypeError('Invalid result');
205
209
  }
210
+
211
+ /**
212
+ * @param {Error & { postcssNode?: (import('postcss').Node | Record<string, unknown>) }} error
213
+ * @throws
214
+ * @returns {never}
215
+ */
216
+ function formatExceptions(error) {
217
+ if (error.postcssNode?.toJSON && typeof error.postcssNode.toJSON === 'function') {
218
+ // see: https://github.com/stylelint/jest-preset-stylelint/issues/130
219
+ // `postcssNode` becomes a circular plain object after structured cloning.
220
+ // Eagerly converting to JSON ensures that jest can always pass this data around between threads and ultimately format the report.
221
+ error.postcssNode = error.postcssNode.toJSON();
222
+ }
223
+
224
+ throw error;
225
+ }
package/index.d.ts CHANGED
@@ -4,6 +4,11 @@ export type TestCase = {
4
4
  */
5
5
  code: string;
6
6
 
7
+ /**
8
+ * The filename for this `code` property.
9
+ */
10
+ codeFilename?: string;
11
+
7
12
  /**
8
13
  * Description of the test case.
9
14
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-preset-stylelint",
3
- "version": "7.0.1",
3
+ "version": "7.1.1",
4
4
  "description": "Jest preset for Stylelint plugins.",
5
5
  "keywords": [
6
6
  "stylelint",
@@ -49,18 +49,6 @@
49
49
  "*.{js,json,md,yml}": "prettier --write"
50
50
  },
51
51
  "prettier": "@stylelint/prettier-config",
52
- "eslintConfig": {
53
- "extends": [
54
- "stylelint",
55
- "stylelint/jest"
56
- ],
57
- "globals": {
58
- "module": true,
59
- "require": true
60
- },
61
- "reportUnusedDisableDirectives": true,
62
- "root": true
63
- },
64
52
  "remarkConfig": {
65
53
  "plugins": [
66
54
  "@stylelint/remark-preset"
@@ -73,21 +61,21 @@
73
61
  },
74
62
  "devDependencies": {
75
63
  "@stylelint/prettier-config": "^3.0.0",
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",
64
+ "@stylelint/remark-preset": "^5.1.1",
65
+ "@types/jest": "^29.5.14",
66
+ "eslint": "^9.16.0",
67
+ "eslint-config-stylelint": "^23.0.0",
68
+ "eslint-plugin-jest": "^28.9.0",
69
+ "husky": "^9.1.7",
82
70
  "jest": "^29.7.0",
83
71
  "jest-light-runner": "^0.6.0",
84
- "lint-staged": "^15.2.5",
85
- "np": "^10.0.5",
72
+ "lint-staged": "^15.2.10",
73
+ "np": "^10.1.0",
86
74
  "npm-run-all": "^4.1.5",
87
- "prettier": "^3.3.0",
75
+ "prettier": "^3.4.1",
88
76
  "remark-cli": "^12.0.1",
89
- "stylelint": "^16.6.1",
90
- "typescript": "^5.4.5"
77
+ "stylelint": "^16.11.0",
78
+ "typescript": "^5.7.2"
91
79
  },
92
80
  "peerDependencies": {
93
81
  "jest": "^29.0.2"