Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .node() method #200

Merged
merged 47 commits into from Jun 18, 2019
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ec492d8
Add fork method
Apr 3, 2019
f844651
Revert changes of stdio
GMartigny Apr 3, 2019
1a15ee7
Cover execArgv and compute stdio
GMartigny Apr 3, 2019
5f49784
Add tests for fork's stdio option
Apr 4, 2019
360f07c
Fix stdio fork tests
Apr 4, 2019
dbc4274
Fix stdio fork function
Apr 4, 2019
b03baf6
Add test for fork
Apr 4, 2019
0a116f8
Avoid mutating arguments to fork
Apr 5, 2019
2e83f03
Use execPath and execArgv
Apr 5, 2019
35e8167
Add more tests to the fork function
Apr 5, 2019
eb2f47a
Remove duplicate fixture file
GMartigny Apr 8, 2019
be63122
normalize
GMartigny Apr 8, 2019
483aa5c
Unshift unique args to windows OS cmd
GMartigny May 7, 2019
69e5571
Merge branch 'master' into addForkMethod
GMartigny May 7, 2019
e5783d0
Update readme, types and types tests
GMartigny May 10, 2019
5e6631a
Merge branch 'master' into addForkMethod
GMartigny May 10, 2019
cf79301
Remove unnecessary normalize
GMartigny May 10, 2019
2c2d727
Revert "Unshift unique args to windows OS cmd"
GMartigny May 10, 2019
f965897
Merge branch 'master' into addForkMethod
GMartigny May 21, 2019
0ed7fd6
Fix tests on windows
GMartigny May 21, 2019
7642806
Reword on readme
GMartigny May 21, 2019
e82b43a
Minor fixes
GMartigny May 21, 2019
054b49b
Fix tests on windows
GMartigny May 21, 2019
ac12a9f
Sync readme and type definition
GMartigny May 21, 2019
fe687c2
Readme fine tune
GMartigny May 22, 2019
497b23f
Allow for user to omit args on fork
GMartigny May 22, 2019
737e118
Add missing semicolon
GMartigny May 22, 2019
0f90a22
revert change to logo.sketch
GMartigny Jun 6, 2019
0fa3941
Move all tests to `test` directory
GMartigny Jun 6, 2019
b02d6f4
Rename `fork` to `node` and remove `silent` option
GMartigny Jun 6, 2019
c931818
Merge master
GMartigny Jun 6, 2019
5680794
Fix `.node()` tests
GMartigny Jun 6, 2019
d93cb69
Minor tweak to syntax
GMartigny Jun 6, 2019
f302e78
Remove linter warning
GMartigny Jun 6, 2019
7746b01
Add execution right to fixtures files
GMartigny Jun 6, 2019
9a65cc5
Fix path in fixtures
GMartigny Jun 6, 2019
f4b77c7
Capitalize `node.js`
GMartigny Jun 7, 2019
0fac604
Add shebang and `'use strict'`
GMartigny Jun 7, 2019
b37f98b
Move remaining fixtures files under `test`
GMartigny Jun 7, 2019
ed7e580
Fix file execution rights thanks to windows
GMartigny Jun 7, 2019
906045e
Rename `.node` specific params
GMartigny Jun 13, 2019
6e181cc
Link `.node` params to their definition
GMartigny Jun 13, 2019
87b861f
Change `.node` description
GMartigny Jun 13, 2019
6394e4d
Minor tweak in syntax
GMartigny Jun 13, 2019
656559c
Merge master
GMartigny Jun 13, 2019
00199ed
Merge master
GMartigny Jun 18, 2019
5c15cf2
Doc say `script` instead of `file` for `.node()`
GMartigny Jun 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 62 additions & 42 deletions test/stdio.js
Expand Up @@ -4,47 +4,67 @@ import stdio from '../lib/stdio';

util.inspect.styles.name = 'magenta';

