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 0283ef9

Browse filesBrowse files
committed
feat: support loading babel.config.js
1 parent ed6041d commit 0283ef9
Copy full SHA for 0283ef9

File tree

Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed

‎lib/load-babel-config.js

Copy file name to clipboardExpand all lines: lib/load-babel-config.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const findBabelConfig = require('find-babel-config')
22
const logger = require('./logger')
33
const cache = require('./cache')
4-
const { readFileSync } = require('fs')
4+
const path = require('path')
5+
const { readFileSync, existsSync } = require('fs')
56

67
module.exports = function getBabelConfig (vueJestConfig) {
78
const cachedConfig = cache.get('babel-config')
@@ -14,6 +15,8 @@ module.exports = function getBabelConfig (vueJestConfig) {
1415

1516
if (vueJestConfig.babelRcFile) {
1617
babelConfig = JSON.parse(readFileSync(vueJestConfig.babelRcFile))
18+
} else if (existsSync('babel.config.js')) {
19+
babelConfig = require(path.resolve('babel.config.js'))
1720
} else {
1821
const { file, config } = findBabelConfig.sync(process.cwd(), 0)
1922

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

Copy file name to clipboardExpand all lines: test/load-babel-config.spec.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,15 @@ describe('load-babel-config.js', () => {
6464
throw err
6565
}
6666
})
67+
68+
it('supports babel.config.js', () => {
69+
const babelConfigPath = resolve(__dirname, '../babel.config.js')
70+
const config = {
71+
plugins: ['foo']
72+
}
73+
writeFileSync(babelConfigPath, `module.exports = ${JSON.stringify(config)}`)
74+
const babelConfig = loadBabelConfig({})
75+
expect(babelConfig).toEqual(config)
76+
unlinkSync(babelConfigPath)
77+
})
6778
})

0 commit comments

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