Skip to content

Commit a74869b

Browse files
committed
Intercept output during functional tests (fixes #47)
1 parent e3fbf67 commit a74869b

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)