2024-04-07 20:49:14 -04:00
|
|
|
// Flags: --expose-internals
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const { it, describe } = require('node:test');
|
|
|
|
const assert = require('node:assert');
|
|
|
|
|
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const envSuffix = common.isWindows ? '-windows' : '';
|
|
|
|
|
|
|
|
describe('node run [command]', () => {
|
|
|
|
it('should emit experimental warning', async () => {
|
|
|
|
const child = await common.spawnPromisified(
|
|
|
|
process.execPath,
|
|
|
|
[ '--run', 'test'],
|
|
|
|
{ cwd: __dirname },
|
|
|
|
);
|
|
|
|
assert.match(child.stderr, /ExperimentalWarning: Task runner is an experimental feature and might change at any time/);
|
2024-05-02 15:54:02 -04:00
|
|
|
assert.match(child.stderr, /Can't read package\.json/);
|
|
|
|
assert.strictEqual(child.stdout, '');
|
2024-04-07 20:49:14 -04:00
|
|
|
assert.strictEqual(child.code, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns error on non-existent file', async () => {
|
|
|
|
const child = await common.spawnPromisified(
|
|
|
|
process.execPath,
|
|
|
|
[ '--no-warnings', '--run', 'test'],
|
|
|
|
{ cwd: __dirname },
|
|
|
|
);
|
2024-05-02 15:54:02 -04:00
|
|
|
assert.match(child.stderr, /Can't read package\.json/);
|
|
|
|
assert.strictEqual(child.stdout, '');
|
2024-04-07 20:49:14 -04:00
|
|
|
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', '--no-warnings'],
|
|
|
|
{ cwd: fixtures.path('run-script') },
|
|
|
|
);
|
|
|
|
assert.match(child.stdout, /Error: no test specified/);
|
|
|
|
assert.strictEqual(child.code, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds node_modules/.bin to path', async () => {
|
|
|
|
const child = await common.spawnPromisified(
|
|
|
|
process.execPath,
|
|
|
|
[ '--no-warnings', '--run', `ada${envSuffix}`],
|
|
|
|
{ cwd: fixtures.path('run-script') },
|
|
|
|
);
|
|
|
|
assert.match(child.stdout, /06062023/);
|
|
|
|
assert.strictEqual(child.stderr, '');
|
|
|
|
assert.strictEqual(child.code, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('appends positional arguments', async () => {
|
|
|
|
const child = await common.spawnPromisified(
|
|
|
|
process.execPath,
|
2024-05-08 07:37:07 -04:00
|
|
|
[ '--no-warnings', '--run', `positional-args${envSuffix}`, '--', '--help "hello world test"', 'A', 'B', 'C'],
|
2024-04-07 20:49:14 -04:00
|
|
|
{ cwd: fixtures.path('run-script') },
|
|
|
|
);
|
2024-05-08 07:37:07 -04:00
|
|
|
if (common.isWindows) {
|
|
|
|
assert.match(child.stdout, /Arguments: '--help ""hello world test"" A B C'/);
|
|
|
|
} else {
|
|
|
|
assert.match(child.stdout, /Arguments: '--help "hello world test" A B C'/);
|
|
|
|
}
|
|
|
|
assert.match(child.stdout, /The total number of arguments are: 4/);
|
2024-04-07 20:49:14 -04:00
|
|
|
assert.strictEqual(child.stderr, '');
|
|
|
|
assert.strictEqual(child.code, 0);
|
|
|
|
});
|
2024-05-04 17:27:05 -04:00
|
|
|
|
|
|
|
it('should set PATH environment variable to node_modules/.bin', async () => {
|
|
|
|
const child = await common.spawnPromisified(
|
|
|
|
process.execPath,
|
|
|
|
[ '--no-warnings', '--run', `path-env${envSuffix}`],
|
|
|
|
{ cwd: fixtures.path('run-script') },
|
|
|
|
);
|
|
|
|
assert.ok(child.stdout.includes(fixtures.path('run-script/node_modules/.bin')));
|
|
|
|
assert.strictEqual(child.stderr, '');
|
|
|
|
assert.strictEqual(child.code, 0);
|
|
|
|
});
|
2024-05-18 21:37:25 -04:00
|
|
|
|
|
|
|
it('should set special environment variables', async () => {
|
|
|
|
const scriptName = `special-env-variables${envSuffix}`;
|
|
|
|
const child = await common.spawnPromisified(
|
|
|
|
process.execPath,
|
|
|
|
[ '--no-warnings', '--run', scriptName],
|
|
|
|
{ cwd: fixtures.path('run-script') },
|
|
|
|
);
|
|
|
|
assert.ok(child.stdout.includes(scriptName));
|
|
|
|
assert.strictEqual(child.stderr, '');
|
|
|
|
assert.strictEqual(child.code, 0);
|
|
|
|
});
|
2024-04-07 20:49:14 -04:00
|
|
|
});
|