Skip to content

Commit

Permalink
Fix randomly failing tests (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Aug 27, 2024
1 parent 381a015 commit 9759b96
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,16 @@ test('Handles result.stderr error', async t => {
test.serial('promise.stdout iteration break waits for the subprocess success', async t => {
const promise = nanoSpawn('node', ['-e', 'process.stdin.pipe(process.stdout); console.log("a");']);
let done = false;
globalThis.setTimeout(() => {
t.true(promise.subprocess.stdout.readable);
t.true(promise.subprocess.stdin.writable);
promise.subprocess.stdin.end('b');
done = true;
}, 1e2);

// eslint-disable-next-line no-unreachable-loop
for await (const line of promise.stdout) {
t.is(line, 'a');
t.false(done);
globalThis.setTimeout(() => {
t.true(promise.subprocess.stdout.readable);
t.true(promise.subprocess.stdin.writable);
promise.subprocess.stdin.end('b');
done = true;
}, 1e2);
break;
}

Expand All @@ -370,19 +369,18 @@ test.serial('promise.stdout iteration break waits for the subprocess success', a
test.serial('promise.stdout iteration exception waits for the subprocess success', async t => {
const promise = nanoSpawn('node', ['-e', 'process.stdin.pipe(process.stdout); console.log("a");']);
let done = false;
globalThis.setTimeout(() => {
t.true(promise.subprocess.stdout.readable);
t.true(promise.subprocess.stdin.writable);
promise.subprocess.stdin.end('b');
done = true;
}, 1e2);

const cause = new Error(testString);
try {
// eslint-disable-next-line no-unreachable-loop
for await (const line of promise.stdout) {
t.is(line, 'a');
t.false(done);
globalThis.setTimeout(() => {
t.true(promise.subprocess.stdout.readable);
t.true(promise.subprocess.stdin.writable);
promise.subprocess.stdin.end('b');
done = true;
}, 1e2);
throw cause;
}
} catch (error) {
Expand All @@ -397,19 +395,18 @@ test.serial('promise.stdout iteration exception waits for the subprocess success
test.serial('promise.stdout iteration break waits for the subprocess failure', async t => {
const promise = nanoSpawn('node', ['-e', 'process.stdin.once("data", (chunk) => {console.log(chunk.toString()); process.exit(2)}); console.log("a");']);
let done = false;
globalThis.setTimeout(() => {
t.true(promise.subprocess.stdout.readable);
t.true(promise.subprocess.stdin.writable);
promise.subprocess.stdin.end('b');
done = true;
}, 1e2);

let cause;
try {
// eslint-disable-next-line no-unreachable-loop
for await (const line of promise.stdout) {
t.is(line, 'a');
t.false(done);
globalThis.setTimeout(() => {
t.true(promise.subprocess.stdout.readable);
t.true(promise.subprocess.stdin.writable);
promise.subprocess.stdin.end('b');
done = true;
}, 1e2);
break;
}
} catch (error) {
Expand All @@ -425,19 +422,18 @@ test.serial('promise.stdout iteration break waits for the subprocess failure', a
test.serial('promise.stdout iteration exception waits for the subprocess failure', async t => {
const promise = nanoSpawn('node', ['-e', 'process.stdin.once("data", (chunk) => {console.log(chunk.toString()); process.exit(2)}); console.log("a");']);
let done = false;
globalThis.setTimeout(() => {
t.true(promise.subprocess.stdout.readable);
t.true(promise.subprocess.stdin.writable);
promise.subprocess.stdin.end('b');
done = true;
}, 1e2);

const cause = new Error(testString);
try {
// eslint-disable-next-line no-unreachable-loop
for await (const line of promise.stdout) {
t.is(line, 'a');
t.false(done);
globalThis.setTimeout(() => {
t.true(promise.subprocess.stdout.readable);
t.true(promise.subprocess.stdin.writable);
promise.subprocess.stdin.end('b');
done = true;
}, 1e2);
throw cause;
}
} catch (error) {
Expand Down

0 comments on commit 9759b96

Please sign in to comment.