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

Fix tests on Windows #57

Merged
merged 12 commits into from
Sep 19, 2016
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ language: node_js
node_js:
- 6
- 4
- 0.12
- 0.11
before_script:
- npm install -g mocha
notifications:
Expand Down
7 changes: 2 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ install:
- npm install -g mocha
- set PATH=%APPDATA%\npm;%PATH%
- npm install
matrix:
fast_finish: true
build: off
version: '{build}'
shallow_clone: true
clone_depth: 1
test_script:
- node --version
- npm --version
- set SHELL=cmd.exe
- set SHELL_EXECUTION_FLAG=/c
- npm test
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var program = require('commander');
var _ = require('lodash');
var chalk = require('chalk');
var defaultShell = require('spawn-default-shell');
var isWindows = /^win/.test(process.platform);
var IS_WINDOWS = /^win/.test(process.platform);

var config = {
// Kill other processes if one dies
Expand Down Expand Up @@ -182,7 +182,7 @@ function run(commands) {
cmd = stripCmdQuotes(cmd);

var spawnOpts = config.raw ? {stdio: 'inherit'} : {};
if (isWindows) {
if (IS_WINDOWS) {
spawnOpts.detached = false;
}

Expand Down Expand Up @@ -291,8 +291,8 @@ function handleClose(streams, children, childrenInfo) {

// Send SIGTERM to alive children
_.each(aliveChildren, function(child) {
if (isWindows) {
spawn('taskkill', ["/pid", child.pid, '/f', '/t']);
if (IS_WINDOWS) {
defaultShell.spawn('taskkill /pid ' + child.pid + ' /f /t');
} else {
child.kill('SIGTERM');
}
Expand Down
103 changes: 51 additions & 52 deletions test/test-functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
var path = require('path');
var assert = require('assert');
var run = require('./utils').run;
var IS_WINDOWS = /^win/.test(process.platform);

// If true, output of commands are shown
var DEBUG_TESTS = false;
var DEBUG_TESTS = process.env.DEBUG_TESTS === 'true';
var TEST_DIR = 'dir/';

// Abs path to test directory
Expand All @@ -15,75 +16,73 @@ process.chdir(path.join(testDir, '..'));
describe('concurrently', function() {
this.timeout(5000);

it('help should be successful', function(done) {
run('node ./src/main.js --help', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
// exit code 0 means success
assert.strictEqual(exitCode, 0);
done();
});
it('help should be successful', () => {
return run('node ./src/main.js --help', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
// exit code 0 means success
assert.strictEqual(exitCode, 0);
});
});

it('version should be successful', function(done) {
run('node ./src/main.js -V', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
done();
});
it('version should be successful', () => {
return run('node ./src/main.js -V', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
});
});

it('two successful commands should exit 0', function(done) {
run('node ./src/main.js "echo" "echo"', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
done();
});
it('two successful commands should exit 0', () => {
return run('node ./src/main.js "echo test" "echo test"', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
});
});

it('at least one unsuccessful commands should exit non-zero', function(done) {
run('node ./src/main.js "echo" "return 1" "echo"', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.notStrictEqual(exitCode, 0);
done();
});
it('at least one unsuccessful commands should exit non-zero', () => {
return run('node ./src/main.js "echo test" "nosuchcmd" "echo test"', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.notStrictEqual(exitCode, 0);
});
});

it('--kill-others should kill other commands if one dies', function(done) {
it('--kill-others should kill other commands if one dies', () => {
// This test would timeout if kill others option does not work
run('node ./src/main.js --kill-others "sleep 1000" "echo" "sleep 1000"', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.notStrictEqual(exitCode, 0);
done();
});
return run('node ./src/main.js --kill-others "sleep 1000" "echo test" "sleep 1000"', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.notStrictEqual(exitCode, 0);
});
});

it('--success=first should return first exit code', function(done) {
run('node ./src/main.js -k --success first "echo" "sleep 1000" ', {pipe: DEBUG_TESTS})
// When killed, sleep returns null exit code
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
done();
});
it('--success=first should return first exit code', () => {
return run('node ./src/main.js -k --success first "echo test" "sleep 1000" ', {pipe: DEBUG_TESTS})
// When killed, sleep returns null exit code
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
});
});

it('--success=last should return last exit code', function(done) {
it('--success=last should return last exit code', () => {
// When killed, sleep returns null exit code
run('node ./src/main.js -k --success last "echo" "sleep 1000" ', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.notStrictEqual(exitCode, 0);
done();
});
return run('node ./src/main.js -k --success last "echo test" "sleep 1000" ', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.notStrictEqual(exitCode, 0);
});
});

it('&& exit 1 should return non-zero exit code', function(done) {
run('node ./src/main.js "echo 1 && return 1" "echo 2 && return 2" ', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 1);
done();
});
it('&& nosuchcmd should return non-zero exit code', () => {
return run('node ./src/main.js "echo 1 && nosuchcmd" "echo 1 && nosuchcmd" ', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 1);
});
});

['SIGINT', 'SIGTERM'].forEach(function(signal) {
['SIGINT', 'SIGTERM'].forEach((signal) => {
if (IS_WINDOWS) {
console.log('IS_WINDOWS=true');
console.log('Skipping SIGINT/SIGTERM propagation tests ..');
return;
}

it('killing it with ' + signal + ' should propagate the signal to the children', function(done) {
var readline = require('readline');
var waitingStart = 2;
Expand Down