jest-preset-stylelint 7.1.0 → 7.2.0
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 +27 -5
- package/index.d.ts +14 -0
- package/package.json +11 -23
package/getTestRule.js
CHANGED
|
@@ -42,7 +42,7 @@ module.exports = function getTestRule(options = {}) {
|
|
|
42
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);
|
|
@@ -68,9 +70,10 @@ module.exports = function getTestRule(options = {}) {
|
|
|
68
70
|
config: stylelintConfig,
|
|
69
71
|
customSyntax: schema.customSyntax,
|
|
70
72
|
codeFilename: testCase.codeFilename || schema.codeFilename,
|
|
73
|
+
computeEditInfo: schema.computeEditInfo,
|
|
71
74
|
};
|
|
72
75
|
|
|
73
|
-
const outputAfterLint = await lint(stylelintOptions);
|
|
76
|
+
const outputAfterLint = await lint(stylelintOptions).catch(formatExceptions);
|
|
74
77
|
|
|
75
78
|
const actualWarnings = [
|
|
76
79
|
...outputAfterLint.results[0].invalidOptionWarnings,
|
|
@@ -90,6 +93,7 @@ module.exports = function getTestRule(options = {}) {
|
|
|
90
93
|
column: expected.column,
|
|
91
94
|
endLine: expected.endLine,
|
|
92
95
|
endColumn: expected.endColumn,
|
|
96
|
+
fix: expected.fix,
|
|
93
97
|
};
|
|
94
98
|
|
|
95
99
|
for (const [key, value] of Object.entries(expectedWarning)) {
|
|
@@ -111,7 +115,9 @@ module.exports = function getTestRule(options = {}) {
|
|
|
111
115
|
);
|
|
112
116
|
}
|
|
113
117
|
|
|
114
|
-
const outputAfterFix = await lint({ ...stylelintOptions, fix: true })
|
|
118
|
+
const outputAfterFix = await lint({ ...stylelintOptions, fix: true }).catch(
|
|
119
|
+
formatExceptions,
|
|
120
|
+
);
|
|
115
121
|
|
|
116
122
|
const fixedCode = getOutputCss(outputAfterFix);
|
|
117
123
|
|
|
@@ -132,7 +138,7 @@ module.exports = function getTestRule(options = {}) {
|
|
|
132
138
|
...stylelintOptions,
|
|
133
139
|
code: fixedCode,
|
|
134
140
|
fix: testCase.unfixable,
|
|
135
|
-
});
|
|
141
|
+
}).catch(formatExceptions);
|
|
136
142
|
|
|
137
143
|
expect(outputAfterLintOnFixedCode.results[0]).toMatchObject({
|
|
138
144
|
warnings: outputAfterFix.results[0].warnings,
|
|
@@ -203,3 +209,19 @@ function getOutputCss(output) {
|
|
|
203
209
|
|
|
204
210
|
throw new TypeError('Invalid result');
|
|
205
211
|
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @param {Error & { postcssNode?: (import('postcss').Node | Record<string, unknown>) }} error
|
|
215
|
+
* @throws
|
|
216
|
+
* @returns {never}
|
|
217
|
+
*/
|
|
218
|
+
function formatExceptions(error) {
|
|
219
|
+
if (error.postcssNode?.toJSON && typeof error.postcssNode.toJSON === 'function') {
|
|
220
|
+
// see: https://github.com/stylelint/jest-preset-stylelint/issues/130
|
|
221
|
+
// `postcssNode` becomes a circular plain object after structured cloning.
|
|
222
|
+
// Eagerly converting to JSON ensures that jest can always pass this data around between threads and ultimately format the report.
|
|
223
|
+
error.postcssNode = error.postcssNode.toJSON();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -57,6 +57,13 @@ export type Warning = {
|
|
|
57
57
|
* Expected end column number of the warning.
|
|
58
58
|
*/
|
|
59
59
|
endColumn?: number;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Expected `EditInfo` of the warning.
|
|
63
|
+
*
|
|
64
|
+
* @experimental
|
|
65
|
+
*/
|
|
66
|
+
fix?: { range: [number, number]; text: string };
|
|
60
67
|
};
|
|
61
68
|
|
|
62
69
|
/**
|
|
@@ -108,6 +115,13 @@ export type TestSchema = {
|
|
|
108
115
|
*/
|
|
109
116
|
fix?: boolean;
|
|
110
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Turn on computing `EditInfo`. Default: `false`.
|
|
120
|
+
*
|
|
121
|
+
* @experimental
|
|
122
|
+
*/
|
|
123
|
+
computeEditInfo?: boolean;
|
|
124
|
+
|
|
111
125
|
/**
|
|
112
126
|
* Maps to Stylelint's `plugins` configuration property.
|
|
113
127
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-preset-stylelint",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
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"
|
|
@@ -74,20 +62,20 @@
|
|
|
74
62
|
"devDependencies": {
|
|
75
63
|
"@stylelint/prettier-config": "^3.0.0",
|
|
76
64
|
"@stylelint/remark-preset": "^5.1.1",
|
|
77
|
-
"@types/jest": "^29.5.
|
|
78
|
-
"eslint": "^
|
|
79
|
-
"eslint-config-stylelint": "^
|
|
80
|
-
"eslint-plugin-jest": "^28.
|
|
81
|
-
"husky": "^9.
|
|
65
|
+
"@types/jest": "^29.5.14",
|
|
66
|
+
"eslint": "^9.17.0",
|
|
67
|
+
"eslint-config-stylelint": "^23.0.0",
|
|
68
|
+
"eslint-plugin-jest": "^28.10.0",
|
|
69
|
+
"husky": "^9.1.7",
|
|
82
70
|
"jest": "^29.7.0",
|
|
83
71
|
"jest-light-runner": "^0.6.0",
|
|
84
|
-
"lint-staged": "^15.
|
|
85
|
-
"np": "^10.0
|
|
72
|
+
"lint-staged": "^15.3.0",
|
|
73
|
+
"np": "^10.1.0",
|
|
86
74
|
"npm-run-all": "^4.1.5",
|
|
87
|
-
"prettier": "^3.
|
|
75
|
+
"prettier": "^3.4.2",
|
|
88
76
|
"remark-cli": "^12.0.1",
|
|
89
|
-
"stylelint": "^16.
|
|
90
|
-
"typescript": "^5.
|
|
77
|
+
"stylelint": "^16.14.0",
|
|
78
|
+
"typescript": "^5.7.2"
|
|
91
79
|
},
|
|
92
80
|
"peerDependencies": {
|
|
93
81
|
"jest": "^29.0.2"
|