@html-validate/jest-config 3.9.0 → 3.11.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
@@ -29,6 +29,14 @@ In your `package.json` file:
29
29
  }
30
30
  ```
31
31
 
32
+ ### Presets
33
+
34
+ | Preset | Description |
35
+ | ------------------------------------------ | ------------------------- |
36
+ | @html-validate/jest-config | Alias for presets/default |
37
+ | @html-validate/jest-config/presets/default | Default preset |
38
+ | @html-validate/jest-config/presets/esm | Experimental ESM support |
39
+
32
40
  ### Transpiling ESM in `node_modules/`
33
41
 
34
42
  If you need to import and use ESM-only libraries you need to install `@babel/core.
package/jest-preset.js CHANGED
@@ -1,88 +1,3 @@
1
- const { version: tsjestVersion } = require("ts-jest/package.json");
2
- const { detectBabel, findTsConfig } = require("./lib");
1
+ #!/usr/bin/env node
3
2
 
4
- const cwd = process.cwd();
5
- const tsjestMajor = parseInt(tsjestVersion.split(".")[0], 10);
6
- const useLegacyTsJestConfig = tsjestMajor < 29;
7
-
8
- const tsjestOptions = {
9
- stringifyContentPathRegex: "\\.html?$",
10
- tsconfig: findTsConfig(cwd),
11
- };
12
-
13
- const preset = {
14
- collectCoverage: true,
15
- collectCoverageFrom: [
16
- "src/**/*.[jt]s",
17
- "packages/*/*src/**/*.[jt]s",
18
- "!**/*.spec.[jt]s",
19
- "!**/*.d.ts",
20
- "!**/index.[jt]s",
21
- "!**/__fixtures__/**",
22
- "!**/generated/**",
23
- ],
24
- coverageReporters: ["text", "text-summary", "cobertura", "html", "json", "lcov"],
25
-
26
- /* until jest 30 we must force prettier 2 or formatting snapshots wont work */
27
- prettierPath: require.resolve("prettier-2"),
28
-
29
- reporters: [
30
- "default",
31
- [
32
- require.resolve("jest-junit"),
33
- {
34
- outputDirectory: "temp",
35
- outputName: "./jest.xml",
36
- },
37
- ],
38
- ],
39
- snapshotFormat: {
40
- escapeString: false,
41
- printBasicPrototype: false,
42
- },
43
- snapshotSerializers: [require.resolve("jest-serializer-ansi-escapes")],
44
- testEnvironmentOptions: {
45
- customExportConditions: ["node"],
46
- },
47
- testPathIgnorePatterns: [
48
- "/node_modules/",
49
- "<rootDir>/build/",
50
- "<rootDir>/dist/",
51
- "<rootDir>/cypress/",
52
- "<rootDir>/packages/.*/dist/",
53
- ],
54
- testRegex: "(/__tests__/.+|(\\.|/)(test|spec))\\.[jt]s$",
55
- };
56
-
57
- if (useLegacyTsJestConfig) {
58
- preset.globals = {
59
- "ts-jest": tsjestOptions,
60
- };
61
- preset.transform = {
62
- "^.+\\.(tsx?|html)$": require.resolve("ts-jest"),
63
- };
64
- } else {
65
- preset.transform = {
66
- "^.+\\.(tsx?|html)$": [require.resolve("ts-jest"), tsjestOptions],
67
- };
68
- }
69
-
70
- if (detectBabel()) {
71
- preset.transformIgnorePatterns = [];
72
- preset.transform["^.+\\.m?js$"] = [
73
- require.resolve("babel-jest"),
74
- {
75
- plugins: [
76
- [require.resolve("babel-plugin-transform-import-meta"), { module: "ES6" }],
77
- require.resolve("@babel/plugin-transform-modules-commonjs"),
78
- ],
79
- },
80
- ];
81
- }
82
-
83
- if (require.main === module) {
84
- /* eslint-disable-next-line no-console */
85
- console.log(JSON.stringify(preset, null, 2));
86
- }
87
-
88
- module.exports = preset;
3
+ module.exports = require("./presets/default/jest-preset");
package/lib/common.js ADDED
@@ -0,0 +1,45 @@
1
+ const commonConfig = {
2
+ collectCoverage: true,
3
+ collectCoverageFrom: [
4
+ "src/**/*.[jt]s",
5
+ "packages/*/*src/**/*.[jt]s",
6
+ "!**/*.spec.[jt]s",
7
+ "!**/*.d.ts",
8
+ "!**/index.[jt]s",
9
+ "!**/__fixtures__/**",
10
+ "!**/generated/**",
11
+ ],
12
+ coverageReporters: ["text", "text-summary", "cobertura", "html", "json", "lcov"],
13
+
14
+ /* until jest 30 we must force prettier 2 or formatting snapshots wont work */
15
+ prettierPath: require.resolve("prettier-2"),
16
+
17
+ reporters: [
18
+ "default",
19
+ [
20
+ require.resolve("jest-junit"),
21
+ {
22
+ outputDirectory: "temp",
23
+ outputName: "./jest.xml",
24
+ },
25
+ ],
26
+ ],
27
+ snapshotFormat: {
28
+ escapeString: false,
29
+ printBasicPrototype: false,
30
+ },
31
+ snapshotSerializers: [require.resolve("jest-serializer-ansi-escapes")],
32
+ testEnvironmentOptions: {
33
+ customExportConditions: ["node"],
34
+ },
35
+ testPathIgnorePatterns: [
36
+ "/node_modules/",
37
+ "<rootDir>/build/",
38
+ "<rootDir>/dist/",
39
+ "<rootDir>/cypress/",
40
+ "<rootDir>/packages/.*/dist/",
41
+ ],
42
+ testRegex: "(/__tests__/.+|(\\.|/)(test|spec))\\.[jt]s$",
43
+ };
44
+
45
+ module.exports = { commonConfig };
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
+ const { commonConfig } = require("./common");
1
2
  const { detectBabel } = require("./detect-babel");
