jest-preset-stylelint 6.2.0 → 6.3.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
@@ -10,12 +10,14 @@ const util = require('util');
10
10
  /** @type {import('.').getTestRule} */
11
11
  module.exports = function getTestRule(options = {}) {
12
12
  return function testRule(schema) {
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.
15
+
13
16
  /** @type {import('stylelint').lint} */
14
17
  let lint;
15
18
 
16
- beforeAll(() => {
17
- // eslint-disable-next-line n/no-unpublished-require -- Avoid auto-install of `stylelint` peer dependency.
18
- lint = require('stylelint').lint;
19
+ beforeAll(async () => {
20
+ lint = await loadLint();
19
21
  });
20
22
 
21
23
  describe(`${schema.ruleName}`, () => {
@@ -11,17 +11,20 @@ module.exports = function getTestRuleConfigs(options = {}) {
11
11
  only = false,
12
12
  skip = false,
13
13
  plugins = options.plugins,
14
+ loadLint: schemaLoadLint,
14
15
  }) {
15
16
  if (accept.length === 0 && reject.length === 0) {
16
17
  throw new TypeError('The either "accept" or "reject" property must not be empty');
17
18
  }
18
19
 
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.
22
+
19
23
  /** @type {import('stylelint').lint} */
20
24
  let lint;
21
25
 
22
- beforeAll(() => {
23
- // eslint-disable-next-line n/no-unpublished-require
24
- lint = require('stylelint').lint;
26
+ beforeAll(async () => {
27
+ lint = await loadLint();
25
28
  });
26
29
 
27
30
  const testGroup = only ? describe.only : skip ? describe.skip : describe;
package/index.d.ts CHANGED
@@ -144,6 +144,16 @@ export type TestSchema = {
144
144
  * @see https://jestjs.io/docs/api#testskipname-fn
145
145
  */
146
146
  skip?: boolean;
147
+
148
+ /**
149
+ * Loads the lint function.
150
+ */
151
+ loadLint?: () => Promise<(typeof import('stylelint'))['lint']>;
152
+ };
153
+
154
+ type GetTestRuleOptions = {
155
+ plugins?: TestSchema['plugins'];
156
+ loadLint?: TestSchema['loadLint'];
147
157
  };
148
158
 
149
159
  /**
@@ -154,7 +164,7 @@ export type TestRule = (schema: TestSchema) => void;
154
164
  /**
155
165
  * Create a `testRule()` function with any specified plugins.
156
166
  */
157
- export function getTestRule(options?: { plugins?: TestSchema['plugins'] }): TestRule;
167
+ export function getTestRule(options?: GetTestRuleOptions): TestRule;
158
168
 
159
169
  export type ConfigCase = {
160
170
  config: unknown;
@@ -167,7 +177,7 @@ export type ConfigCase = {
167
177
  * Test configurations for a rule.
168
178
  */
169
179
  export type TestRuleConfigs = (
170
- schema: Pick<TestSchema, 'ruleName' | 'plugins' | 'only' | 'skip'> & {
180
+ schema: Pick<TestSchema, 'ruleName' | 'plugins' | 'only' | 'skip' | 'loadLint'> & {
171
181
  accept?: ConfigCase[];
172
182
  reject?: ConfigCase[];
173
183
  },
@@ -176,7 +186,7 @@ export type TestRuleConfigs = (
176
186
  /**
177
187
  * Create a `testRuleConfigs()` function with any specified plugins.
178
188
  */
179
- export function getTestRuleConfigs(options?: { plugins?: TestSchema['plugins'] }): TestRuleConfigs;
189
+ export function getTestRuleConfigs(options?: GetTestRuleOptions): TestRuleConfigs;
180
190
 
181
191
  declare global {
182
192
  var testRule: TestRule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-preset-stylelint",
3
- "version": "6.2.0",
3
+ "version": "6.3.1",
4
4
  "description": "Jest preset for Stylelint plugins.",
5
5
  "keywords": [
6
6
  "stylelint",
@@ -63,19 +63,19 @@
63
63
  "devDependencies": {
64
64
  "@stylelint/prettier-config": "^3.0.0",
65
65
  "@stylelint/remark-preset": "^4.0.0",
66
- "@types/jest": "^29.5.3",
67
- "eslint": "^8.46.0",
68
- "eslint-config-stylelint": "^19.1.0",
69
- "eslint-plugin-jest": "^27.2.3",
66
+ "@types/jest": "^29.5.5",
67
+ "eslint": "^8.50.0",
68
+ "eslint-config-stylelint": "^20.0.0",
69
+ "eslint-plugin-jest": "^27.4.2",
70
70
  "husky": "^8.0.3",
71
- "jest": "^29.6.2",
72
- "lint-staged": "^13.2.3",
71
+ "jest": "^29.7.0",
72
+ "lint-staged": "^14.0.1",
73
73
  "np": "^8.0.4",
74
74
  "npm-run-all": "^4.1.5",
75
- "prettier": "^3.0.1",
76
- "remark-cli": "^11.0.0",
77
- "stylelint": "^15.10.2",
78
- "typescript": "^5.1.6"
75
+ "prettier": "^3.0.3",
76
+ "remark-cli": "^12.0.0",
77
+ "stylelint": "^15.10.3",
78
+ "typescript": "^5.2.2"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "jest": "^29.0.2"