jest-preset-stylelint 6.0.0 → 6.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
@@ -1,8 +1,6 @@
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.
5
- const { lint } = require('stylelint');
6
4
 
7
5
  /**
8
6
  * @typedef {import('.').TestCase} TestCase
@@ -12,6 +10,14 @@ const { lint } = require('stylelint');
12
10
  /** @type {import('.').getTestRule} */
13
11
  module.exports = function getTestRule(options = {}) {
14
12
  return function testRule(schema) {
13
+ /** @type {import('stylelint').lint} */
14
+ let lint;
15
+
16
+ beforeAll(() => {
17
+ // eslint-disable-next-line n/no-unpublished-require -- Avoid auto-install of `stylelint` peer dependency.
18
+ lint = require('stylelint').lint;
19
+ });
20
+
15
21
  describe(`${schema.ruleName}`, () => {
16
22
  const stylelintConfig = {
17
23
  plugins: options.plugins || schema.plugins,
@@ -36,6 +42,7 @@ module.exports = function getTestRule(options = {}) {
36
42
 
37
43
  expect(output.results[0].warnings).toEqual([]);
38
44
  expect(output.results[0].parseErrors).toEqual([]);
45
+ expect(output.results[0].invalidOptionWarnings).toEqual([]);
39
46
 
40
47
  if (!schema.fix) return;
41
48
 
@@ -61,7 +68,10 @@ module.exports = function getTestRule(options = {}) {
61
68
 
62
69
  const outputAfterLint = await lint(stylelintOptions);
63
70
 
64
- const actualWarnings = outputAfterLint.results[0].warnings;
71
+ const actualWarnings = [
72
+ ...outputAfterLint.results[0].invalidOptionWarnings,
73
+ ...outputAfterLint.results[0].warnings,
74
+ ];
65
75
 
66
76
  expect(outputAfterLint.results[0]).toMatchObject({ parseErrors: [] });
67
77
  expect(actualWarnings).toHaveLength(testCase.warnings ? testCase.warnings.length : 1);
@@ -117,6 +127,7 @@ module.exports = function getTestRule(options = {}) {
117
127
  const outputAfterLintOnFixedCode = await lint({
118
128
  ...stylelintOptions,
119
129
  code: fixedCode,
130
+ fix: testCase.unfixable,
120
131
  });
121
132
 
122
133
  expect(outputAfterLintOnFixedCode.results[0]).toMatchObject({
package/jest-preset.js CHANGED
@@ -2,5 +2,6 @@
2
2
 
3
3
  module.exports = {
4
4
  setupFiles: [require.resolve('./jest-setup.js')],
5
+ setupFilesAfterEnv: [require.resolve('./jest-setup-after-env.js')],
5
6
  testEnvironment: 'node',
6
7
  };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const os = require('os');
4
+
5
+ const eolDescriptor = Object.getOwnPropertyDescriptor(os, 'EOL');
6
+
7
+ if (!eolDescriptor) {
8
+ throw new TypeError('`os` must have an `EOL` property');
9
+ }
10
+
11
+ beforeAll(() => {
12
+ // NOTE: `jest.replaceProperty()` is unavailable for a read-only property.
13
+ Object.defineProperty(os, 'EOL', { ...eolDescriptor, value: '\n' });
14
+ });
15
+
16
+ afterAll(() => {
17
+ Object.defineProperty(os, 'EOL', eolDescriptor);
18
+ });
package/jest-setup.js CHANGED
@@ -1,8 +1,5 @@
1
1
  'use strict';
2
2
 
3
- // Mock should be before stylelint required. Even if it's required inside other modules
4
- jest.mock('stylelint/lib/utils/getOsEol', () => () => '\n');
5
-
6
3
  const getTestRule = require('./getTestRule');
7
4
 
8
5
  global.testRule = getTestRule();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-preset-stylelint",
3
- "version": "6.0.0",
3
+ "version": "6.1.1",
4
4
  "description": "Jest preset for Stylelint plugins.",
5
5
  "keywords": [
6
6
  "stylelint",
@@ -17,6 +17,7 @@
17
17
  "getTestRule.js",
18
18
  "jest-preset.js",
19
19
  "jest-setup.js",
20
+ "jest-setup-after-env.js",
20
21
  "index.d.ts"
21
22
  ],
22
23
  "scripts": {
@@ -27,6 +28,7 @@
27
28
  "lint:md": "remark . --quiet --frail",
28
29
  "lint:types": "tsc",
29
30
  "release": "np",
31
+ "pretest": "npm run lint",
30
32
  "test": "jest",
31
33
  "watch": "jest --watch",
32
34
  "prepare": "husky install"
@@ -38,7 +40,8 @@
38
40
  "prettier": "@stylelint/prettier-config",
39
41
  "eslintConfig": {
40
42
  "extends": [
41
- "stylelint"
43
+ "stylelint",
44
+ "stylelint/jest"
42
45
  ],
43
46
  "globals": {
44
47
  "module": true,
@@ -53,20 +56,21 @@
53
56
  ]
54
57
  },
55
58
  "devDependencies": {
56
- "@stylelint/prettier-config": "^2.0.0",
59
+ "@stylelint/prettier-config": "^3.0.0",
57
60
  "@stylelint/remark-preset": "^4.0.0",
58
- "@types/jest": "^29.0.0",
59
- "eslint": "^8.23.0",
60
- "eslint-config-stylelint": "^15.1.0",
61
- "husky": "^8.0.1",
62
- "jest": "^29.0.2",
63
- "lint-staged": "^13.0.3",
64
- "np": "^7.6.2",
61
+ "@types/jest": "^29.5.3",
62
+ "eslint": "^8.45.0",
63
+ "eslint-config-stylelint": "^19.0.0",
64
+ "eslint-plugin-jest": "^27.2.3",
65
+ "husky": "^8.0.3",
66
+ "jest": "^29.6.1",
67
+ "lint-staged": "^13.2.3",
68
+ "np": "^8.0.4",
65
69
  "npm-run-all": "^4.1.5",
66
- "prettier": "^2.7.1",
70
+ "prettier": "^3.0.0",
67
71
  "remark-cli": "^11.0.0",
68
- "stylelint": "^14.11.0",
69
- "typescript": "^4.8.2"
72
+ "stylelint": "^15.10.2",
73
+ "typescript": "^5.1.6"
70
74
  },
71
75
  "peerDependencies": {
72
76
  "jest": "^29.0.2"