Skip to content

Commit

Permalink
feat(errors): throw errors with standard format
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Sep 3, 2017
1 parent be96fc0 commit d5dcb6b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/compilers/babel-compiler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const babel = require('babel-core')
const path = require('path')
const fs = require('fs')
const throwError = require('../throw-error')

var defaultBabelOptions = {
presets: ['es2015'],
Expand All @@ -12,7 +13,7 @@ function getBabelRc (path) {
try {
rc = JSON.parse(fs.readFileSync(path, 'utf-8'))
} catch (e) {
throw new Error('[vue-jest] Your .babelrc seems to be incorrectly formatted.')
throwError('[Your .babelrc seems to be incorrectly formatted.')
}
return rc
}
Expand Down
3 changes: 2 additions & 1 deletion lib/compilers/coffee-compiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var ensureRequire = require('../ensure-require.js')
const throwError = require('../throw-error')

module.exports = function (raw, cb, compiler) {
ensureRequire('coffee', ['coffee-script'])
Expand All @@ -10,7 +11,7 @@ module.exports = function (raw, cb, compiler) {
sourceMap: true
})
} catch (err) {
throw new Error(err)
throwError(err)
}
return {
code: compiled.js,
Expand Down
3 changes: 2 additions & 1 deletion lib/compilers/jade-compiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var ensureRequire = require('../ensure-require.js')
const throwError = require('../throw-error')

module.exports = function (raw) {
var html;
Expand All @@ -7,7 +8,7 @@ module.exports = function (raw) {
try {
var html = jade.compile(raw)()
} catch (err) {
throw Error(err)
throwError(err)
}
return html
}
3 changes: 2 additions & 1 deletion lib/compilers/pug-compiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var ensureRequire = require('../ensure-require.js')
const throwError = require('../throw-error')

module.exports = function (raw) {
var html;
Expand All @@ -7,7 +8,7 @@ module.exports = function (raw) {
try {
var html = jade.compile(raw)()
} catch (err) {
throw Error(err)
throwError(err)
}
return html
}
4 changes: 3 additions & 1 deletion lib/ensure-require.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const throwError = require('./throw-error')

module.exports = function (name, deps) {
var i, len
var missing = []
Expand Down Expand Up @@ -33,6 +35,6 @@ module.exports = function (name, deps) {
message += missing[0] + ' is '
}
message += 'missing.\n\nTo install run:\n' + npmInstall
throw new Error(message)
throwError(message)
}
}
3 changes: 2 additions & 1 deletion lib/template-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var vueCompiler = require('vue-template-compiler')
var transpile = require('vue-template-es2015-compiler')
var compilePug = require('./compilers/pug-compiler')
var compileJade = require('./compilers/jade-compiler')
const throwError = require('./throw-error')

function getTemplateContent(templatePart) {
if(templatePart.lang === 'pug') {
Expand All @@ -22,7 +23,7 @@ module.exports = function compileTemplate (templatePart, compiler) {
compiled.errors.forEach(function (msg) {
console.error('\n' + chalk.red(msg) + '\n')
})
throw new Error('Vue template compilation failed')
throwError('Vue template compilation failed')
} else {
return {
render: toFunction(compiled.render),
Expand Down
3 changes: 3 additions & 0 deletions lib/throw-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function error (msg){
throw new Error('\n[jest-vue] Error: ' + (msg) + '\n')
}

0 comments on commit d5dcb6b

Please sign in to comment.