Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Dec 14, 2023
1 parent a85766d commit e67f3e0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions test/fixtures/verbose-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
import {$} from '../../index.js';

const $$ = $({stdio: 'inherit'});
await $$`node -p "one"`;
await $$`node -p "two"`;
await $$`node -e console.error("one")`;
await $$`node -e console.error("two")`;
4 changes: 3 additions & 1 deletion test/kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ const spawnAndKill = async (t, [signal, cleanup, detached, isKilled]) => {
const exitIfWindows = process.platform === 'win32';
test('spawnAndKill SIGTERM', spawnAndKill, ['SIGTERM', false, false, exitIfWindows]);
test('spawnAndKill SIGKILL', spawnAndKill, ['SIGKILL', false, false, exitIfWindows]);
test('spawnAndKill cleanup SIGTERM', spawnAndKill, ['SIGTERM', true, false, true]);
// The `cleanup` option can introduce a race condition in this test
// This is especially true when run concurrently, so wwe use `test.serial()`
test.serial('spawnAndKill cleanup SIGTERM', spawnAndKill, ['SIGTERM', true, false, true]);
test('spawnAndKill cleanup SIGKILL', spawnAndKill, ['SIGKILL', true, false, exitIfWindows]);
test('spawnAndKill detached SIGTERM', spawnAndKill, ['SIGTERM', false, true, false]);
test('spawnAndKill detached SIGKILL', spawnAndKill, ['SIGKILL', false, true, false]);
Expand Down
9 changes: 5 additions & 4 deletions test/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ const pipeToFile = async (t, fixtureName, funcName, streamName) => {
t.is(await readFile(file, 'utf8'), 'test\n');
};

test('pipeStdout() can pipe to files', pipeToFile, 'noop.js', 'pipeStdout', 'stdout');
test('pipeStderr() can pipe to files', pipeToFile, 'noop-err.js', 'pipeStderr', 'stderr');
test('pipeAll() can pipe stdout to files', pipeToFile, 'noop.js', 'pipeAll', 'stdout');
test('pipeAll() can pipe stderr to files', pipeToFile, 'noop-err.js', 'pipeAll', 'stderr');
// `test.serial()` is due to a race condition: `execa(...).pipe*(file)` might resolve before the file stream has resolved
test.serial('pipeStdout() can pipe to files', pipeToFile, 'noop.js', 'pipeStdout', 'stdout');
test.serial('pipeStderr() can pipe to files', pipeToFile, 'noop-err.js', 'pipeStderr', 'stderr');
test.serial('pipeAll() can pipe stdout to files', pipeToFile, 'noop.js', 'pipeAll', 'stdout');
test.serial('pipeAll() can pipe stderr to files', pipeToFile, 'noop-err.js', 'pipeAll', 'stderr');

const invalidTarget = (t, funcName, getTarget) => {
t.throws(() => execa('noop.js', {all: true})[funcName](getTarget()), {
Expand Down
12 changes: 5 additions & 7 deletions test/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ const normalizeTimestamp = output => output.replaceAll(/\d/g, '0');
const testTimestamp = '[00:00:00.000]';

test('Prints command when "verbose" is true', async t => {
const {stdout, stderr, all} = await execa('nested.js', [JSON.stringify({verbose: true}), 'noop.js', 'test'], {all: true});
const {stdout, stderr} = await execa('nested.js', [JSON.stringify({verbose: true}), 'noop.js', 'test'], {all: true});
t.is(stdout, 'test');
t.is(normalizeTimestamp(stderr), `${testTimestamp} noop.js test`);
t.is(normalizeTimestamp(all), `${testTimestamp} noop.js test\ntest`);
});

test('Prints command with NODE_DEBUG=execa', async t => {
const {stdout, stderr, all} = await execa('nested.js', [JSON.stringify({}), 'noop.js', 'test'], {all: true, env: {NODE_DEBUG: 'execa'}});
const {stdout, stderr} = await execa('nested.js', [JSON.stringify({}), 'noop.js', 'test'], {all: true, env: {NODE_DEBUG: 'execa'}});
t.is(stdout, 'test');
t.is(normalizeTimestamp(stderr), `${testTimestamp} noop.js test`);
t.is(normalizeTimestamp(all), `${testTimestamp} noop.js test\ntest`);
});

test('Escape verbose command', async t => {
Expand All @@ -27,9 +25,9 @@ test('Escape verbose command', async t => {
});

test('Verbose option works with inherit', async t => {
const {all} = await execa('verbose-script.js', {all: true, env: {NODE_DEBUG: 'execa'}});
t.is(normalizeTimestamp(all), `${testTimestamp} node -p "\\"one\\""
const {stderr} = await execa('verbose-script.js', {all: true, env: {NODE_DEBUG: 'execa'}});
t.is(normalizeTimestamp(stderr), `${testTimestamp} node -e "console.error(\\"one\\")"
one
${testTimestamp} node -p "\\"two\\""
${testTimestamp} node -e "console.error(\\"two\\")"
two`);
});

0 comments on commit e67f3e0

Please sign in to comment.