Skip to content

Commit

Permalink
Intercept output during functional tests (fixes #47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrkan committed Aug 18, 2017
1 parent e3fbf67 commit a74869b
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions lib/test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,47 @@ function createWebpackConfig(testAppDir, outputDirName = '', command, argv = {})
}

function runWebpack(webpackConfig, callback, allowCompilationError = false) {
validator(webpackConfig);
const compiler = webpack(configGenerator(webpackConfig));
compiler.run((err, stats) => {
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
const stdoutWrite = process.stdout.write;

throw new Error('Error running webpack!');
}
try {
// Mute stdout
process.stdout.write = () => {};

const info = stats.toJson();
validator(webpackConfig);

if (stats.hasErrors() && !allowCompilationError) {
console.error(info.errors);
const compiler = webpack(configGenerator(webpackConfig));
compiler.run((err, stats) => {

throw new Error('Compilation error running webpack!');
}
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}

if (stats.hasWarnings()) {
console.warn(info.warnings);
}
throw new Error('Error running webpack!');
}

callback(assertUtil(webpackConfig), stats);
});
const info = stats.toJson();

if (stats.hasErrors() && !allowCompilationError) {
console.error(info.errors);

throw new Error('Compilation error running webpack!');
}

if (stats.hasWarnings()) {
console.warn(info.warnings);
}

// Restore stdout and then call the callback
process.stdout.write = stdoutWrite;
callback(assertUtil(webpackConfig), stats);
});
} catch (e) {
// Restore stdout and then re-throw the exception
process.stdout.write = stdoutWrite;
throw e;
}
}

function emptyTmpDir() {
Expand Down Expand Up @@ -158,6 +173,7 @@ function requestTestPage(webRootDir, scriptSrcs, callback) {
startHttpServer('8090', webRootDir);

const browser = new Browser();
browser.silent = true;
browser.on('error', function(error) {
throw new Error(`Error when running the browser: ${error}`);
});
Expand Down

0 comments on commit a74869b

Please sign in to comment.