1- import { join } from 'node:path'
1+ import fs from 'node:fs'
2+ import path from 'node:path'
23import type { ExecaSyncReturnValue , SyncOptions } from 'execa'
34import { execaCommandSync } from 'execa'
4- import fs from 'fs-extra'
55import { afterEach , beforeAll , expect , test } from 'vitest'
66
7- const CLI_PATH = join ( __dirname , '..' )
7+ const CLI_PATH = path . join ( __dirname , '..' )
88
99const projectName = 'electron-vite-app'
10- const genPath = join ( __dirname , projectName )
10+ const generatePath = path . join ( __dirname , projectName )
1111
1212const run = (
1313 args : string [ ] ,
@@ -18,24 +18,24 @@ const run = (
1818
1919const createNonEmptyDir = ( ) => {
2020 // Create the temporary directory
21- fs . mkdirpSync ( genPath )
21+ fs . mkdirSync ( generatePath , { recursive : true } )
2222
2323 // Create a package.json file
24- const pkgJson = join ( genPath , 'package.json' )
24+ const pkgJson = path . join ( generatePath , 'package.json' )
2525 fs . writeFileSync ( pkgJson , '{ "foo": "bar" }' )
2626}
2727
28- beforeAll ( ( ) => fs . remove ( genPath ) )
29- afterEach ( ( ) => fs . remove ( genPath ) )
28+ beforeAll ( ( ) => fs . rmSync ( generatePath , { recursive : true , force : true } ) )
29+ afterEach ( ( ) => fs . rmSync ( generatePath , { recursive : true , force : true } ) )
3030
3131test ( 'prompts for the project name if none supplied' , ( ) => {
3232 const { stdout } = run ( [ ] )
3333 expect ( stdout ) . toContain ( 'Project name:' )
3434} )
3535
3636test ( 'prompts for the framework if none supplied when target dir is current directory' , ( ) => {
37- fs . mkdirpSync ( genPath )
38- const { stdout } = run ( [ '.' ] , { cwd : genPath } )
37+ fs . mkdirSync ( generatePath , { recursive : true } )
38+ const { stdout } = run ( [ '.' ] , { cwd : generatePath } )
3939 expect ( stdout ) . toContain ( 'Project template:' )
4040} )
4141
@@ -52,6 +52,6 @@ test('asks to overwrite non-empty target directory', () => {
5252
5353test ( 'asks to overwrite non-empty current directory' , ( ) => {
5454 createNonEmptyDir ( )
55- const { stdout } = run ( [ '.' ] , { cwd : genPath } )
55+ const { stdout } = run ( [ '.' ] , { cwd : generatePath } )
5656 expect ( stdout ) . toContain ( `Current directory is not empty.` )
5757} )
0 commit comments