Skip to content

Commit dc260ca

Browse files
TomaszChrosniakeddyerburgh
authored andcommitted
fix: respect babel config falsy value (#136)
1 parent 2f6c49e commit dc260ca

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/load-babel-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ module.exports = function getBabelConfig (vueJestConfig, filePath) {
2828
if (vueJestConfig.babelRcFile) {
2929
deprecate.replace('babelRcFile', 'babelConfig')
3030
babelConfig = JSON.parse(readFileSync(vueJestConfig.babelRcFile))
31-
} else if (existsSync('babel.config.js')) {
32-
babelConfig = require(path.resolve('babel.config.js'))
3331
} else if (vueJestConfig.hasOwnProperty('babelConfig')) {
3432
switch (typeof vueJestConfig.babelConfig) {
3533
case 'string':
@@ -49,6 +47,8 @@ module.exports = function getBabelConfig (vueJestConfig, filePath) {
4947
babelConfig = vueJestConfig.babelConfig
5048
break
5149
}
50+
} else if (existsSync('babel.config.js')) {
51+
babelConfig = require(path.resolve('babel.config.js'))
5252
} else {
5353
babelConfig = find()
5454
}

test/load-babel-config.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,27 @@ describe('load-babel-config.js', () => {
143143
findBabelConfig.sync.mockRestore()
144144
})
145145

146+
it('should skip configuring babel if a falsey config is provided', () => {
147+
const config = {
148+
plugins: ['foo']
149+
}
150+
findBabelConfig.sync = jest.fn(() => ({ file: true, config }))
151+
const noBabelConfig = loadBabelConfig({
152+
babelConfig: false
153+
})
154+
expect(findBabelConfig.sync).not.toHaveBeenCalled()
155+
expect(noBabelConfig).toBeUndefined()
156+
157+
const babelConfigPath = resolve(__dirname, '../babel.config.js')
158+
writeFileSync(babelConfigPath, `module.exports = ${JSON.stringify(config)}`)
159+
const babelConfig = loadBabelConfig({
160+
babelConfig: false
161+
})
162+
expect(babelConfig).toBeUndefined()
163+
unlinkSync(babelConfigPath)
164+
findBabelConfig.sync.mockRestore()
165+
})
166+
146167
it('supports an inline babel configuration object', () => {
147168
const config = {
148169
plugins: ['foo']

0 commit comments

Comments
 (0)