1
+ import { existsSync , readFileSync } from "node:fs" ;
2
+ import { cp , mkdir , readFile , writeFile } from "node:fs/promises" ;
3
+ import path from "node:path" ;
1
4
import type { Writable } from "node:stream" ;
2
5
import { Readable } from "node:stream" ;
3
- import path from "node:path" ;
4
6
import url from "node:url" ;
5
- import fse from "fs-extra" ;
6
7
import express from "express" ;
7
8
import getPort from "get-port" ;
8
9
import stripIndent from "strip-indent" ;
@@ -51,7 +52,7 @@ export async function createFixture(init: FixtureInit, mode?: ServerMode) {
51
52
) . href ;
52
53
53
54
let getBrowserAsset = async ( asset : string ) => {
54
- return fse . readFile (
55
+ return readFile (
55
56
path . join ( projectDir , "public" , asset . replace ( / ^ \/ / , "" ) ) ,
56
57
"utf8"
57
58
) ;
@@ -64,7 +65,7 @@ export async function createFixture(init: FixtureInit, mode?: ServerMode) {
64
65
isSpaMode : init . spaMode ,
65
66
prerender : init . prerender ,
66
67
requestDocument ( ) {
67
- let html = fse . readFileSync (
68
+ let html = readFileSync (
68
69
path . join ( projectDir , "build/client/index.html" )
69
70
) ;
70
71
return new Response ( html , {
@@ -102,25 +103,21 @@ export async function createFixture(init: FixtureInit, mode?: ServerMode) {
102
103
"client" ,
103
104
"__spa-fallback.html"
104
105
) ;
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 ) ;
108
109
return new Response ( html , {
109
110
headers : {
110
111
"Content-Type" : "text/html" ,
111
112
} ,
112
113
} ) ;
113
114
} ,
114
115
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 ) ) ;
118
117
return new Response ( data ) ;
119
118
} ,
120
119
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 ) ) ;
124
121
let stream = createReadableStreamFromReadable ( Readable . from ( data ) ) ;
125
122
return {
126
123
status : 200 ,
@@ -280,7 +277,7 @@ export async function createAppFixture(fixture: Fixture, mode?: ServerMode) {
280
277
let port = await getPort ( ) ;
281
278
let app = express ( ) ;
282
279
app . use ( express . static ( path . join ( fixture . projectDir , "build/client" ) ) ) ;
283
- app . get ( "*" , ( _ , res , next ) =>
280
+ app . get ( "*" , ( _ , res ) =>
284
281
res . sendFile ( path . join ( fixture . projectDir , "build/client/index.html" ) )
285
282
) ;
286
283
let server = app . listen ( port ) ;
@@ -300,11 +297,11 @@ export async function createAppFixture(fixture: Fixture, mode?: ServerMode) {
300
297
let file = req . path . endsWith ( ".data" )
301
298
? req . path
302
299
: 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 ) ) ) {
304
301
file = "__spa-fallback.html" ;
305
302
}
306
303
let filePath = path . join ( dir , file ) ;
307
- if ( fse . existsSync ( filePath ) ) {
304
+ if ( existsSync ( filePath ) ) {
308
305
res . sendFile ( filePath , next ) ;
309
306
} else {
310
307
// Avoid a built-in console error from `sendFile` on 404's
@@ -375,8 +372,8 @@ export async function createFixtureProject(
375
372
let projectDir = path . join ( TMP_DIR , projectName ) ;
376
373
let port = init . port ?? ( await getPort ( ) ) ;
377
374
378
- await fse . ensureDir ( projectDir ) ;
379
- await fse . copy ( integrationTemplateDir , projectDir ) ;
375
+ await mkdir ( projectDir , { recursive : true } ) ;
376
+ await cp ( integrationTemplateDir , projectDir , { recursive : true } ) ;
380
377
381
378
let hasViteConfig = Object . keys ( init . files ?? { } ) . some ( ( filename ) =>
382
379
filename . startsWith ( "vite.config." )
@@ -463,10 +460,10 @@ async function writeTestFiles(
463
460
await Promise . all (
464
461
Object . keys ( files ?? { } ) . map ( async ( filename ) => {
465
462
let filePath = path . join ( dir , filename ) ;
466
- await fse . ensureDir ( path . dirname ( filePath ) ) ;
463
+ await mkdir ( path . dirname ( filePath ) , { recursive : true } ) ;
467
464
let file = files ! [ filename ] ;
468
465
469
- await fse . writeFile ( filePath , stripIndent ( file ) ) ;
466
+ await writeFile ( filePath , stripIndent ( file ) ) ;
470
467
} )
471
468
) ;
472
469
}
0 commit comments