1
1
import { join } from 'node:path'
2
2
import type { ExecaSyncReturnValue , SyncOptions } from 'execa'
3
3
import { execaCommandSync } from 'execa'
4
- import { mkdirpSync , readdirSync , remove , writeFileSync } from 'fs-extra'
4
+ import fs from 'fs-extra'
5
5
import { afterEach , beforeAll , expect , test } from 'vitest'
6
6
7
7
const CLI_PATH = join ( __dirname , '..' )
@@ -19,29 +19,30 @@ const run = (
19
19
// Helper to create a non-empty directory
20
20
const createNonEmptyDir = ( ) => {
21
21
// Create the temporary directory
22
- mkdirpSync ( genPath )
22
+ fs . mkdirpSync ( genPath )
23
23
24
24
// Create a package.json file
25
25
const pkgJson = join ( genPath , 'package.json' )
26
- writeFileSync ( pkgJson , '{ "foo": "bar" }' )
26
+ fs . writeFileSync ( pkgJson , '{ "foo": "bar" }' )
27
27
}
28
28
29
29
// Vue 3 starter template
30
- const templateFiles = readdirSync ( join ( CLI_PATH , 'template-vue' ) )
30
+ const templateFiles = fs
31
+ . readdirSync ( join ( CLI_PATH , 'template-vue' ) )
31
32
// _gitignore is renamed to .gitignore
32
33
. map ( ( filePath ) => ( filePath === '_gitignore' ? '.gitignore' : filePath ) )
33
34
. sort ( )
34
35
35
- beforeAll ( ( ) => remove ( genPath ) )
36
- afterEach ( ( ) => remove ( genPath ) )
36
+ beforeAll ( ( ) => fs . remove ( genPath ) )
37
+ afterEach ( ( ) => fs . remove ( genPath ) )
37
38
38
39
test ( 'prompts for the project name if none supplied' , ( ) => {
39
40
const { stdout } = run ( [ ] )
40
41
expect ( stdout ) . toContain ( 'Project name:' )
41
42
} )
42
43
43
44
test ( 'prompts for the framework if none supplied when target dir is current directory' , ( ) => {
44
- mkdirpSync ( genPath )
45
+ fs . mkdirpSync ( genPath )
45
46
const { stdout } = run ( [ '.' ] , { cwd : genPath } )
46
47
expect ( stdout ) . toContain ( 'Select a framework:' )
47
48
} )
@@ -79,7 +80,7 @@ test('successfully scaffolds a project based on vue starter template', () => {
79
80
const { stdout } = run ( [ projectName , '--template' , 'vue' ] , {
80
81
cwd : __dirname ,
81
82
} )
82
- const generatedFiles = readdirSync ( genPath ) . sort ( )
83
+ const generatedFiles = fs . readdirSync ( genPath ) . sort ( )
83
84
84
85
// Assertions
85
86
expect ( stdout ) . toContain ( `Scaffolding project in ${ genPath } ` )
@@ -90,7 +91,7 @@ test('works with the -t alias', () => {
90
91
const { stdout } = run ( [ projectName , '-t' , 'vue' ] , {
91
92
cwd : __dirname ,
92
93
} )
93
- const generatedFiles = readdirSync ( genPath ) . sort ( )
94
+ const generatedFiles = fs . readdirSync ( genPath ) . sort ( )
94
95
95
96
// Assertions
96
97
expect ( stdout ) . toContain ( `Scaffolding project in ${ genPath } ` )
0 commit comments