Skip to content

Commit

Permalink
minor #143 Intercept Webpack output during functional tests (Lyrkan)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
weaverryan committed Sep 2, 2017
2 parents e3fbf67 + a74869b commit 1c98c9c
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions lib/test/setup.js
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 1c98c9c

Please sign in to comment.