Skip to content

Commit 199d969

Browse files
committed
feat(babel): log when no .babelrc could be found
1 parent b312a28 commit 199d969

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

lib/compilers/babel-compiler.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const babel = require('babel-core')
22
const path = require('path')
33
const fs = require('fs')
44
const throwError = require('../throw-error')
5-
5+
const logger = require('../logger')
66
var defaultBabelOptions = {
77
presets: ['es2015'],
88
plugins: ['transform-runtime']
@@ -13,7 +13,7 @@ function getBabelRc (path) {
1313
try {
1414
rc = JSON.parse(fs.readFileSync(path, 'utf-8'))
1515
} catch (e) {
16-
throwError('[Your .babelrc seems to be incorrectly formatted.')
16+
throwError('Your .babelrc seems to be incorrectly formatted.')
1717
}
1818
return rc
1919
}
@@ -26,6 +26,10 @@ module.exports = function compileBabel (scriptContent) {
2626

2727
const res = babel.transform(scriptContent, babelOptions)
2828

29+
if (!babelRcExists) {
30+
logger.info('no .babelrc found, defaulting to default babel options')
31+
}
32+
2933
return {
3034
code: res.code,
3135
sourceMap: res.map

lib/logger.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports.info = function info(msg) {
2+
console.info('\n[jest-vue] Info: ' + (msg) + '\n')
3+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"release": "build/release.sh",
2121
"release:note": "node build/gen-release-note.js",
2222
"test": "npm run lint && npm run unit",
23-
"unit": "cross-env BABEL_ENV=test jest --no-cache --coverage --coverageDirectory test/coverage"
23+
"unit": "cross-env BABEL_ENV=test jest --no-cache --coverage --coverageDirectory test/coverage --runInBand"
2424
},
2525
"author": "Edd Yerburgh",
2626
"license": "MIT",

test/Babel.spec.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,34 @@ test('processes .vue files with default babel if there is no .babelrc', () => {
1717
const babelRcPath = resolve(__dirname, '../.babelrc')
1818
const tempPath = resolve(__dirname, '../.renamed')
1919
renameSync(babelRcPath, tempPath)
20-
const vm = new Vue(Basic).$mount()
21-
expect(typeof vm.$el).toBe('object')
20+
const filePath = resolve(__dirname, './resources/Basic.vue')
21+
const fileString = readFileSync(filePath, { encoding: 'utf8' })
22+
try {
23+
jestVue.process(fileString, filePath)
24+
} catch (err) {
25+
renameSync(tempPath, babelRcPath)
26+
throw err
27+
}
28+
renameSync(tempPath, babelRcPath)
29+
})
30+
31+
test('logs info when there is no .babelrc', () => {
32+
const babelRcPath = resolve(__dirname, '../.babelrc')
33+
const tempPath = resolve(__dirname, '../.renamed')
34+
renameSync(babelRcPath, tempPath)
35+
const info = jest.spyOn(global.console, 'info')
36+
const filePath = resolve(__dirname, './resources/Basic.vue')
37+
const fileString = readFileSync(filePath, { encoding: 'utf8' })
38+
39+
jestVue.process(fileString, filePath)
40+
try {
41+
expect(info).toHaveBeenCalledWith('\n[jest-vue] Info: no .babelrc found, defaulting to default babel options\n')
42+
} catch (err) {
43+
renameSync(tempPath, babelRcPath)
44+
throw err
45+
}
2246
renameSync(tempPath, babelRcPath)
47+
jest.resetModules()
2348
})
2449

2550
test('processes .vue files using .babelrc if it exists in route', () => {

0 commit comments

Comments
 (0)