|
| 1 | +import assert from 'node:assert'; |
| 2 | +import { |
| 3 | + execAndWaitForOutputToMatch, |
| 4 | + ng, |
| 5 | + silentNg, |
| 6 | + waitForAnyProcessOutputToMatch, |
| 7 | +} from '../../utils/process'; |
| 8 | +import { installWorkspacePackages, uninstallPackage } from '../../utils/packages'; |
| 9 | +import { useSha } from '../../utils/project'; |
| 10 | +import { getGlobalVariable } from '../../utils/env'; |
| 11 | +import { findFreePort } from '../../utils/network'; |
| 12 | +import { writeFile } from '../../utils/fs'; |
| 13 | + |
| 14 | +export default async function () { |
| 15 | + assert( |
| 16 | + getGlobalVariable('argv')['esbuild'], |
| 17 | + 'This test should not be called in the Webpack suite.', |
| 18 | + ); |
| 19 | + |
| 20 | + // Forcibly remove in case another test doesn't clean itself up. |
| 21 | + await uninstallPackage('@angular/ssr'); |
| 22 | + await ng('add', '@angular/ssr', '--no-server-routing', '--skip-confirmation', '--skip-install'); |
| 23 | + await useSha(); |
| 24 | + await installWorkspacePackages(); |
| 25 | + |
| 26 | + await silentNg('generate', 'component', 'home'); |
| 27 | + await writeFile( |
| 28 | + 'src/app/app.routes.ts', |
| 29 | + ` |
| 30 | + import { Routes } from '@angular/router'; |
| 31 | + import {HomeComponent} from './home/home.component'; |
| 32 | +
|
| 33 | + export const routes: Routes = [{ |
| 34 | + path: 'sub/home', |
| 35 | + component: HomeComponent |
| 36 | + }]; |
| 37 | + `, |
| 38 | + ); |
| 39 | + |
| 40 | + const port = await findFreePort(); |
| 41 | + await execAndWaitForOutputToMatch('ng', ['serve', '--port', `${port}`], /complete/, { |
| 42 | + NO_COLOR: 'true', |
| 43 | + }); |
| 44 | + |
| 45 | + const [, response] = await Promise.all([ |
| 46 | + assert.rejects( |
| 47 | + waitForAnyProcessOutputToMatch(/Pre-transform error: Failed to load url/, 8_000), |
| 48 | + ), |
| 49 | + fetch(`http://localhost:${port}/sub/home`), |
| 50 | + ]); |
| 51 | + |
| 52 | + assert(response.ok, `Expected 'response.ok' to be 'true'.`); |
| 53 | +} |
0 commit comments