2
3
  const { findTsConfig } = require("./find-ts-config");
3
4
 
4
- module.exports = { detectBabel, findTsConfig };
5
+ module.exports = { commonConfig, detectBabel, findTsConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@html-validate/jest-config",
3
- "version": "3.9.0",
3
+ "version": "3.11.0",
4
4
  "description": "Jest sharable preset used by the various HTML-validate packages",
5
5
  "keywords": [
6
6
  "jest"
@@ -11,19 +11,23 @@
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://gitlab.com/html-validate/jest-config.git"
14
+ "url": "git+https://gitlab.com/html-validate/jest-config.git"
15
15
  },
16
16
  "license": "MIT",
17
17
  "author": "David Sveningsson <ext@sidvind.com>",
18
18
  "main": "jest-preset.js",
19
- "bin": "jest-preset.js",
19
+ "bin": {
20
+ "jest-config": "jest-preset.js"
21
+ },
20
22
  "files": [
21
23
  "dist",
22
24
  "lib",
23
- "jest-preset.js"
25
+ "presets",
26
+ "jest-preset.js",
27
+ "!**/*.spec.js"
24
28
  ],
25
29
  "dependencies": {
26
- "@babel/plugin-transform-modules-commonjs": "7.23.3",
30
+ "@babel/plugin-transform-modules-commonjs": "7.25.9",
27
31
  "babel-plugin-transform-import-meta": "2.2.1",
28
32
  "jest-junit": "16.0.0",
29
33
  "jest-serializer-ansi-escapes": "3.0.0",
@@ -34,7 +38,7 @@
34
38
  "babel-jest": "^25 || ^26 || ^27 || ^28 || ^29",
35
39
  "jest": "^25 || ^26 || ^27 || ^28 || ^29",
36
40
  "ts-jest": "^25 || ^26 || ^27.1 || ^28 || ^29",
37
- "typescript": "^3 || ^4 || ^5"
41
+ "typescript": "^3.9.2 || ^4.6.2 || ^5.0.2"
38
42
  },
39
43
  "peerDependenciesMeta": {
40
44
  "@babel/core": {
@@ -42,7 +46,7 @@
42
46
  }
43
47
  },
44
48
  "engines": {
45
- "node": ">= 14.0",
49
+ "node": ">= 16.0",
46
50
  "npm": ">= 7"
47
51
  },
48
52
  "publishConfig": {
@@ -0,0 +1,46 @@
1
+ const { version: tsjestVersion } = require("ts-jest/package.json");
2
+ const { commonConfig, detectBabel, findTsConfig } = require("../../lib");
3
+
4
+ const cwd = process.cwd();
5
+ const tsjestMajor = parseInt(tsjestVersion.split(".")[0], 10);
6
+ const useLegacyTsJestConfig = tsjestMajor < 29;
7
+
8
+ const tsjestOptions = {
9
+ stringifyContentPathRegex: "\\.html?$",
10
+ tsconfig: findTsConfig(cwd),
11
+ };
12
+
13
+ const preset = { ...commonConfig };
14
+
15
+ if (useLegacyTsJestConfig) {
16
+ preset.globals = {
17
+ "ts-jest": tsjestOptions,
18
+ };
19
+ preset.transform = {
20
+ "^.+\\.(tsx?|html)$": require.resolve("ts-jest"),
21
+ };
22
+ } else {
23
+ preset.transform = {
24
+ "^.+\\.(tsx?|html)$": [require.resolve("ts-jest"), tsjestOptions],
25
+ };
26
+ }
27
+
28
+ if (detectBabel()) {
29
+ preset.transformIgnorePatterns = [];
30
+ preset.transform["^.+\\.m?js$"] = [
31
+ require.resolve("babel-jest"),
32
+ {
33
+ plugins: [
34
+ [require.resolve("babel-plugin-transform-import-meta"), { module: "ES6" }],
35
+ require.resolve("@babel/plugin-transform-modules-commonjs"),
36
+ ],
37
+ },
38
+ ];
39
+ }
40
+
41
+ if (require.main === module) {
42
+ /* eslint-disable-next-line no-console */
43
+ console.log(JSON.stringify(preset, null, 2));
44
+ }
45
+
46
+ module.exports = preset;
@@ -0,0 +1,24 @@
1
+ const { commonConfig, findTsConfig } = require("../../lib");
2
+
3
+ const cwd = process.cwd();
4
+
5
+ const tsjestOptions = {
6
+ stringifyContentPathRegex: "\\.html?$",
7
+ tsconfig: findTsConfig(cwd),
8
+ useESM: true,
9
+ };
10
+
11
+ const preset = {
12
+ ...commonConfig,
13
+ extensionsToTreatAsEsm: [".ts", ".tsx", ".mts"],
14
+ transform: {
15
+ "^.+\\.(tsx?|html)$": [require.resolve("ts-jest"), tsjestOptions],
16
+ },
17
+ };
18
+
19
+ if (require.main === module) {
20
+ /* eslint-disable-next-line no-console */
21
+ console.log(JSON.stringify(preset, null, 2));
22
+ }
23
+
24
+ module.exports = preset;
@@ -1,48 +0,0 @@
1
- const { findTsConfig } = require("./find-ts-config");
2
- const fs = require("fs");
3
- const path = require("path");
4
-
5
- jest.mock("fs");
6
-
7
- function mockFilesystem(files) {
8
- jest.spyOn(fs, "existsSync").mockImplementation((filePath) => {
9
- if (filePath.includes("node_modules") || path.dirname(filePath) === __dirname) {
10
- return true;
11
- }
12
- return files.includes(filePath);
13
- });
14
- }
15
-
16
- afterEach(() => {
17
- jest.restoreAllMocks();
18
- });
19
-
20
- it("should find tsconfig.jest.json", () => {
21
- expect.assertions(1);
22
- mockFilesystem(["/path/to/project/tsconfig.jest.json"]);
23
- expect(findTsConfig("/path/to/project")).toBe("/path/to/project/tsconfig.jest.json");
24
- });
25
-
26
- it("should find tsconfig.json", () => {
27
- expect.assertions(1);
28
- mockFilesystem(["/path/to/project/tsconfig.json"]);
29
- expect(findTsConfig("/path/to/project")).toBe("/path/to/project/tsconfig.json");
30
- });
31
-
32
- it("should prefer tsconfig.jest.json over tsconfig.json", () => {
33
- expect.assertions(1);
34
- mockFilesystem(["/path/to/project/tsconfig.jest.json", "/path/to/project/tsconfig.json"]);
35
- expect(findTsConfig("/path/to/project")).toBe("/path/to/project/tsconfig.jest.json");
36
- });
37
-
38
- it("should find from parent directory", () => {
39
- expect.assertions(1);
40
- mockFilesystem(["/path/to/project/tsconfig.jest.json"]);
41
- expect(findTsConfig("/path/to/project/deep/path")).toBe("/path/to/project/tsconfig.jest.json");
42
- });
43
-
44
- it("should return undefined if no config file was found", () => {
45
- expect.assertions(1);
46
- mockFilesystem([]);
47
- expect(findTsConfig("/path/to/project")).toBeUndefined();
48
- });