Skip to content

Commit afcd2ac

Browse files
author
Justin Helmer
committed
feat: update to support babel configuration object
1 parent d9f9336 commit afcd2ac

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

README.md

+51
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 options
89+
90+
```json
91+
{
92+
"jest": {
93+
"globals": {
94+
"vue-jest": {
95+
"babelOptions": {
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+
"babelOptions": {
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

+2
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

+10
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)