@@ -51,6 +51,38 @@ export async function createFixture(init: FixtureInit, mode?: ServerMode) {
51
51
compiler === "vite" ? "build/server/index.js" : "build/index.js"
52
52
)
53
53
) . href ;
54
+
55
+ let getBrowserAsset = async ( asset : string ) => {
56
+ return fse . readFile (
57
+ path . join ( projectDir , "public" , asset . replace ( / ^ \/ / , "" ) ) ,
58
+ "utf8"
59
+ ) ;
60
+ } ;
61
+
62
+ let isSpaMode =
63
+ compiler === "vite" &&
64
+ fse . existsSync ( path . join ( projectDir , "build/client/index.html" ) ) ;
65
+
66
+ if ( isSpaMode ) {
67
+ return {
68
+ projectDir,
69
+ build : null ,
70
+ isSpaMode,
71
+ compiler,
72
+ requestDocument : ( ) => {
73
+ throw new Error ( "Cannot requestDocument in SPA Mode tests" ) ;
74
+ } ,
75
+ requestData : ( ) => {
76
+ throw new Error ( "Cannot requestData in SPA Mode tests" ) ;
77
+ } ,
78
+ postDocument : ( ) => {
79
+ throw new Error ( "Cannot postDocument in SPA Mode tests" ) ;
80
+ } ,
81
+ getBrowserAsset,
82
+ useRemixServe : init . useRemixServe ,
83
+ } ;
84
+ }
85
+
54
86
let app : ServerBuild = await import ( buildPath ) ;
55
87
let handler = createRequestHandler ( app , mode || ServerMode . Production ) ;
56
88
@@ -89,16 +121,10 @@ export async function createFixture(init: FixtureInit, mode?: ServerMode) {
89
121
} ) ;
90
122
} ;
91
123
92
- let getBrowserAsset = async ( asset : string ) => {
93
- return fse . readFile (
94
- path . join ( projectDir , "public" , asset . replace ( / ^ \/ / , "" ) ) ,
95
- "utf8"
96
- ) ;
97
- } ;
98
-
99
124
return {
100
125
projectDir,
101
126
build : app ,
127
+ isSpaMode,
102
128
compiler,
103
129
requestDocument,
104
130
requestData,
@@ -175,6 +201,22 @@ export async function createAppFixture(fixture: Fixture, mode?: ServerMode) {
175
201
} ) ;
176
202
}
177
203
204
+ if ( fixture . isSpaMode ) {
205
+ return new Promise ( async ( accept ) => {
206
+ let port = await getPort ( ) ;
207
+ let app = express ( ) ;
208
+ app . use ( express . static ( path . join ( fixture . projectDir , "build/client" ) ) ) ;
209
+ app . get ( "*" , ( _ , res , next ) =>
210
+ res . sendFile (
211
+ path . join ( process . cwd ( ) , "build/client/index.html" ) ,
212
+ next
213
+ )
214
+ ) ;
215
+ let server = app . listen ( port ) ;
216
+ accept ( { stop : server . close . bind ( server ) , port } ) ;
217
+ } ) ;
218
+ }
219
+
178
220
return new Promise ( async ( accept ) => {
179
221
let port = await getPort ( ) ;
180
222
let app = express ( ) ;
@@ -281,7 +323,7 @@ export async function createFixtureProject(
281
323
at the same time, unless the \`remix.config.js\` file contains a reference
282
324
to the \`global.INJECTED_FIXTURE_REMIX_CONFIG\` placeholder so it can
283
325
accept the injected config values. Either move all config values into
284
- \`remix.config.js\` file, or spread the injected config,
326
+ \`remix.config.js\` file, or spread the injected config,
285
327
e.g. \`export default { ...global.INJECTED_FIXTURE_REMIX_CONFIG }\`.
286
328
` ) ;
287
329
}
0 commit comments