Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercept Webpack output during functional tests #143

Merged
merged 1 commit into from
Sep 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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