function macro(t, input, expected) {
if (expected instanceof Error) {
t.throws(() => stdio(input), expected.message);
return;
}

const result = stdio(input);

if (typeof expected === 'object' && expected !== null) {
t.deepEqual(result, expected);
} else {
t.is(result, expected);
}
function createMacro(func) {
const macro = (t, input, expected) => {
if (expected instanceof Error) {
t.throws(() => stdio(input), expected.message);
GMartigny marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const result = func(input);

if (typeof expected === 'object' && expected !== null) {
t.deepEqual(result, expected);
} else {
t.is(result, expected);
}
};

macro.title = (providedTitle, input) => `${func.name} ${(providedTitle || util.inspect(input, {colors: true}))}`;

return macro;
}

macro.title = (providedTitle, input) => providedTitle || util.inspect(input, {colors: true});

test(macro, undefined, undefined);
test(macro, null, undefined);

test(macro, {stdio: 'inherit'}, 'inherit');
test(macro, {stdio: 'pipe'}, 'pipe');
test(macro, {stdio: 'ignore'}, 'ignore');
test(macro, {stdio: [0, 1, 2]}, [0, 1, 2]);

test(macro, {}, [undefined, undefined, undefined]);
test(macro, {stdio: []}, [undefined, undefined, undefined]);
test(macro, {stdin: 'pipe'}, ['pipe', undefined, undefined]);
test(macro, {stdout: 'ignore'}, [undefined, 'ignore', undefined]);
test(macro, {stderr: 'inherit'}, [undefined, undefined, 'inherit']);
test(macro, {stdin: 'pipe', stdout: 'ignore', stderr: 'inherit'}, ['pipe', 'ignore', 'inherit']);
test(macro, {stdin: 'pipe', stdout: 'ignore'}, ['pipe', 'ignore', undefined]);
test(macro, {stdin: 'pipe', stderr: 'inherit'}, ['pipe', undefined, 'inherit']);
test(macro, {stdout: 'ignore', stderr: 'inherit'}, [undefined, 'ignore', 'inherit']);
test(macro, {stdin: 0, stdout: 1, stderr: 2}, [0, 1, 2]);
test(macro, {stdin: 0, stdout: 1}, [0, 1, undefined]);
test(macro, {stdin: 0, stderr: 2}, [0, undefined, 2]);
test(macro, {stdout: 1, stderr: 2}, [undefined, 1, 2]);

test(macro, {stdio: {foo: 'bar'}}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `object`'));

test(macro, {stdin: 'inherit', stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));
test(macro, {stdin: 'inherit', stdio: ['pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));
test(macro, {stdin: 'inherit', stdio: [undefined, 'pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));
const stdioMacro = createMacro(stdio);

test(stdioMacro, undefined, undefined);
test(stdioMacro, null, undefined);

test(stdioMacro, {stdio: 'inherit'}, 'inherit');
test(stdioMacro, {stdio: 'pipe'}, 'pipe');
test(stdioMacro, {stdio: 'ignore'}, 'ignore');
test(stdioMacro, {stdio: [0, 1, 2]}, [0, 1, 2]);

test(stdioMacro, {}, [undefined, undefined, undefined]);
test(stdioMacro, {stdio: []}, [undefined, undefined, undefined]);
test(stdioMacro, {stdin: 'pipe'}, ['pipe', undefined, undefined]);
test(stdioMacro, {stdout: 'ignore'}, [undefined, 'ignore', undefined]);
test(stdioMacro, {stderr: 'inherit'}, [undefined, undefined, 'inherit']);
test(stdioMacro, {stdin: 'pipe', stdout: 'ignore', stderr: 'inherit'}, ['pipe', 'ignore', 'inherit']);
test(stdioMacro, {stdin: 'pipe', stdout: 'ignore'}, ['pipe', 'ignore', undefined]);
test(stdioMacro, {stdin: 'pipe', stderr: 'inherit'}, ['pipe', undefined, 'inherit']);
test(stdioMacro, {stdout: 'ignore', stderr: 'inherit'}, [undefined, 'ignore', 'inherit']);
test(stdioMacro, {stdin: 0, stdout: 1, stderr: 2}, [0, 1, 2]);
test(stdioMacro, {stdin: 0, stdout: 1}, [0, 1, undefined]);
test(stdioMacro, {stdin: 0, stderr: 2}, [0, undefined, 2]);
test(stdioMacro, {stdout: 1, stderr: 2}, [undefined, 1, 2]);

test(stdioMacro, {stdio: {foo: 'bar'}}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `object`'));

test(stdioMacro, {stdin: 'inherit', stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));
test(stdioMacro, {stdin: 'inherit', stdio: ['pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));
test(stdioMacro, {stdin: 'inherit', stdio: [undefined, 'pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));

const forkMacro = createMacro(stdio.fork);

test(forkMacro, undefined, ['pipe', 'pipe', 'pipe', 'ipc']);
GMartigny marked this conversation as resolved.
Show resolved Hide resolved
test(forkMacro, {stdio: 'ignore'}, ['ignore', 'ignore', 'ignore', 'ipc']);
test(forkMacro, {stdio: [0, 1, 2]}, [0, 1, 2, 'ipc']);
test(forkMacro, {stdio: [0, 1, 2, 3]}, [0, 1, 2, 3, 'ipc']);
GMartigny marked this conversation as resolved.
Show resolved Hide resolved

test(forkMacro, {stdout: 'ignore'}, ['pipe', 'ignore', 'pipe', 'ipc']);
test(forkMacro, {stdout: 'ignore', stderr: 'ignore'}, ['pipe', 'ignore', 'ignore', 'ipc']);

test(forkMacro, {silent: true, stdio: 'ignore'}, ['pipe', 'pipe', 'pipe', 'ipc']);
test(forkMacro, {silent: true, stdio: [0, 1, 2, 42, 5]}, ['pipe', 'pipe', 'pipe', 'ipc']);
GMartigny marked this conversation as resolved.
Show resolved Hide resolved
test(forkMacro, {silent: true, stdout: 'ignore'}, ['pipe', 'pipe', 'pipe', 'ipc']);