Skip to content

Commit 2e6420b

Browse files
committed
test: add test for spawnAsPromise
1 parent 5a07329 commit 2e6420b

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

test/exit-code-err.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
process.stdout.write('Hello World!');
2+
process.stderr.write('Errors');
3+
process.exit(1);

test/exit-code.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
process.stdout.write('Hello World!');
2+
process.stderr.write('No errors');

test/tools.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import * as path from 'path';
12
import * as assert from 'assert';
2-
import { shellTask } from '../src/lib/tools';
3+
import { shellTask, spawnAsPromise } from '../src/lib/tools';
34

45
suite('Tools tests', () => {
56
test('shellTask returns correct output', async () => {
@@ -16,4 +17,36 @@ suite('Tools tests', () => {
1617
const name = 'pip: fortls';
1718
assert.rejects(shellTask('python3', ['-m', 'pip', 'install', 'fortls2'], name));
1819
});
20+
21+
test('spawnAsPromise correct stdout, stderr output exit code 0', async () => {
22+
const [stdout, stderr] = await spawnAsPromise('node', [
23+
path.resolve(__dirname, './exit-code.js'),
24+
]);
25+
assert.strictEqual(stdout, 'Hello World!');
26+
assert.strictEqual(stderr, 'No errors');
27+
});
28+
29+
test('spawnAsPromise correct stdout, stderr output exit code 1', async () => {
30+
try {
31+
const [stdout, stderr] = await spawnAsPromise('node', [
32+
path.resolve(__dirname, './exit-code-err.js'),
33+
]);
34+
} catch (error) {
35+
const [stdout, stderr] = error;
36+
assert.strictEqual(stdout, 'Hello World!');
37+
assert.strictEqual(stderr, 'Errors');
38+
}
39+
});
40+
41+
test('spawnAsPromise correct stdout, stderr output exit code 1 with ignoreExitCode', async () => {
42+
const [stdout, stderr] = await spawnAsPromise(
43+
'node',
44+
[path.resolve(__dirname, './exit-code-err.js')],
45+
undefined,
46+
undefined,
47+
true
48+
);
49+
assert.strictEqual(stdout, 'Hello World!');
50+
assert.strictEqual(stderr, 'Errors');
51+
});
1952
});

0 commit comments

Comments
 (0)