Skip to content

Commit 83b32a6

Browse files
committed
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.
1 parent a6eaf2f commit 83b32a6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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

Comments
 (0)