1- import { promises , readFileSync , existsSync } from 'fs'
1+ import { readFileSync , existsSync } from 'fs'
2+ import { mkdir } from 'fs/promises'
23import { platform } from 'os'
34import { join , resolve } from 'path'
45import { env } from 'process'
56import { fileURLToPath } from 'url'
67
7- import test from 'ava'
88import execa from 'execa'
9+ import { expect , test } from 'vitest'
910
1011import { packageManagerConfig , packageManagerExists } from './utils.mjs'
1112
1213const { version } = JSON . parse ( readFileSync ( fileURLToPath ( new URL ( '../package.json' , import . meta. url ) ) , 'utf-8' ) )
13- const { mkdir } = promises
1414
1515/**
1616 * Prepares the workspace for the test suite to run
@@ -23,28 +23,22 @@ const prepare = async (folderName) => {
2323}
2424
2525Object . entries ( packageManagerConfig ) . forEach ( ( [ packageManager , { install : installCmd , lockFile } ] ) => {
26- /** @type {import('ava').TestInterface } */
27- const testSuite = packageManagerExists ( packageManager ) ? test . serial : test . skip
28-
29- testSuite ( `${ packageManager } → should install the cli and run the help command` , async ( t ) => {
30- const cwd = await prepare ( `${ packageManager } -try-install` )
31- await execa ( ...installCmd , { stdio : env . DEBUG ? 'inherit' : 'ignore' , cwd } )
32-
33- t . is ( existsSync ( join ( cwd , lockFile ) ) , true , `Generated lock file ${ lockFile } does not exists in ${ cwd } ` )
34-
35- const binary = resolve ( join ( cwd , `./node_modules/.bin/netlify${ platform ( ) === 'win32' ? '.cmd' : '' } ` ) )
36- const { stdout } = await execa ( binary , [ 'help' ] , { cwd } )
37-
38- t . is ( stdout . trim ( ) . startsWith ( 'VERSION' ) , true , `Help command does not start with 'VERSION':\n\n${ stdout } ` )
39- t . is (
40- stdout . includes ( `netlify-cli/${ version } ` ) ,
41- true ,
42- `Help command does not include 'netlify-cli/${ version } ':\n\n${ stdout } ` ,
43- )
44- t . is (
45- stdout . includes ( `$ netlify [COMMAND]` ) ,
46- true ,
47- `Help command does not include '$ netlify [COMMAND]':\n\n${ stdout } ` ,
48- )
49- } )
26+ test . runIf ( packageManagerExists ( packageManager ) ) (
27+ `${ packageManager } → should install the cli and run the help command` ,
28+ async ( ) => {
29+ const cwd = await prepare ( `${ packageManager } -try-install` )
30+ await execa ( ...installCmd , { stdio : env . DEBUG ? 'inherit' : 'ignore' , cwd } )
31+
32+ expect ( existsSync ( join ( cwd , lockFile ) ) , `Generated lock file ${ lockFile } does not exists in ${ cwd } ` ) . toBe ( true )
33+
34+ const binary = resolve ( join ( cwd , `./node_modules/.bin/netlify${ platform ( ) === 'win32' ? '.cmd' : '' } ` ) )
35+ const { stdout } = await execa ( binary , [ 'help' ] , { cwd } )
36+
37+ expect ( stdout . trim ( ) , `Help command does not start with 'VERSION':\n\n${ stdout } ` ) . toMatch ( / ^ V E R S I O N / )
38+ expect ( stdout , `Help command does not include 'netlify-cli/${ version } ':\n\n${ stdout } ` ) . toContain (
39+ `netlify-cli/${ version } ` ,
40+ )
41+ expect ( stdout , `Help command does not include '$ netlify [COMMAND]':\n\n${ stdout } ` ) . toMatch ( '$ netlify [COMMAND]' )
42+ } ,
43+ )
5044} )
0 commit comments