jest-preset-stylelint 3.0.0 → 4.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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ## Installation
8
8
 
9
- Install the preset alongside jest and stylelint:
9
+ Install the preset alongside Jest and Stylelint:
10
10
 
11
11
  ```bash
12
12
  npm install jest-preset-stylelint jest stylelint --save-dev
@@ -116,7 +116,7 @@ Turn on autofix.
116
116
 
117
117
  ### `plugins` \[array\<string\>\]
118
118
 
119
- Maps to stylelint's [`plugins` configuration property](https://stylelint.io/user-guide/configure#plugins).
119
+ Maps to Stylelint's [`plugins` configuration property](https://stylelint.io/user-guide/configure#plugins).
120
120
 
121
121
  Path to the file that exports the plugin object, relative to the root. Usually it's the same path as a `main` property in plugin's `package.json`.
122
122
 
@@ -138,9 +138,13 @@ Default: `false` (Optional).
138
138
 
139
139
  Skip [basic checks](https://github.com/stylelint/stylelint/blob/master/lib/testUtils/basicChecks.js), e.g. an empty source.
140
140
 
141
- ### `syntax` \<string\>
141
+ ### `customSyntax` \<string\>
142
142
 
143
- Maps to stylelint's [`syntax` option](https://stylelint.io/user-guide/usage/options#syntax).
143
+ Maps to Stylelint's [`customSyntax` option](https://stylelint.io/user-guide/usage/options#customsyntax).
144
+
145
+ ### `codeFilename` \<string\>
146
+
147
+ Maps to Stylelint's [`codeFilename` option](https://stylelint.io/user-guide/usage/options#codefilename).
144
148
 
145
149
  ## Shared test case properties
146
150
 
package/getTestRule.js CHANGED
@@ -1,9 +1,36 @@
1
1
  'use strict';
2
2
 
3
3
  const util = require('util');
4
+ // eslint-disable-next-line node/no-unpublished-require -- Avoid auto-install of `stylelint` peer dependency.
4
5
  const { basicChecks, lint } = require('stylelint');
5
6
 
7
+ /**
8
+ * @typedef {Object} TestCase
9
+ * @property {string} code
10
+ * @property {string} [description]
11
+ * @property {boolean} [only]
12
+ * @property {boolean} [skip]
13
+ */
14
+
15
+ /**
16
+ * @typedef {Object} TestSchema
17
+ * @property {string} ruleName
18
+ * @property {any} config
19
+ * @property {TestCase[]} accept
20
+ * @property {TestCase[]} reject
21
+ * @property {string | string[]} plugins
22
+ * @property {boolean} [skipBasicChecks]
23
+ * @property {boolean} [fix]
24
+ * @property {Syntax} [customSyntax] - PostCSS Syntax (https://postcss.org/api/#syntax)
25
+ * @property {string} [codeFilename]
26
+ * @property {boolean} [only]
27
+ * @property {boolean} [skip]
28
+ */
29
+
6
30
  function getTestRule(options = {}) {
31
+ /**
32
+ * @param {TestSchema} schema
33
+ */
7
34
  return function testRule(schema) {
8
35
  describe(`${schema.ruleName}`, () => {
9
36
  const stylelintConfig = {
@@ -24,13 +51,14 @@ function getTestRule(options = {}) {
24
51
  cases: passingTestCases,
25
52
  schema,
26
53
  comparisons: (testCase) => async () => {
27
- const options = {
54
+ const stylelintOptions = {
28
55
  code: testCase.code,
29
56
  config: stylelintConfig,
30
- syntax: schema.syntax,
57
+ customSyntax: schema.customSyntax,
58
+ codeFilename: schema.codeFilename,
31
59
  };
32
60
 
33
- const output = await lint(options);
61
+ const output = await lint(stylelintOptions);
34
62
 
35
63
  expect(output.results[0].warnings).toEqual([]);
36
64
  expect(output.results[0].parseErrors).toEqual([]);
@@ -38,7 +66,7 @@ function getTestRule(options = {}) {
38
66
  if (!schema.fix) return;
39
67
 
40
68
  // Check that --fix doesn't change code
41
- const outputAfterFix = await lint({ ...options, fix: true });
69
+ const outputAfterFix = await lint({ ...stylelintOptions, fix: true });
42
70
  const fixedCode = getOutputCss(outputAfterFix);
43
71
 
44
72
  expect(fixedCode).toBe(testCase.code);
@@ -50,13 +78,14 @@ function getTestRule(options = {}) {
50
78
  cases: schema.reject,
51
79
  schema,
52
80
  comparisons: (testCase) => async () => {
53
- const options = {
81
+ const stylelintOptions = {
54
82
  code: testCase.code,
55
83
  config: stylelintConfig,
56
- syntax: schema.syntax,
84
+ customSyntax: schema.customSyntax,
85
+ codeFilename: schema.codeFilename,
57
86
  };
58
87
 
59
- const outputAfterLint = await lint(options);
88
+ const outputAfterLint = await lint(stylelintOptions);
60
89
 
61
90
  const actualWarnings = outputAfterLint.results[0].warnings;
62
91
 
@@ -88,7 +117,7 @@ function getTestRule(options = {}) {
88
117
  );
89
118
  }
90
119
 
91
- const outputAfterFix = await lint({ ...options, fix: true });
120
+ const outputAfterFix = await lint({ ...stylelintOptions, fix: true });
92
121
 
93
122
  const fixedCode = getOutputCss(outputAfterFix);
94
123
 
@@ -106,7 +135,7 @@ function getTestRule(options = {}) {
106
135
 
107
136
  // Checks whether only errors other than those fixed are reported
108
137
  const outputAfterLintOnFixedCode = await lint({
109
- ...options,
138
+ ...stylelintOptions,
110
139
  code: fixedCode,
111
140
  });
112
141
 
@@ -137,7 +166,9 @@ function getTestRule(options = {}) {
137
166
 
138
167
  function setupTestCases({ name, cases, schema, comparisons }) {
139
168
  if (cases && cases.length) {
140
- describe(name, () => {
169
+ const testGroup = schema.only ? describe.only : schema.skip ? describe.skip : describe;
170
+
171
+ testGroup(`${name}`, () => {
141
172
  cases.forEach((testCase) => {
142
173
  if (testCase) {
143
174
  const spec = testCase.only ? it.only : testCase.skip ? it.skip : it;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jest-preset-stylelint",
3
- "version": "3.0.0",
4
- "description": "Jest preset for stylelint plugins.",
3
+ "version": "4.2.0",
4
+ "description": "Jest preset for Stylelint plugins.",
5
5
  "keywords": [
6
6
  "stylelint",
7
7
  "jest",
@@ -24,12 +24,8 @@
24
24
  "lint:md": "remark . --quiet --frail ",
25
25
  "release": "np",
26
26
  "test": "jest",
27
- "watch": "jest --watch"
28
- },
29
- "husky": {
30
- "hooks": {
31
- "pre-commit": "lint-staged"
32
- }
27
+ "watch": "jest --watch",
28
+ "prepare": "husky install"
33
29
  },
34
30
  "lint-staged": {
35
31
  "*.js": "eslint --cache --fix",
@@ -39,7 +35,11 @@
39
35
  "eslintConfig": {
40
36
  "extends": [
41
37
  "stylelint"
42
- ]
38
+ ],
39
+ "globals": {
40
+ "module": true,
41
+ "require": true
42
+ }
43
43
  },
44
44
  "remarkConfig": {
45
45
  "plugins": [
@@ -48,23 +48,22 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@stylelint/prettier-config": "^2.0.0",
51
- "@stylelint/remark-preset": "^1.0.0",
52
- "eslint": "^6.8.0",
53
- "eslint-config-stylelint": "^12.0.0",
54
- "husky": "^4.2.5",
55
- "jest": "^26.0.1",
56
- "lint-staged": "^10.1.7",
57
- "np": "^6.2.1",
51
+ "@stylelint/remark-preset": "^3.0.0",
52
+ "eslint": "^8.2.0",
53
+ "eslint-config-stylelint": "^15.0.0",
54
+ "husky": "^7.0.4",
55
+ "jest": "^27.3.1",
56
+ "lint-staged": "^11.2.6",
57
+ "np": "^7.5.0",
58
58
  "npm-run-all": "^4.1.5",
59
- "prettier": "^2.0.4",
60
- "remark-cli": "^8.0.0",
61
- "stylelint": "^13.3.2"
59
+ "prettier": "^2.4.1",
60
+ "remark-cli": "^10.0.0",
61
+ "stylelint": "^14.0.1"
62
62
  },
63
63
  "peerDependencies": {
64
- "jest": "^25.3.0 || ^26.0.1",
65
- "stylelint": "^13.0.0"
64
+ "jest": "^25.3.0 || ^26.0.1 || ^27.0.1"
66
65
  },
67
66
  "engines": {
68
- "node": ">=10"
67
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
69
68
  }
70
69
  }
package/CHANGELOG.md DELETED
@@ -1,37 +0,0 @@
1
- # Changelog
2
-
3
- ## 3.0.0
4
-
5
- - Changed: `getTestRule` signature to only accept options as argument.
6
- - Added: support for Jest 26.0.1+.
7
-
8
- ## 2.0.0
9
-
10
- - Removed: support for stylelint versions less than 13.
11
- - Removed: support for node@8.
12
- - Removed: settings not related to plugin testing.
13
- - Changed: `testRule` signature to only accept `schema` as argument.
14
- - Added: `warnings` to `reject` schema property.
15
- - Added: `plugins` schema property.
16
- - Added: `only` schema property.
17
- - Added: `skip` schema property.
18
- - Fixed: `TypeError: stylelint is not a function`.
19
-
20
- ## 1.3.0
21
-
22
- - Use stylelint exported modules.
23
- - Include `getOsEol.js` in a `.package.json` distribution files.
24
-
25
- ## 1.2.0
26
-
27
- - Use absolute path to `jest-setup.js` in `jest-preset.json`.
28
- - Avoid Jest preset conflicts by not using the Jest preset for this repo.
29
-
30
- ## 1.1.0
31
-
32
- - Include `jest-setup.js` in a .package.json`distribution`files`.
33
-
34
- ## 1.0.0
35
-
36
- - Initial release.
37
- - `jest-setup.js` copied from stylelint upstream [commit](https://github.com/stylelint/stylelint/blob/4c90af5863acf3026d8424b49a78189106f052dc/jest-setup.js).