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

Set process exit code (See #7) #8

Merged
merged 3 commits into from
Jan 18, 2019
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
23 changes: 14 additions & 9 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ const chokidar = require('chokidar');
* @param {string} conf.spec Glob to mocha spec files.
*/

const preProcess = (conf) => ({
const preProcess = conf => ({
watchedDirectories: conf.watch && conf.watch.length ? conf.watch.split(',') : [],
webpackConfig: `${conf['webpack-config'] ? conf['webpack-config'] : path.join(__dirname, 'webpack.config.js') }`,
webpackConfig: `${conf['webpack-config'] ? conf['webpack-config'] : path.join(__dirname, 'webpack.config.js')}`,
specGlob: `${conf.spec ? conf.spec : ''}`,
coverage: conf.coverage,
});

module.exports.preProcess = preProcess;

module.exports.run = conf => {
module.exports.run = (conf) => {
let watcher;

if (!conf) {
Expand All @@ -29,7 +29,7 @@ module.exports.run = conf => {

const confPreprocessed = preProcess(conf);

console.log(`Running tests:` );
console.log('Running tests:');
console.log('--------------------------------');
console.log(`watched directories: ${confPreprocessed.watchedDirectories}`);
console.log(`webpack config: ${conf['webpack-config'] ? conf['webpack-config'] : 'Using built-in config'}`);
Expand All @@ -41,7 +41,6 @@ module.exports.run = conf => {
* Compile via webpack config and run unit tests.
*/
const run = () => {

// Base spawn command.
const spawnCmd = [
'cross-env',
Expand All @@ -55,7 +54,7 @@ module.exports.run = conf => {
confPreprocessed.webpackConfig,
'--require', path.join(__dirname, 'setup.js'),
'--require', 'ignore-styles',
confPreprocessed.specGlob
confPreprocessed.specGlob,
];

// Remove nyc if not running coverage.
Expand All @@ -79,15 +78,21 @@ module.exports.run = conf => {
});

// Log errors.
cmd.stderr.on('data', data => console.log(data.toString()))
cmd.stderr.on('data', (data) => {
console.log(data.toString());
});

cmd.on('exit', (code) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix.

process.exitCode = code;
});
};

// Re-run tests on file change.
if (confPreprocessed.watchedDirectories.length > 0) {
if (!watcher) {
watcher = chokidar.watch(confPreprocessed.watchedDirectories);
watcher.on('change', (path) => {
console.log(`${path} changed.`);
watcher.on('change', (pathToFile) => {
console.log(`${pathToFile} changed.`);
run();
});
}
Expand Down
Loading