1- import fs from 'fs-extra'
1+ import { rmSync } from 'node:fs'
2+ import fs from 'node:fs/promises'
23import os from 'node:os'
34import path from 'node:path'
45import { glob } from 'tinyglobby'
@@ -15,15 +16,16 @@ export async function setup(): Promise<void> {
1516 args : process . env . CI ? [ '--no-sandbox' , '--disable-setuid-sandbox' ] : undefined ,
1617 } )
1718
18- await fs . mkdirp ( DIR )
19+ await fs . mkdir ( DIR , { recursive : true } )
1920 await fs . writeFile ( path . join ( DIR , 'wsEndpoint' ) , browserServer . wsEndpoint ( ) )
2021
2122 const tempDir = path . resolve ( __dirname , '../playground-temp' )
22- await fs . ensureDir ( tempDir )
23- await fs . emptyDir ( tempDir )
23+ await fs . rm ( tempDir , { force : true , recursive : true } )
24+ await fs . mkdir ( tempDir , { recursive : true } )
2425 await fs
25- . copy ( path . resolve ( __dirname , '../playground' ) , tempDir , {
26+ . cp ( path . resolve ( __dirname , '../playground' ) , tempDir , {
2627 dereference : false ,
28+ recursive : true ,
2729 filter ( file ) {
2830 const _file = file . replace ( / \\ / g, '/' )
2931 return ! _file . includes ( '__tests__' ) && ! file . match ( / d i s t ( \/ | $ ) / )
@@ -42,16 +44,16 @@ export async function setup(): Promise<void> {
4244 if ( process . env [ 'VITEST_TEST_CJS' ] ) {
4345 const packageJsons = await glob ( `${ tempDir } /**/package.json` )
4446 for ( const packageJson of packageJsons ) {
45- const packageJsonContents = await fs . readJson ( packageJson )
47+ const packageJsonContents = await fs . readFile ( packageJson , 'utf-8' ) . then ( r => JSON . parse ( r . toString ( ) ) )
4648 delete packageJsonContents [ 'module' ]
47- await fs . writeJson ( packageJson , packageJsonContents , { spaces : 2 } )
49+ await fs . writeFile ( packageJson , JSON . stringify ( packageJsonContents , null , 2 ) )
4850 }
4951 }
5052}
5153
5254export async function teardown ( ) : Promise < void > {
5355 browserServer ?. close ( )
5456 if ( ! process . env . VITE_PRESERVE_BUILD_ARTIFACTS ) {
55- fs . removeSync ( path . resolve ( __dirname , '../playground-temp' ) )
57+ rmSync ( path . resolve ( __dirname , '../playground-temp' ) , { force : true , recursive : true } )
5658 }
5759}
0 commit comments