1
1
import { describe , it , expect } from '@jest/globals' ;
2
- import { exec } from 'node:child_process' ;
2
+ import { execFile } from 'node:child_process' ;
3
3
import path from 'node:path' ;
4
4
import process from 'node:process' ;
5
5
@@ -8,13 +8,15 @@ const cliPath = path.resolve(__dirname, '../dist/cli.js');
8
8
const doIntegration = process . env [ 'TEST_INTEGRATION' ] ?. toLowerCase ( ) === 'true' ;
9
9
const doRemote = process . env [ 'TEST_REMOTE' ] ?. toLowerCase ( ) === 'true' ;
10
10
11
+ const url = process . env [ 'TEST_LI_URL' ] || 'http://localhost:3000' ;
12
+
11
13
const describeIntegration = doIntegration ? describe : describe . skip ;
12
14
// const describeRemote = doRemote ? describe : describe.skip;
13
15
const itRemote = doRemote ? it : it . skip ;
14
16
15
17
describeIntegration ( 'CLI Integration Tests' , ( ) => {
16
18
it ( 'should show help with no arguments' , ( done ) => {
17
- exec ( ` node ${ cliPath } ` , ( error , stdout , stderr ) => {
19
+ execFile ( ' node' , [ cliPath ] , ( error , stdout , stderr ) => {
18
20
expect ( stderr ) . toContain ( ' <command>' ) ;
19
21
expect ( stderr ) . toContain ( 'Not enough non-option arguments' ) ;
20
22
expect ( stderr ) . toContain ( ' add-license ' ) ;
@@ -24,24 +26,25 @@ describeIntegration('CLI Integration Tests', () => {
24
26
25
27
describeIntegration ( 'add-license' , ( ) => {
26
28
it ( '--help' , ( done ) => {
27
- exec ( ` node ${ cliPath } add-license --help` , ( error , stdout ) => {
29
+ execFile ( ' node' , [ cliPath , ' add-license' , ' --help' ] , ( error , stdout ) => {
28
30
expect ( stdout ) . toContain ( ' add-license ' ) ;
29
31
expect ( stdout ) . toContain ( '--require-cal' ) ;
30
32
done ( ) ;
31
33
} ) ;
32
34
} ) ;
33
35
34
36
it ( 'should require --li-url' , ( done ) => {
35
- exec ( ` node ${ cliPath } add-license` , ( error , stdout , stderr ) => {
37
+ execFile ( ' node' , [ cliPath , ' add-license' ] , ( error , stdout , stderr ) => {
36
38
expect ( stderr ) . toContain ( 'Missing required argument: li-url' ) ;
37
39
expect ( stderr ) . toContain ( '--require-cal' ) ;
38
40
done ( ) ;
39
41
} ) ;
40
42
} ) ;
41
43
42
44
itRemote ( 'should apply a license' , ( done ) => {
43
- exec (
44
- `node ${ cliPath } add-license --li-url http://localhost:3000 apache-2.0` ,
45
+ execFile (
46
+ 'node' ,
47
+ [ cliPath , 'add-license' , '--li-url' , url , 'apache-2.0' ] ,
45
48
( error , stdout , stderr ) => {
46
49
expect ( stdout ) . toContain ( 'fetching license list' ) ;
47
50
expect ( stdout ) . toContain ( 'Choose A License info' ) ;
0 commit comments