@@ -9,7 +9,7 @@ import axios from 'axios';
99
1010
1111// Mock axios
12- jest . mock ( 'axios' ) ;
12+ vi . mock ( 'axios' ) ;
1313
1414const execPromise = util . promisify ( exec ) ;
1515
@@ -19,11 +19,11 @@ describe('CLI Integration Tests', () => {
1919 const millisPerSecond = 1000 ;
2020 const integrationTestPrefix = 'calm-test' ;
2121 const projectRoot = __dirname ;
22- jest . setTimeout ( 30 * millisPerSecond ) ;
22+ vi . setConfig ( { testTimeout : 30 * millisPerSecond } ) ;
2323
2424 beforeAll ( async ( ) => {
2525 tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , integrationTestPrefix ) ) ;
26- await callNpxFunction ( ` ${ projectRoot } / ../..` , 'link cli') ; // Link the CLI package to the top-level node_modules
26+ await execPromise ( 'npm link' , { cwd : path . resolve ( projectRoot , ' ../../ cli') } ) ;
2727 } , millisPerSecond * 20 ) ;
2828
2929 afterAll ( async ( ) => {
@@ -32,46 +32,42 @@ describe('CLI Integration Tests', () => {
3232 }
3333 } , millisPerSecond * 20 ) ;
3434
35- test ( 'shows help if no arguments provided' , ( done ) => {
35+ test ( 'shows help if no arguments provided' , async ( ) => {
3636 const noArgCommand = 'calm' ;
3737 exec ( noArgCommand , ( error , _stdout , stderr ) => {
3838 expect ( error ) . not . toBeNull ( ) ;
3939 expect ( stderr ) . toContain ( 'A set of tools for interacting with the Common Architecture Language Model' ) ;
4040 expect ( stderr ) . toContain ( 'Usage:' ) ;
41- done ( ) ;
4241 } ) ;
4342 } ) ;
4443
45- test ( 'shows help if -h provided' , ( done ) => {
44+ test ( 'shows help if -h provided' , async ( ) => {
4645 const helpShortFlagCommand = 'calm -h' ;
4746 exec ( helpShortFlagCommand , ( _error , stdout , _stderr ) => {
4847 expect ( stdout ) . toContain ( 'A set of tools for interacting with the Common Architecture Language Model' ) ;
4948 expect ( stdout ) . toContain ( 'Usage:' ) ;
50- done ( ) ;
5149 } ) ;
5250 } ) ;
5351
54- test ( 'shows help if --help provided' , ( done ) => {
52+ test ( 'shows help if --help provided' , async ( ) => {
5553 const helpLongFlagCommand = 'calm --help' ;
5654 exec ( helpLongFlagCommand , ( _error , stdout , _stderr ) => {
5755 expect ( stdout ) . toContain ( 'A set of tools for interacting with the Common Architecture Language Model' ) ;
5856 expect ( stdout ) . toContain ( 'Usage:' ) ;
59- done ( ) ;
6057 } ) ;
6158 } ) ;
6259
63- test ( 'example validate command - outputting JSON to stdout' , ( done ) => {
60+ test ( 'example validate command - outputting JSON to stdout' , async ( ) => {
6461 const exampleValidateCommand = 'calm validate -p ../calm/pattern/api-gateway.json -a ../calm/samples/api-gateway-architecture.json' ;
6562 exec ( exampleValidateCommand , ( _error , stdout , _stderr ) => {
6663 const parsedOutput = JSON . parse ( stdout ) ;
6764 const expectedFilePath = path . join ( __dirname , '../test_fixtures/validate_output.json' ) ;
6865 const expectedJson = JSON . parse ( fs . readFileSync ( expectedFilePath , 'utf-8' ) ) ;
6966 expect ( parsedOutput ) . toEqual ( expectedJson ) ;
70- done ( ) ;
7167 } ) ;
7268 } ) ;
7369
74- test ( 'example validate command - outputting JSON to file' , ( done ) => {
70+ test ( 'example validate command - outputting JSON to file' , async ( ) => {
7571 const targetOutputFile = path . join ( tempDir , 'validate-output.json' ) ;
7672 const exampleValidateCommand = `calm validate -p ../calm/pattern/api-gateway.json -a ../calm/samples/api-gateway-architecture.json -o ${ targetOutputFile } ` ;
7773 exec ( exampleValidateCommand , ( _error , _stdout , _stderr ) => {
@@ -84,12 +80,10 @@ describe('CLI Integration Tests', () => {
8480 const expectedJson = JSON . parse ( fs . readFileSync ( expectedFilePath , 'utf-8' ) ) ;
8581
8682 expect ( parsedOutput ) . toEqual ( expectedJson ) ;
87-
88- done ( ) ;
8983 } ) ;
9084 } ) ;
9185
92- test ( 'example validate command - outputting JUNIT to stdout' , ( done ) => {
86+ test ( 'example validate command - outputting JUNIT to stdout' , async ( ) => {
9387 const exampleValidateCommand = 'calm validate -p ../calm/pattern/api-gateway.json -a ../calm/samples/api-gateway-architecture.json -f junit' ;
9488 exec ( exampleValidateCommand , async ( _error , stdout , _stderr ) => {
9589 const parsedOutput = await parseStringPromise ( stdout ) ;
@@ -99,11 +93,10 @@ describe('CLI Integration Tests', () => {
9993 const expectedXml = await parseStringPromise ( expectedXmlString ) ;
10094
10195 expect ( parsedOutput ) . toEqual ( expectedXml ) ;
102- done ( ) ;
10396 } ) ;
10497 } ) ;
10598
106- test ( 'example validate command - outputting JUNIT to file' , ( done ) => {
99+ test ( 'example validate command - outputting JUNIT to file' , async ( ) => {
107100 const targetOutputFile = path . join ( tempDir , 'validate-output.xml' ) ;
108101 const exampleValidateCommand = `calm validate -p ../calm/pattern/api-gateway.json -a ../calm/samples/api-gateway-architecture.json -f junit -o ${ targetOutputFile } ` ;
109102 exec ( exampleValidateCommand , async ( _error , _stdout , _stderr ) => {
@@ -117,13 +110,11 @@ describe('CLI Integration Tests', () => {
117110 const expectedXml = await parseStringPromise ( expectedXmlString ) ;
118111
119112 expect ( parsedOutput ) . toEqual ( expectedXml ) ;
120-
121- done ( ) ;
122113 } ) ;
123114 } ) ;
124115
125116
126- test ( 'example generate command - does it give the output we expect' , ( done ) => {
117+ test ( 'example generate command - does it give the output we expect' , async ( ) => {
127118 const targetOutputFile = path . join ( tempDir , 'generate-output.json' ) ;
128119 const exampleGenerateCommand = `calm generate -p ../calm/pattern/api-gateway.json -o ${ targetOutputFile } ` ;
129120 exec ( exampleGenerateCommand , async ( _error , _stdout , _stderr ) => {
@@ -136,23 +127,20 @@ describe('CLI Integration Tests', () => {
136127 const expectedJson = JSON . parse ( fs . readFileSync ( expectedFilePath , 'utf-8' ) ) ;
137128
138129 expect ( parsedOutput ) . toEqual ( expectedJson ) ;
139-
140- done ( ) ;
141130 } ) ;
142131 } ) ;
143132
144- test ( 'example validate command - outputting PRETTY to stdout' , ( done ) => {
133+ test ( 'example validate command - outputting PRETTY to stdout' , async ( ) => {
145134 const exampleValidateCommand = 'calm validate -p ../calm/pattern/api-gateway.json -a ../calm/samples/api-gateway-architecture.json -f pretty' ;
146135 exec ( exampleValidateCommand , ( _error , stdout , _stderr ) => {
147136 const expectedFilePath = path . join ( __dirname , '../test_fixtures/validate_output_pretty.txt' ) ;
148137 const expectedOutput = fs . readFileSync ( expectedFilePath , 'utf-8' ) ;
149138 //Some minor replacement logic to avoid issues with line endings
150139 expect ( stdout . replace ( / \r \n / g, '\n' ) ) . toEqual ( expectedOutput . replace ( / \r \n / g, '\n' ) ) ;
151- done ( ) ;
152140 } ) ;
153141 } ) ;
154142
155- test ( 'example validate command - outputting PRETTY to file' , ( done ) => {
143+ test ( 'example validate command - outputting PRETTY to file' , async ( ) => {
156144 const targetOutputFile = path . join ( tempDir , 'validate-output-pretty.txt' ) ;
157145 const exampleValidateCommand = `calm validate -p ../calm/pattern/api-gateway.json -a ../calm/samples/api-gateway-architecture.json -f pretty -o ${ targetOutputFile } ` ;
158146 exec ( exampleValidateCommand , ( _error , _stdout , _stderr ) => {
@@ -164,34 +152,31 @@ describe('CLI Integration Tests', () => {
164152
165153 //Some minor replacement logic to avoid issues with line endings
166154 expect ( outputString . replace ( / \r \n / g, '\n' ) ) . toEqual ( expectedOutput . replace ( / \r \n / g, '\n' ) ) ;
167- done ( ) ;
168155 } ) ;
169156 } ) ;
170157
171- test ( 'example validate command - fails when neither an architecture or a pattern is provided' , ( done ) => {
158+ test ( 'example validate command - fails when neither an architecture or a pattern is provided' , async ( ) => {
172159 const calmValidateCommand = 'calm validate' ;
173160 exec ( calmValidateCommand , ( error , _stdout , stderr ) => {
174161 expect ( error ) . not . toBeNull ( ) ;
175162 expect ( stderr ) . toContain ( 'error: one of the required options \'-p, --pattern <file>\' or \'-a, --architecture <file>\' was not specified' ) ;
176- done ( ) ;
177163 } ) ;
178164 } ) ;
179165
180- test ( 'example validate command - validates an architecture only' , ( done ) => {
166+ test ( 'example validate command - validates an architecture only' , async ( ) => {
181167 const calmValidateArchitectureOnlyCommand = 'calm validate -a ../calm/samples/api-gateway-architecture.json' ;
182168 exec ( calmValidateArchitectureOnlyCommand , ( error , stdout , _stderr ) => {
183169 const expectedFilePath = path . join ( __dirname , '../test_fixtures/validate_architecture_only_output.json' ) ;
184170 const expectedOutput = fs . readFileSync ( expectedFilePath , 'utf-8' ) ;
185171 expect ( error ) . toBeNull ( ) ;
186172 expect ( stdout ) . toContain ( expectedOutput ) ;
187- done ( ) ;
188173 } ) ;
189174 } ) ;
190175
191176 test ( 'example server command - starts server and responds to requests' , async ( ) => {
192177 // Mock the axios response
193178 const mockResponse = { status : 200 , data : { status : 'ok' } } ;
194- ( axios . get as jest . Mock ) . mockResolvedValue ( mockResponse ) ;
179+ ( axios . get as vi . Mock ) . mockResolvedValue ( mockResponse ) ;
195180
196181 const serverCommand = 'calm server -p 3001 --schemaDirectory ../../dist/calm/' ;
197182 const serverProcess = exec ( serverCommand ) ;
@@ -217,22 +202,21 @@ describe('CLI Integration Tests', () => {
217202 const outputFile = path . join ( outputDir , 'cli-e2e-output.html' ) ;
218203
219204 const templateCommand = `calm template --input ${ testModelPath } --bundle ${ templateBundlePath } --output ${ outputDir } --url-to-local-file-mapping ${ localDirectory } ` ;
220- await execPromise ( templateCommand ) ;
205+ exec ( templateCommand , ( _stderr ) => {
221206
222- await new Promise ( resolve => setTimeout ( resolve , 2 * millisPerSecond ) ) ;
207+ expect ( fs . existsSync ( outputFile ) ) . toBe ( true ) ;
223208
224- expect ( fs . existsSync ( outputFile ) ) . toBe ( true ) ;
209+ if ( fs . existsSync ( outputFile ) ) {
210+ const actualContent = fs . readFileSync ( outputFile , 'utf8' ) . trim ( ) ;
211+ const expectedContent = fs . readFileSync ( expectedOutput , 'utf8' ) . trim ( ) ;
225212
226- if ( fs . existsSync ( outputFile ) ) {
227- const actualContent = fs . readFileSync ( outputFile , 'utf8' ) . trim ( ) ;
228- const expectedContent = fs . readFileSync ( expectedOutput , 'utf8' ) . trim ( ) ;
213+ expect ( actualContent ) . toEqual ( expectedContent ) ;
229214
230- expect ( actualContent ) . toEqual ( expectedContent ) ;
231-
232- if ( fs . existsSync ( outputDir ) ) {
233- fs . rmSync ( outputDir , { recursive : true , force : true } ) ;
215+ if ( fs . existsSync ( outputDir ) ) {
216+ fs . rmSync ( outputDir , { recursive : true , force : true } ) ;
217+ }
234218 }
235- }
219+ } ) ;
236220 } ) ;
237221
238222 test ( 'example docify command - generates expected output' , async ( ) => {
@@ -252,13 +236,12 @@ describe('CLI Integration Tests', () => {
252236
253237 try {
254238 const templateCommand = `calm docify --input ${ testModelPath } --output ${ outputDir } --url-to-local-file-mapping ${ localDirectory } ` ;
255- await execPromise ( templateCommand ) ;
256-
257- await new Promise ( resolve => setTimeout ( resolve , 2 * 1000 ) ) ;
239+ exec ( templateCommand , ( _stderr ) => {
258240
259- for ( const file of expectedFiles ) {
260- expect ( fs . existsSync ( file ) ) . toBeTruthy ( ) ;
261- }
241+ for ( const file of expectedFiles ) {
242+ expect ( fs . existsSync ( file ) ) . toBeTruthy ( ) ;
243+ }
244+ } ) ;
262245 } finally {
263246 if ( fs . existsSync ( outputDir ) ) {
264247 fs . rmSync ( outputDir , { recursive : true , force : true } ) ;
@@ -268,7 +251,3 @@ describe('CLI Integration Tests', () => {
268251
269252
270253} ) ;
271-
272- async function callNpxFunction ( projectRoot : string , command : string ) {
273- await execPromise ( `npx ${ command } ` , { cwd : projectRoot } ) ;
274- }
0 commit comments