Skip to content

Commit 0283ef9

Browse files
committed
feat: support loading babel.config.js
1 parent ed6041d commit 0283ef9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/load-babel-config.js

+4-1
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

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