Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 361918d

Browse filesBrowse files
author
Justin Helmer
committed
feat: update to support babel configuration object
1 parent d9f9336 commit 361918d
Copy full SHA for 361918d

File tree

Expand file treeCollapse file tree

3 files changed

+63
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+63
-0
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,57 @@ To define a babelrc file that vue-jest will use when transpiling javascript, you
8585
}
8686
```
8787

88+
You can also directly supply babel configuration
89+
90+
```json
91+
{
92+
"jest": {
93+
"globals": {
94+
"vue-jest": {
95+
"babelConfig": {
96+
"presets": [
97+
[
98+
"env",
99+
{
100+
"useBuiltIns": "entry",
101+
"shippedProposals": true
102+
}
103+
]
104+
],
105+
"plugins": [
106+
"syntax-dynamic-import"
107+
],
108+
"env": {
109+
"test": {
110+
"plugins": [
111+
"dynamic-import-node"
112+
]
113+
}
114+
}
115+
}
116+
}
117+
}
118+
}
119+
}
120+
```
121+
122+
This can be used to support a [project-wide configuration](https://babeljs.io/docs/en/config-files#project-wide-configuration) file:
123+
124+
```json
125+
{
126+
"jest": {
127+
"globals": {
128+
"vue-jest": {
129+
"babelConfig": {
130+
"configFile": "/path/to/babel.config.js"
131+
}
132+
}
133+
}
134+
}
135+
}
136+
```
137+
> *Tip:* Need programmatic configuration? Use the [--config](https://jestjs.io/docs/en/cli.html#config-path) option in Jest CLI, and export a `.js` file
138+
88139
### Supported template languages
89140

90141
- **pug** (`lang="pug"`)

‎lib/load-babel-config.js

Copy file name to clipboardExpand all lines: lib/load-babel-config.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module.exports = function getBabelConfig (vueJestConfig) {
1717
babelConfig = JSON.parse(readFileSync(vueJestConfig.babelRcFile))
1818
} else if (existsSync('babel.config.js')) {
1919
babelConfig = require(path.resolve('babel.config.js'))
20+
} else if (vueJestConfig.babelOptions) {
21+
babelConfig = vueJestConfig.babelOptions
2022
} else {
2123
const { file, config } = findBabelConfig.sync(process.cwd(), 0)
2224

‎test/load-babel-config.spec.js

Copy file name to clipboardExpand all lines: test/load-babel-config.spec.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,14 @@ describe('load-babel-config.js', () => {
7575
expect(babelConfig).toEqual(config)
7676
unlinkSync(babelConfigPath)
7777
})
78+
79+
it('supports a babel options configuration object', () => {
80+
const config = {
81+
plugins: ['foo']
82+
}
83+
const babelConfig = loadBabelConfig({
84+
babelOptions: config
85+
})
86+
expect(babelConfig).toEqual(config)
87+
})
7888
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.