1
1
const childProcess = require ( 'child_process' ) ;
2
2
const path = require ( 'path' ) ;
3
3
const util = require ( 'util' ) ;
4
- const execAsync = util . promisify ( childProcess . exec ) ;
4
+ const execFileAsync = util . promisify ( childProcess . execFile ) ;
5
5
6
6
// Calling node explicitly so pm works without file suffix cross-platform.
7
7
@@ -13,7 +13,7 @@ const pm = path.join(__dirname, './fixtures/pm');
13
13
14
14
test ( 'when subcommand file missing then error' , ( ) => {
15
15
expect . assertions ( 1 ) ;
16
- return execAsync ( ` node ${ pm } list` ) . catch ( ( err ) => {
16
+ return execFileAsync ( ' node' , [ pm , ' list' ] ) . catch ( ( err ) => {
17
17
if ( process . platform === 'win32' ) {
18
18
// Get uncaught thrown error on Windows
19
19
// eslint-disable-next-line jest/no-conditional-expect
@@ -27,7 +27,7 @@ test('when subcommand file missing then error', () => {
27
27
28
28
test ( 'when alias subcommand file missing then error' , ( ) => {
29
29
expect . assertions ( 1 ) ;
30
- return execAsync ( ` node ${ pm } lst` ) . catch ( ( err ) => {
30
+ return execFileAsync ( ' node' , [ pm , ' lst' ] ) . catch ( ( err ) => {
31
31
if ( process . platform === 'win32' ) {
32
32
// Get uncaught thrown error on Windows
33
33
// eslint-disable-next-line jest/no-conditional-expect
@@ -40,44 +40,44 @@ test('when alias subcommand file missing then error', () => {
40
40
} ) ;
41
41
42
42
test ( 'when subcommand file has no suffix then lookup succeeds' , async ( ) => {
43
- const { stdout } = await execAsync ( ` node ${ pm } install` ) ;
43
+ const { stdout } = await execFileAsync ( ' node' , [ pm , ' install' ] ) ;
44
44
expect ( stdout ) . toBe ( 'install\n' ) ;
45
45
} ) ;
46
46
47
47
test ( 'when alias subcommand file has no suffix then lookup succeeds' , async ( ) => {
48
- const { stdout } = await execAsync ( ` node ${ pm } i` ) ;
48
+ const { stdout } = await execFileAsync ( ' node' , [ pm , 'i' ] ) ;
49
49
expect ( stdout ) . toBe ( 'install\n' ) ;
50
50
} ) ;
51
51
52
52
test ( 'when subcommand target executablefile has no suffix then lookup succeeds' , async ( ) => {
53
- const { stdout } = await execAsync ( ` node ${ pm } specifyInstall` ) ;
53
+ const { stdout } = await execFileAsync ( ' node' , [ pm , ' specifyInstall' ] ) ;
54
54
expect ( stdout ) . toBe ( 'install\n' ) ;
55
55
} ) ;
56
56
57
57
test ( 'when subcommand file suffix .js then lookup succeeds' , async ( ) => {
58
- const { stdout } = await execAsync ( ` node ${ pm } publish` ) ;
58
+ const { stdout } = await execFileAsync ( ' node' , [ pm , ' publish' ] ) ;
59
59
expect ( stdout ) . toBe ( 'publish\n' ) ;
60
60
} ) ;
61
61
62
62
test ( 'when alias subcommand file suffix .js then lookup succeeds' , async ( ) => {
63
- const { stdout } = await execAsync ( ` node ${ pm } p` ) ;
63
+ const { stdout } = await execFileAsync ( ' node' , [ pm , 'p' ] ) ;
64
64
expect ( stdout ) . toBe ( 'publish\n' ) ;
65
65
} ) ;
66
66
67
67
test ( 'when subcommand target executablefile has suffix .js then lookup succeeds' , async ( ) => {
68
- const { stdout } = await execAsync ( ` node ${ pm } specifyPublish` ) ;
68
+ const { stdout } = await execFileAsync ( ' node' , [ pm , ' specifyPublish' ] ) ;
69
69
expect ( stdout ) . toBe ( 'publish\n' ) ;
70
70
} ) ;
71
71
72
72
testOrSkipOnWindows ( 'when subcommand file is symlink then lookup succeeds' , async ( ) => {
73
73
const pmlink = path . join ( __dirname , 'fixtures' , 'pmlink' ) ;
74
- const { stdout } = await execAsync ( ` node ${ pmlink } install` ) ;
74
+ const { stdout } = await execFileAsync ( ' node' , [ pmlink , ' install' ] ) ;
75
75
expect ( stdout ) . toBe ( 'install\n' ) ;
76
76
} ) ;
77
77
78
78
testOrSkipOnWindows ( 'when subcommand file is double symlink then lookup succeeds' , async ( ) => {
79
79
const pmlink = path . join ( __dirname , 'fixtures' , 'another-dir' , 'pm' ) ;
80
- const { stdout } = await execAsync ( ` node ${ pmlink } install` ) ;
80
+ const { stdout } = await execFileAsync ( ' node' , [ pmlink , ' install' ] ) ;
81
81
expect ( stdout ) . toBe ( 'install\n' ) ;
82
82
} ) ;
83
83
@@ -86,11 +86,11 @@ test('when subcommand suffix is .ts then lookup succeeds', async() => {
86
86
// The program and the subcommand `pm-install.ts` are both plain JavaScript code.
87
87
const binLinkTs = path . join ( __dirname , 'fixtures-ts' , 'pm.ts' ) ;
88
88
// childProcess.execFile('node', ['-r', 'ts-node/register', binLinkTs, 'install'], function(_error, stdout, stderr) {
89
- const { stdout } = await execAsync ( ` node ${ binLinkTs } install` ) ;
89
+ const { stdout } = await execFileAsync ( ' node' , [ binLinkTs , ' install' ] ) ;
90
90
expect ( stdout ) . toBe ( 'install\n' ) ;
91
91
} ) ;
92
92
93
93
test ( 'when subsubcommand then lookup sub-sub-command' , async ( ) => {
94
- const { stdout } = await execAsync ( ` node ${ pm } cache clear` ) ;
94
+ const { stdout } = await execFileAsync ( ' node' , [ pm , ' cache' , ' clear' ] ) ;
95
95
expect ( stdout ) . toBe ( 'cache-clear\n' ) ;
96
96
} ) ;
0 commit comments