(fixture: Fixture, mode?: ServerMode)
| 282 | * It also means that sometimes the CLI is skipped over in those tests, missing out on code paths that should be tested. |
| 283 | */ |
| 284 | export async function createAppFixture(fixture: Fixture, mode?: ServerMode) { |
| 285 | let startAppServer = async (): Promise<{ |
| 286 | port: number; |
| 287 | stop: VoidFunction; |
| 288 | }> => { |
| 289 | if (fixture.useReactRouterServe) { |
| 290 | let port = await getPort(); |
| 291 | let { stop } = await spawnTestServer({ |
| 292 | cwd: fixture.projectDir, |
| 293 | command: [ |
| 294 | process.argv[0], |
| 295 | "node_modules/@react-router/serve/dist/cli.js", |
| 296 | "build/server/index.js", |
| 297 | ], |
| 298 | env: { |
| 299 | NODE_ENV: mode || "production", |
| 300 | PORT: port.toFixed(0), |
| 301 | }, |
| 302 | regex: /\[react-router-serve\] http:\/\/localhost:(\d+)\s/, |
| 303 | validate: (matches) => { |
| 304 | let parsedPort = parseInt(matches[1], 10); |
| 305 | if (port !== parsedPort) { |
| 306 | throw new Error( |
| 307 | `Expected react-router-serve to start on port ${port}, but it started on port ${parsedPort}`, |
| 308 | ); |
| 309 | } |
| 310 | }, |
| 311 | }); |
| 312 | return { stop, port }; |
| 313 | } |
| 314 | |
| 315 | if (fixture.isSpaMode) { |
| 316 | return new Promise(async (accept) => { |
| 317 | let port = await getPort(); |
| 318 | let app = express(); |
| 319 | app.use(express.static(path.join(fixture.projectDir, "build/client"))); |
| 320 | app.get("*", (_, res) => |
| 321 | res.sendFile( |
| 322 | path.join(fixture.projectDir, "build/client/index.html"), |
| 323 | ), |
| 324 | ); |
| 325 | let server = app.listen(port); |
| 326 | accept({ stop: server.close.bind(server), port }); |
| 327 | }); |
| 328 | } |
| 329 | |
| 330 | if (fixture.prerender) { |
| 331 | return new Promise(async (accept) => { |
| 332 | let port = await getPort(); |
| 333 | let app = express(); |
| 334 | app.use( |
| 335 | express.static(path.join(fixture.projectDir, "build", "client")), |
| 336 | ); |
| 337 | app.get("*", (req, res, next) => { |
| 338 | let dir = path.join(fixture.projectDir, "build", "client"); |
| 339 | let filePath; |
| 340 | if (req.path.endsWith(".data")) { |
| 341 | filePath = path.join(dir, req.path); |
no test coverage detected
searching dependent graphs…