Skip to content

Commit 5a1107b

Browse files
authored
docs: explain tranformIgnorePatterns option usage
in cli-plugin-jest README
1 parent f971829 commit 5a1107b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/@vue/cli-plugin-unit-jest/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,32 @@ Jest can be configured via `jest.config.js` in your project root, or the `jest`
3838
``` sh
3939
vue add @vue/unit-jest
4040
```
41+
42+
## Transform dependencies from `/node_modules`
43+
44+
By default, jest doesn't transform anything from `/nodee_modules`.
45+
46+
Since jest runs in node, we also don't have to transpile anything that uses modern ECMAScript features as Node >=8 already supports these features, so it's a sensible default. cli-plugin-jest also doesn't respect the `transpileDependencies` option in `vue.config.js` for the same reason.
47+
48+
However, we have two cases where we do need to transpile code from `/node_modules` in jest:
49+
50+
1. Usage of ES6 `import`/`export` statements, which have to be compiled to commonjs `module.exports`
51+
2. Single File Components (`.vue` files) which have to be run through `vue-jest`
52+
53+
To do this, we need to add an exception to the `tranformIgnorePatterns` option of jest. This is its default value:
54+
55+
```js
56+
tranformIgnorePatterns: ["/node_modules/"]
57+
```
58+
59+
We have to add exceptions to this pattern with a RegExp negative lookahead:
60+
61+
```js
62+
tranformIgnorePatterns: ["/node_modules/(?!name-of-lib-o-transform)"]
63+
```
64+
65+
To exclude multiple libraries:
66+
67+
```js
68+
tranformIgnorePatterns: ["/node_modules/(?!lib-to-transform|other-lib)"]
69+
```

0 commit comments

Comments
 (0)