@html-validate/jest-config 3.6.3 → 3.7.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 +26 -0
- package/jest-preset.js +11 -1
- package/lib/detect-babel.js +16 -0
- package/lib/index.js +2 -1
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Jest is configured to:
|
|
|
8
8
|
- Collect coverage from `.js` and `.ts` in `src` and ignore tests (`**/*.spec.[jt]s`) and index (`**/index.[jt]s`).
|
|
9
9
|
- Report results as junit in `temp/jest.xml`.
|
|
10
10
|
- Transform typescript with `ts-jest`.
|
|
11
|
+
- Transform js with `babel-jest` if babel is detected.
|
|
11
12
|
- Ignores spec-files from Cypress.
|
|
12
13
|
|
|
13
14
|
## Install
|
|
@@ -28,6 +29,31 @@ In your `package.json` file:
|
|
|
28
29
|
}
|
|
29
30
|
```
|
|
30
31
|
|
|
32
|
+
### Transpiling ESM in `node_modules/`
|
|
33
|
+
|
|
34
|
+
If you need to import and use ESM-only libraries you need to install `@babel/core.
|
|
35
|
+
You do not need a `babel.config.js`or`.babelrc`as the preset passes the required configuration directly to`babel-jest`.
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
npm install --save-dev @babel/core
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
When babel is detect the preset sets `transformIgnorePatterns` to transpile everything under `node_modules`.
|
|
42
|
+
You can include a more specific list of packages to transform (potential speed gain) by manually setting `transformIgnorePatterns`:
|
|
43
|
+
|
|
44
|
+
Optionally you can set `transformIgnorePatterns` in `package.json`:
|
|
45
|
+
|
|
46
|
+
```diff
|
|
47
|
+
{
|
|
48
|
+
"jest": {
|
|
49
|
+
"preset": "@html-validate/jest-config",
|
|
50
|
+
+ "transformIgnorePatterns": ["node_modules/(?!(foo|bar|baz)/)"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This will transform only the `foo`, `bar` and `baz` packages.
|
|
56
|
+
|
|
31
57
|
### Importing HTML as string
|
|
32
58
|
|
|
33
59
|
Importing `*.html` is supported by jest configuration but requires additional typescript config by creating a declaration:
|
package/jest-preset.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { version: tsjestVersion } = require("ts-jest/package.json");
|
|
2
|
-
const { findTsConfig } = require("./lib");
|
|
2
|
+
const { detectBabel, findTsConfig } = require("./lib");
|
|
3
3
|
|
|
4
4
|
const cwd = process.cwd();
|
|
5
5
|
const tsjestMajor = parseInt(tsjestVersion.split(".")[0], 10);
|
|
@@ -60,6 +60,16 @@ if (useLegacyTsJestConfig) {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
if (detectBabel()) {
|
|
64
|
+
preset.transformIgnorePatterns = [];
|
|
65
|
+
preset.transform["^.+\\.js$"] = [
|
|
66
|
+
require.resolve("babel-jest"),
|
|
67
|
+
{
|
|
68
|
+
plugins: [require.resolve("@babel/plugin-transform-modules-commonjs")],
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
|
|
63
73
|
if (require.main === module) {
|
|
64
74
|
/* eslint-disable-next-line no-console */
|
|
65
75
|
console.log(JSON.stringify(preset, null, 2));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autodetects if babel is present.
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
* @returns {boolean}
|
|
6
|
+
*/
|
|
7
|
+
function detectBabel() {
|
|
8
|
+
try {
|
|
9
|
+
require("@babel/core");
|
|
10
|
+
return true;
|
|
11
|
+
} catch (err) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = { detectBabel };
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@html-validate/jest-config",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Jest sharable preset used by the various HTML-validate packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jest"
|
|
@@ -23,14 +23,22 @@
|
|
|
23
23
|
"jest-preset.js"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@babel/plugin-transform-modules-commonjs": "7.21.2",
|
|
26
27
|
"jest-junit": "15.0.0",
|
|
27
28
|
"jest-serializer-ansi-escapes": "2.0.1"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
31
|
+
"@babel/core": "^7.8",
|
|
32
|
+
"babel-jest": "^25 || ^26 || ^27 || ^28 || ^29",
|
|
30
33
|
"jest": "^25 || ^26 || ^27 || ^28 || ^29",
|
|
31
34
|
"ts-jest": "^25 || ^26 || ^27.1 || ^28 || ^29",
|
|
32
35
|
"typescript": "^3 || ^4 || ^5"
|
|
33
36
|
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"@babel/core": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
34
42
|
"engines": {
|
|
35
43
|
"node": ">= 14.0",
|
|
36
44
|
"npm": ">= 7"
|