node/test/parallel/test-child-process-spawnsync.js
Rich Trott fffa4c2528 test: speed up test-child-process-spawnsync.js
There's a bunch of stuff in test-child-process-spawnsync.js that seems
designed to test that it is in fact blocking/synchronous. However, that
code really just tests the OS sleep command. Change `sleep 1` to `sleep
0` and shave about one second off the test run.`

We check the return status to confirm the command is successful. The
tests in this file in general would not work if spawnSync() were
asynchronous. That includes this one, as a return status would not be
available if the command where asynchronous.

PR-URL: https://github.com/nodejs/node/pull/2542
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-08-25 13:16:58 -07:00

36 lines
1.1 KiB
JavaScript

'use strict';
var common = require('../common');
var assert = require('assert');
var spawnSync = require('child_process').spawnSync;
// Echo does different things on Windows and Unix, but in both cases, it does
// more-or-less nothing if there are no parameters
var ret = spawnSync('sleep', ['0']);
assert.strictEqual(ret.status, 0, 'exit status should be zero');
// Error test when command does not exist
var ret_err = spawnSync('command_does_not_exist', ['bar']).error;
assert.strictEqual(ret_err.code, 'ENOENT');
assert.strictEqual(ret_err.errno, 'ENOENT');
assert.strictEqual(ret_err.syscall, 'spawnSync command_does_not_exist');
assert.strictEqual(ret_err.path, 'command_does_not_exist');
assert.deepEqual(ret_err.spawnargs, ['bar']);
// Verify that the cwd option works - GH #7824
(function() {
var response;
var cwd;
if (common.isWindows) {
cwd = 'c:\\';
response = spawnSync('cmd.exe', ['/c', 'cd'], {cwd: cwd});
} else {
cwd = '/';
response = spawnSync('pwd', [], {cwd: cwd});
}
assert.strictEqual(response.stdout.toString().trim(), cwd);
})();