|
| 1 | +import assert from 'node:assert'; |
| 2 | +import { ng } from '../../utils/process'; |
| 3 | +import { installWorkspacePackages, uninstallPackage } from '../../utils/packages'; |
| 4 | +import { ngServe, useSha } from '../../utils/project'; |
| 5 | +import { getGlobalVariable } from '../../utils/env'; |
| 6 | + |
| 7 | +export default async function () { |
| 8 | + assert( |
| 9 | + getGlobalVariable('argv')['esbuild'], |
| 10 | + 'This test should not be called in the Webpack suite.', |
| 11 | + ); |
| 12 | + |
| 13 | + // Enable caching to test real development workflow. |
| 14 | + await ng('cache', 'clean'); |
| 15 | + await ng('cache', 'on'); |
| 16 | + |
| 17 | + // Forcibly remove in case another test doesn't clean itself up. |
| 18 | + await uninstallPackage('@angular/ssr'); |
| 19 | + await ng('add', '@angular/ssr', '--server-routing', '--skip-confirmation', '--skip-install'); |
| 20 | + await useSha(); |
| 21 | + await installWorkspacePackages(); |
| 22 | + |
| 23 | + const port = await ngServe(); |
| 24 | + |
| 25 | + // Verify the server is running and the API response is correct. |
| 26 | + await validateResponse('/main.js', /bootstrapApplication/); |
| 27 | + await validateResponse('/', /Hello,/); |
| 28 | + await validateResponse('/unknown', /Cannot GET/, 404); |
| 29 | + |
| 30 | + async function validateResponse(pathname: string, match: RegExp, status = 200): Promise<void> { |
| 31 | + const response = await fetch(new URL(pathname, `http://localhost:${port}`)); |
| 32 | + const text = await response.text(); |
| 33 | + assert.match(text, match); |
| 34 | + assert.equal(response.status, status); |
| 35 | + } |
| 36 | +} |
0 commit comments