1- import { join } from 'path' ;
21import { describe , expect , it , vi } from 'vitest' ;
32import { getAsyncProcessRunnerConfig , mockProcessConfig } from '../../test' ;
4- import { executeProcess , objectToCliArgs } from './execute-process' ;
5-
6- const outFolder = '' ;
7- const outName = 'tmp/out-async-runner.json' ;
8- const outputFile = join ( outFolder , outName ) ;
3+ import { executeProcess } from './execute-process' ;
94
105describe ( 'executeProcess' , ( ) => {
116 it ( 'should work with node command `node -v`' , async ( ) => {
127 const cfg = mockProcessConfig ( { command : `node` , args : [ '-v' ] } ) ;
138 const processResult = await executeProcess ( cfg ) ;
14- expect ( processResult . stdout ) . toContain ( 'v' ) ;
9+ expect ( processResult . stdout ) . toMatch ( / v [ 0 - 9 ] { 1 , 2 } ( \. [ 0 - 9 ] { 1 , 2 } ) { 0 , 2 } / ) ;
1510 } ) ;
1611
1712 it ( 'should work with npx command `npx --help`' , async ( ) => {
@@ -20,12 +15,12 @@ describe('executeProcess', () => {
2015 const processResult = await executeProcess ( cfg ) ;
2116 expect ( observer ?. onStdout ) . toHaveBeenCalledTimes ( 1 ) ;
2217 expect ( observer ?. onComplete ) . toHaveBeenCalledTimes ( 1 ) ;
23- expect ( processResult . stdout ) . toContain ( 'Options ' ) ;
18+ expect ( processResult . stdout ) . toContain ( 'npm exec ' ) ;
2419 } ) ;
2520
2621 it ( 'should work with script `node custom-script.js`' , async ( ) => {
2722 const cfg = mockProcessConfig (
28- getAsyncProcessRunnerConfig ( { interval : 10 , outputFile } ) ,
23+ getAsyncProcessRunnerConfig ( { interval : 10 } ) ,
2924 ) ;
3025 const { observer } = cfg ;
3126 const errorSpy = vi . fn ( ) ;
@@ -51,60 +46,3 @@ describe('executeProcess', () => {
5146 expect ( observer ?. onError ) . toHaveBeenCalledTimes ( 1 ) ;
5247 } ) ;
5348} ) ;
54-
55- describe ( 'objectToCliArgs' , ( ) => {
56- it ( 'should handle the "_" argument as script' , ( ) => {
57- const params = { _ : 'bin.js' } ;
58- const result = objectToCliArgs ( params ) ;
59- expect ( result ) . toEqual ( [ 'bin.js' ] ) ;
60- } ) ;
61-
62- it ( 'should handle the "_" argument with multiple values' , ( ) => {
63- const params = { _ : [ 'bin.js' , '--help' ] } ;
64- const result = objectToCliArgs ( params ) ;
65- expect ( result ) . toEqual ( [ 'bin.js' , '--help' ] ) ;
66- } ) ;
67-
68- it ( 'should handle shorthands arguments' , ( ) => {
69- const params = {
70- e : `test` ,
71- } ;
72- const result = objectToCliArgs ( params ) ;
73- expect ( result ) . toEqual ( [ `-e="${ params . e } "` ] ) ;
74- } ) ;
75-
76- it ( 'should handle string arguments' , ( ) => {
77- const params = { name : 'Juanita' } ;
78- const result = objectToCliArgs ( params ) ;
79- expect ( result ) . toEqual ( [ '--name="Juanita"' ] ) ;
80- } ) ;
81-
82- it ( 'should handle number arguments' , ( ) => {
83- const params = { parallel : 5 } ;
84- const result = objectToCliArgs ( params ) ;
85- expect ( result ) . toEqual ( [ '--parallel=5' ] ) ;
86- } ) ;
87-
88- it ( 'should handle boolean arguments' , ( ) => {
89- const params = { progress : true } ;
90- const result = objectToCliArgs ( params ) ;
91- expect ( result ) . toEqual ( [ '--progress' ] ) ;
92- } ) ;
93-
94- it ( 'should handle negated boolean arguments' , ( ) => {
95- const params = { progress : false } ;
96- const result = objectToCliArgs ( params ) ;
97- expect ( result ) . toEqual ( [ '--no-progress' ] ) ;
98- } ) ;
99-
100- it ( 'should handle array of string arguments' , ( ) => {
101- const params = { format : [ 'json' , 'md' ] } ;
102- const result = objectToCliArgs ( params ) ;
103- expect ( result ) . toEqual ( [ '--format="json"' , '--format="md"' ] ) ;
104- } ) ;
105-
106- it ( 'should throw error for unsupported type' , ( ) => {
107- const params = { unsupported : undefined as any } ;
108- expect ( ( ) => objectToCliArgs ( params ) ) . toThrow ( 'Unsupported type' ) ;
109- } ) ;
110- } ) ;
0 commit comments