1+ import { existsSync , readFileSync } from "node:fs" ;
2+ import { cp , mkdir , readFile , writeFile } from "node:fs/promises" ;
3+ import path from "node:path" ;
14import type { Writable } from "node:stream" ;
25import { Readable } from "node:stream" ;
3- import path from "node:path" ;
46import url from "node:url" ;
5- import fse from "fs-extra" ;
67import express from "express" ;
78import getPort from "get-port" ;
89import stripIndent from "strip-indent" ;
@@ -51,7 +52,7 @@ export async function createFixture(init: FixtureInit, mode?: ServerMode) {
5152 ) . href ;
5253
5354 let getBrowserAsset = async ( asset : string ) => {
54- return fse . readFile (
55+ return readFile (
5556 path . join ( projectDir , "public" , asset . replace ( / ^ \/ / , "" ) ) ,
5657 "utf8"
5758 ) ;
@@ -64,7 +65,7 @@ export async function createFixture(init: FixtureInit, mode?: ServerMode) {
6465 isSpaMode : init . spaMode ,
6566 prerender : init . prerender ,
6667 requestDocument ( ) {
67- let html = fse . readFileSync (
68+ let html = readFileSync (
6869 path . join ( projectDir , "build/client/index.html" )
6970 ) ;
7071 return new Response ( html , {
@@ -102,25 +103,21 @@ export async function createFixture(init: FixtureInit, mode?: ServerMode) {
102103 "client" ,
103104 "__spa-fallback.html"
104105 ) ;
105- let html = fse . existsSync ( mainPath )
106- ? fse . readFileSync ( mainPath )
107- : fse . readFileSync ( fallbackPath ) ;
106+ let html = existsSync ( mainPath )
107+ ? readFileSync ( mainPath )
108+ : readFileSync ( fallbackPath ) ;
108109 return new Response ( html , {
109110 headers : {
110111 "Content-Type" : "text/html" ,
111112 } ,
112113 } ) ;
113114 } ,
114115 requestResource ( href : string ) {
115- let data = fse . readFileSync (
116- path . join ( projectDir , "build/client" , href )
117- ) ;
116+ let data = readFileSync ( path . join ( projectDir , "build/client" , href ) ) ;
118117 return new Response ( data ) ;
119118 } ,
120119 async requestSingleFetchData ( href : string ) {
121- let data = fse . readFileSync (
122- path . join ( projectDir , "build/client" , href )
123- ) ;
120+ let data = readFileSync ( path . join ( projectDir , "build/client" , href ) ) ;
124121 let stream = createReadableStreamFromReadable ( Readable . from ( data ) ) ;
125122 return {
126123 status : 200 ,
@@ -280,7 +277,7 @@ export async function createAppFixture(fixture: Fixture, mode?: ServerMode) {
280277 let port = await getPort ( ) ;
281278 let app = express ( ) ;
282279 app . use ( express . static ( path . join ( fixture . projectDir , "build/client" ) ) ) ;
283- app . get ( "*" , ( _ , res , next ) =>
280+ app . get ( "*" , ( _ , res ) =>
284281 res . sendFile ( path . join ( fixture . projectDir , "build/client/index.html" ) )
285282 ) ;
286283 let server = app . listen ( port ) ;
@@ -300,11 +297,11 @@ export async function createAppFixture(fixture: Fixture, mode?: ServerMode) {
300297 let file = req . path . endsWith ( ".data" )
301298 ? req . path
302299 : req . path + "/index.html" ;
303- if ( file . endsWith ( ".html" ) && ! fse . existsSync ( path . join ( dir , file ) ) ) {
300+ if ( file . endsWith ( ".html" ) && ! existsSync ( path . join ( dir , file ) ) ) {
304301 file = "__spa-fallback.html" ;
305302 }
306303 let filePath = path . join ( dir , file ) ;
307- if ( fse . existsSync ( filePath ) ) {
304+ if ( existsSync ( filePath ) ) {
308305 res . sendFile ( filePath , next ) ;
309306 } else {
310307 // Avoid a built-in console error from `sendFile` on 404's
@@ -375,8 +372,8 @@ export async function createFixtureProject(
375372 let projectDir = path . join ( TMP_DIR , projectName ) ;
376373 let port = init . port ?? ( await getPort ( ) ) ;
377374
378- await fse . ensureDir ( projectDir ) ;
379- await fse . copy ( integrationTemplateDir , projectDir ) ;
375+ await mkdir ( projectDir , { recursive : true } ) ;
376+ await cp ( integrationTemplateDir , projectDir , { recursive : true } ) ;
380377
381378 let hasViteConfig = Object . keys ( init . files ?? { } ) . some ( ( filename ) =>
382379 filename . startsWith ( "vite.config." )
@@ -463,10 +460,10 @@ async function writeTestFiles(
463460 await Promise . all (
464461 Object . keys ( files ?? { } ) . map ( async ( filename ) => {
465462 let filePath = path . join ( dir , filename ) ;
466- await fse . ensureDir ( path . dirname ( filePath ) ) ;
463+ await mkdir ( path . dirname ( filePath ) , { recursive : true } ) ;
467464 let file = files ! [ filename ] ;
468465
469- await fse . writeFile ( filePath , stripIndent ( file ) ) ;
466+ await writeFile ( filePath , stripIndent ( file ) ) ;
470467 } )
471468 ) ;
472469}
0 commit comments