forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add end-to-end tests for SSR setup
This commit introduces end-to-end (e2e) tests to validate the server-side rendering (SSR) setup.
- Loading branch information
1 parent
148af6e
commit f1dc11b
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import assert from 'node:assert'; | ||
import { ng } from '../../utils/process'; | ||
import { installWorkspacePackages, uninstallPackage } from '../../utils/packages'; | ||
import { ngServe, useSha } from '../../utils/project'; | ||
import { getGlobalVariable } from '../../utils/env'; | ||
|
||
export default async function () { | ||
assert( | ||
getGlobalVariable('argv')['esbuild'], | ||
'This test should not be called in the Webpack suite.', | ||
); | ||
|
||
// Enable caching to test real development workflow. | ||
await ng('cache', 'clean'); | ||
await ng('cache', 'on'); | ||
|
||
// Forcibly remove in case another test doesn't clean itself up. | ||
await uninstallPackage('@angular/ssr'); | ||
await ng('add', '@angular/ssr', '--server-routing', '--skip-confirmation', '--skip-install'); | ||
await useSha(); | ||
await installWorkspacePackages(); | ||
|
||
const port = await ngServe(); | ||
|
||
// Verify the server is running and the API response is correct. | ||
await validateResponse('/main.js', /bootstrapApplication/); | ||
await validateResponse('', /Hello,/); | ||
await validateResponse('/invalid', /Cannot GET \/invalid/, 404); | ||
|
||
async function validateResponse(pathname: string, match: RegExp, status = 200): Promise<void> { | ||
const response = await fetch(new URL(pathname, `http://localhost:${port}`)); | ||
const text = await response.text(); | ||
assert.match(text, match); | ||
assert.equal(response.status, status); | ||
} | ||
} |