Skip to content

Commit d5dcb6b

Browse files
committed
feat(errors): throw errors with standard format
1 parent be96fc0 commit d5dcb6b

File tree

7 files changed

+16
-6
lines changed

7 files changed

+16
-6
lines changed

lib/compilers/babel-compiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const babel = require('babel-core')
22
const path = require('path')
33
const fs = require('fs')
4+
const throwError = require('../throw-error')
45

56
var defaultBabelOptions = {
67
presets: ['es2015'],
@@ -12,7 +13,7 @@ function getBabelRc (path) {
1213
try {
1314
rc = JSON.parse(fs.readFileSync(path, 'utf-8'))
1415
} catch (e) {
15-
throw new Error('[vue-jest] Your .babelrc seems to be incorrectly formatted.')
16+
throwError('[Your .babelrc seems to be incorrectly formatted.')
1617
}
1718
return rc
1819
}

lib/compilers/coffee-compiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var ensureRequire = require('../ensure-require.js')
2+
const throwError = require('../throw-error')
23

34
module.exports = function (raw, cb, compiler) {
45
ensureRequire('coffee', ['coffee-script'])
@@ -10,7 +11,7 @@ module.exports = function (raw, cb, compiler) {
1011
sourceMap: true
1112
})
1213
} catch (err) {
13-
throw new Error(err)
14+
throwError(err)
1415
}
1516
return {
1617
code: compiled.js,

lib/compilers/jade-compiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var ensureRequire = require('../ensure-require.js')
2+
const throwError = require('../throw-error')
23

34
module.exports = function (raw) {
45
var html;
@@ -7,7 +8,7 @@ module.exports = function (raw) {
78
try {
89
var html = jade.compile(raw)()
910
} catch (err) {
10-
throw Error(err)
11+
throwError(err)
1112
}
1213
return html
1314
}

lib/compilers/pug-compiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var ensureRequire = require('../ensure-require.js')
2+
const throwError = require('../throw-error')
23

34
module.exports = function (raw) {
45
var html;
@@ -7,7 +8,7 @@ module.exports = function (raw) {
78
try {
89
var html = jade.compile(raw)()
910
} catch (err) {
10-
throw Error(err)
11+
throwError(err)
1112
}
1213
return html
1314
}

lib/ensure-require.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const throwError = require('./throw-error')
2+
13
module.exports = function (name, deps) {
24
var i, len
35
var missing = []
@@ -33,6 +35,6 @@ module.exports = function (name, deps) {
3335
message += missing[0] + ' is '
3436
}
3537
message += 'missing.\n\nTo install run:\n' + npmInstall
36-
throw new Error(message)
38+
throwError(message)
3739
}
3840
}

lib/template-compiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var vueCompiler = require('vue-template-compiler')
33
var transpile = require('vue-template-es2015-compiler')
44
var compilePug = require('./compilers/pug-compiler')
55
var compileJade = require('./compilers/jade-compiler')
6+
const throwError = require('./throw-error')
67

78
function getTemplateContent(templatePart) {
89
if(templatePart.lang === 'pug') {
@@ -22,7 +23,7 @@ module.exports = function compileTemplate (templatePart, compiler) {
2223
compiled.errors.forEach(function (msg) {
2324
console.error('\n' + chalk.red(msg) + '\n')
2425
})
25-
throw new Error('Vue template compilation failed')
26+
throwError('Vue template compilation failed')
2627
} else {
2728
return {
2829
render: toFunction(compiled.render),

lib/throw-error.js

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

0 commit comments

Comments
 (0)