mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

PR-URL: https://github.com/nodejs/node/pull/52609 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
// 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/);
|
|
assert.match(child.stderr, /Can't read package\.json/);
|
|
assert.strictEqual(child.stdout, '');
|
|
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 },
|
|
);
|
|
assert.match(child.stderr, /Can't read package\.json/);
|
|
assert.strictEqual(child.stdout, '');
|
|
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,
|
|
[ '--no-warnings', '--run', `positional-args${envSuffix}`, '--', '--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);
|
|
});
|
|
});
|