Skip to content

Commit 6d499f2

Browse files
authored
test: add async throw tests (tinylibs#133)
1 parent 3bafedb commit 6d499f2

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/test/main_test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ describe('exec (async)', () => {
6464
expect(proc.exitCode).toBe(1);
6565
});
6666

67+
test('async iterator throws when throwOnError=true and exit non-zero', async () => {
68+
const proc = x('node', ['-e', "console.log('foo'); process.exit(1);"], {
69+
throwOnError: true
70+
});
71+
const lines: string[] = [];
72+
await expect(async () => {
73+
for await (const line of proc) {
74+
lines.push(line);
75+
}
76+
}).rejects.toThrow(NonZeroExitError);
77+
expect(lines).toEqual(['foo']);
78+
expect(proc.exitCode).toBe(1);
79+
});
80+
6781
test('supports stdin passed as a string', async () => {
6882
let result = await x('node', ['-e', 'process.stdin.pipe(process.stdout)'], {
6983
stdin: 'foo\nbar'

0 commit comments

Comments
 (0)