Skip to content

add --progress cli test #1182

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

Merged
merged 2 commits into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const assert = require('assert');
const path = require('path');
const execa = require('execa');
const runDevServer = require('./helpers/run-webpack-dev-server');


describe('SIGINT', () => {
it('should exit the process when SIGINT is detected', (done) => {
Expand All @@ -26,3 +28,15 @@ describe('SIGINT', () => {
});
}).timeout(4000);
});

describe('CLI', () => {
it('--progress', (done) => {
runDevServer('--progress')
.then((output) => {
assert(output.code === 0);
assert(output.stderr.indexOf('0% compiling') >= 0);
done();
})
.catch(done);
}).timeout(4000);
});
3 changes: 3 additions & 0 deletions test/fixtures/cli/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

console.log('i am foo!');
20 changes: 20 additions & 0 deletions test/fixtures/cli/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

module.exports = {
context: __dirname,
entry: './foo.js',
output: {
filename: 'bundle.js'
},
plugins: [{
apply(compiler) {
compiler.plugin('done', (stats) => {
let exitCode = 0;
if (stats.hasErrors()) {
exitCode = 1;
}
setTimeout(() => process.exit(exitCode));
});
}
}]
};
50 changes: 50 additions & 0 deletions test/helpers/run-webpack-dev-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

const path = require('path');
const spawn = require('child_process').spawn;

const webpackDevServerPath = path.resolve(__dirname, '../../bin/webpack-dev-server.js');
const basicConfigPath = path.resolve(__dirname, '../fixtures/cli/webpack.config.js');


function runWebackDevServer(testArgs, configPath) {
const cwd = process.cwd();
const env = process.env.NODE_ENV;
let stdout = '';
let stderr = '';

if (!configPath) {
configPath = basicConfigPath;
}

if (!testArgs) {
testArgs = [];
} else if (typeof testArgs === 'string') {
testArgs = testArgs.split(' ');
}

const args = [webpackDevServerPath, '--config', configPath].concat(testArgs);

return new Promise((resolve, reject) => {
const child = spawn('node', args, { cwd, env });

child.on('error', error => reject(error));

child.stdout.on('data', (data) => {
stdout += data.toString();
});

child.stderr.on('data', (data) => {
stderr += data.toString();
});

child.on('close', (code) => {
if (code !== 0) {
return reject(stderr);
}
resolve({ stdout, stderr, code });
});
});
}

module.exports = runWebackDevServer;