Skip to content

Commit bf729ab

Browse files
committed
Make test async & more generic
1 parent 7b3dbf4 commit bf729ab

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

tests/exec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
const { execvp } = require('../exec.js');
22

3-
execvp('ls', ['tests']);
3+
if (process.argv.length < 3) {
4+
throw new Error('Missing command');
5+
}
6+
7+
const [_node, _file, command, ...args] = process.argv;
8+
9+
execvp(command, args);

tests/exec.spec.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
const { execSync } = require('node:child_process');
1+
const { exec } = require('node:child_process');
2+
const { promisify } = require('node:util');
3+
4+
const execAsync = promisify(exec);
25

36
describe('exec', () => {
4-
test('it should work', () => {
5-
expect(execSync('node tests/exec.js').toString()).toBe('exec.js\nexec.spec.js\n');
7+
test('it should work', async () => {
8+
await expect(execAsync('node tests/exec.js ls tests')).resolves.toEqual({
9+
stderr: '',
10+
stdout: 'exec.js\nexec.spec.js\n'
11+
});
612
});
713
});

0 commit comments

Comments
 (0)