Skip to content

Commit 7907f28

Browse files
author
Walker Leite
committed
fix(karma): throws when vue warns
1 parent 3e8da00 commit 7907f28

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

template/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"loopback-chai": "^2.3.0",
7979
"mocha": "^3.4.2",
8080
"sinon": "^2.3.8",
81+
"through2": "^2.0.3",
8182
"tmp": "0.0.33",
8283
"vinyl-buffer": "^1.0.0",
8384
"vinyl-source-stream": "^1.1.0",

template/test/karma.conf.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@ import babelify from 'babelify';
22
import vueify from 'vueify';
33
import modulesify from 'css-modulesify';
44
import tmp from 'tmp';
5+
import through from 'through2';
56
import {dirs} from '../gulp-tasks/config';
67
import {customSass} from '../gulp-tasks/compilers';
78

89
const cssBundleFile = tmp.fileSync();
910

11+
// Just hook window.console to throw vue warn
12+
const consoleAppendfy = () => through(function (buf, enc, next) {
13+
const hook = `
14+
const error = console.error;
15+
console.error = function(warning, ...args) {
16+
if (/(Vue warn)/.test(warning)) {
17+
throw new Error(warning);
18+
}
19+
error.apply(console, [warning, ...args]);
20+
};
21+
`;
22+
this.push(hook + buf.toString('utf8'));
23+
next();
24+
});
25+
1026
export default (config) => {
1127
vueify.compiler.applyConfig({
1228
sass: {
@@ -31,7 +47,7 @@ export default (config) => {
3147
browserify: {
3248
output: cssBundleFile.name,
3349
debug: true,
34-
transform: [babelify, vueify],
50+
transform: [consoleAppendfy, babelify, vueify],
3551
plugin: [[modulesify, {
3652
global: true,
3753
generateScopedName(name, filename) {

0 commit comments

Comments
 (0)