forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-node-run.js
More file actions
77 lines (69 loc) · 2.26 KB
/
test-node-run.js
File metadata and controls
77 lines (69 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
const common = require('../common');
const { it, describe } = require('node:test');
const assert = require('node:assert');
const fixtures = require('../common/fixtures');
describe('node run [command]', () => {
it('returns error on non-existent command', async () => {
const child = await common.spawnPromisified(
process.execPath,
[ 'run', 'test'],
{ cwd: __dirname },
);
assert.match(child.stdout, /Can't read package\.json/);
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 1);
});
it('runs a valid command', async () => {
// Run a script that just log `no test specified`
const child = await common.spawnPromisified(
process.execPath,
[ 'run', 'test'],
{ cwd: fixtures.path('run-script') },
);
assert.match(child.stdout, /Error: no test specified/);
assert.strictEqual(child.code, 1);
});
let adabatch = 'ada';
if (common.isWindows) {
adabatch = 'ada.bat';
}
it('adds node_modules/.bin to path', async () => {
const child = await common.spawnPromisified(
process.execPath,
[ 'run', adabatch],
{ cwd: fixtures.path('run-script') },
);
assert.match(child.stdout, /06062023/);
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});
let posbatch = 'positional-args';
if (common.isWindows) {
posbatch = 'positional-args.bat';
}
it('appends positional arguments', async () => {
const child = await common.spawnPromisified(
process.execPath,
[ 'run', posbatch, '--help "hello world test"'],
{ cwd: fixtures.path('run-script') },
);
assert.match(child.stdout, /--help ["]*hello world test.*/);
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});
let cusbatch = 'custom-env';
if (common.isWindows) {
cusbatch = 'custom-env.bat';
}
it('should support having --env-file cli flag', async () => {
const child = await common.spawnPromisified(
process.execPath,
[ `--env-file=${fixtures.path('run-script/.env')}`, 'run', cusbatch],
{ cwd: fixtures.path('run-script') },
);
assert.match(child.stdout, /hello world/);
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});
});