Skip to content

Commit 1c98c9c

Browse files
committed
minor #143 Intercept Webpack output during functional tests (Lyrkan)
This PR was merged into the master branch. Discussion ---------- Intercept Webpack output during functional tests This PR replaces `process.stdout.write` by an empty function when running webpack in each functional test (fixes #47). It also sets the `silent` option of the Zombie.js browser to true to avoid displaying things like: ``` Download the Vue Devtools extension for a better development experience: https://github.com/vuejs/vue-devtools You are running Vue in development mode. Make sure to turn on production mode when deploying for production. See more tips at https://vuejs.org/guide/deployment.html ``` The only "noisy" message left should be `DeprecationWarning: Chunk.modules is deprecated. Use Chunk.getNumberOfModules/mapModules/forEachModule/containsModule instead` since it is sent to stderr (should be fixed when alexindigo/webpack-chunk-hash#9 is released). Commits ------- a74869b Intercept output during functional tests (fixes #47)
2 parents e3fbf67 + a74869b commit 1c98c9c

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

lib/test/setup.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,47 @@ function createWebpackConfig(testAppDir, outputDirName = '', command, argv = {})
6060
}
6161

6262
function runWebpack(webpackConfig, callback, allowCompilationError = false) {
63-
validator(webpackConfig);
64-
const compiler = webpack(configGenerator(webpackConfig));
65-
compiler.run((err, stats) => {
66-
if (err) {
67-
console.error(err.stack || err);
68-
if (err.details) {
69-
console.error(err.details);
70-
}
63+
const stdoutWrite = process.stdout.write;
7164

72-
throw new Error('Error running webpack!');
73-
}
65+
try {
66+
// Mute stdout
67+
process.stdout.write = () => {};
7468

75-
const info = stats.toJson();
69+
validator(webpackConfig);
7670

77-
if (stats.hasErrors() && !allowCompilationError) {
78-
console.error(info.errors);
71+
const compiler = webpack(configGenerator(webpackConfig));
72+
compiler.run((err, stats) => {
7973

80-
throw new Error('Compilation error running webpack!');
81-
}
74+
if (err) {
75+
console.error(err.stack || err);
76+
if (err.details) {
77+
console.error(err.details);
78+
}
8279

83-
if (stats.hasWarnings()) {
84-
console.warn(info.warnings);
85-
}
80+
throw new Error('Error running webpack!');
81+
}
8682

87-
callback(assertUtil(webpackConfig), stats);
88-
});
83+
const info = stats.toJson();
84+
85+
if (stats.hasErrors() && !allowCompilationError) {
86+
console.error(info.errors);
87+
88+
throw new Error('Compilation error running webpack!');
89+
}
90+
91+
if (stats.hasWarnings()) {
92+
console.warn(info.warnings);
93+
}
94+
95+
// Restore stdout and then call the callback
96+
process.stdout.write = stdoutWrite;
97+
callback(assertUtil(webpackConfig), stats);
98+
});
99+
} catch (e) {
100+
// Restore stdout and then re-throw the exception
101+
process.stdout.write = stdoutWrite;
102+
throw e;
103+
}
89104
}
90105

91106
function emptyTmpDir() {
@@ -158,6 +173,7 @@ function requestTestPage(webRootDir, scriptSrcs, callback) {
158173
startHttpServer('8090', webRootDir);
159174

160175
const browser = new Browser();
176+
browser.silent = true;
161177
browser.on('error', function(error) {
162178
throw new Error(`Error when running the browser: ${error}`);
163179
});

0 commit comments

Comments
 (0)