Skip to content

Commit dd02caa

Browse files
alan-agius4angular-robot[bot]
authored andcommitted
test: add an E2E to tests standalone server build
Add an E2E to test the generated universal application.
1 parent c2f0075 commit dd02caa

File tree

2 files changed

+76
-7
lines changed

2 files changed

+76
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { normalize } from 'path';
2+
import { getGlobalVariable } from '../../../utils/env';
3+
import { expectFileToMatch, replaceInFile, writeFile } from '../../../utils/fs';
4+
import { installPackage } from '../../../utils/packages';
5+
import { exec, ng } from '../../../utils/process';
6+
import { updateJsonFile } from '../../../utils/project';
7+
8+
const snapshots = require('../../../ng-snapshot/package.json');
9+
10+
export default async function () {
11+
await ng('generate', 'application', 'test-project-two', '--standalone', '--skip-install');
12+
await ng('generate', 'universal', '--project', 'test-project-two');
13+
14+
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
15+
if (isSnapshotBuild) {
16+
const packagesToInstall: string[] = [];
17+
await updateJsonFile('package.json', (packageJson) => {
18+
const dependencies = packageJson['dependencies'];
19+
// Iterate over all of the packages to update them to the snapshot version.
20+
for (const [name, version] of Object.entries<string>(snapshots.dependencies)) {
21+
if (name in dependencies && dependencies[name] !== version) {
22+
packagesToInstall.push(version);
23+
}
24+
}
25+
});
26+
27+
for (const pkg of packagesToInstall) {
28+
await installPackage(pkg);
29+
}
30+
}
31+
32+
await writeFile(
33+
'./projects/test-project-two/server.ts',
34+
` import 'zone.js/node';
35+
import * as fs from 'fs';
36+
import { renderApplication } from '@angular/platform-server';
37+
import bootstrap from './src/main.server';
38+
39+
renderApplication(bootstrap, {
40+
url: '/',
41+
document: '<app-root></app-root>'
42+
}).then(html => {
43+
fs.writeFileSync('dist/test-project-two/server/index.html', html);
44+
})
45+
`,
46+
);
47+
48+
await replaceInFile(
49+
'./projects/test-project-two/tsconfig.server.json',
50+
'src/main.server.ts',
51+
'server.ts',
52+
);
53+
await replaceInFile('angular.json', 'src/main.server.ts', 'server.ts');
54+
55+
await ng('run', 'test-project-two:server', '--optimization', 'false');
56+
await exec(normalize('node'), 'dist/test-project-two/server/main.js');
57+
await expectFileToMatch(
58+
'dist/test-project-two/server/index.html',
59+
/<p.*>Here are some links to help you get started:<\/p>/,
60+
);
61+
62+
// works with optimization
63+
await ng('run', 'test-project-two:server', '--optimization');
64+
await exec(normalize('node'), 'dist/test-project-two/server/main.js');
65+
await expectFileToMatch(
66+
'dist/test-project-two/server/index.html',
67+
/<p.*>Here are some links to help you get started:<\/p>/,
68+
);
69+
}

tests/legacy-cli/e2e/tests/build/platform-server.ts renamed to tests/legacy-cli/e2e/tests/build/server/platform-server.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { normalize } from 'path';
2-
import { getGlobalVariable } from '../../utils/env';
3-
import { expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs';
4-
import { installPackage } from '../../utils/packages';
5-
import { exec, ng } from '../../utils/process';
6-
import { updateJsonFile } from '../../utils/project';
2+
import { getGlobalVariable } from '../../../utils/env';
3+
import { expectFileToMatch, replaceInFile, writeFile } from '../../../utils/fs';
4+
import { installPackage } from '../../../utils/packages';
5+
import { exec, ng } from '../../../utils/process';
6+
import { updateJsonFile } from '../../../utils/project';
77

8-
const snapshots = require('../../ng-snapshot/package.json');
8+
const snapshots = require('../../../ng-snapshot/package.json');
99

1010
export default async function () {
1111
await ng('generate', 'universal', '--project', 'test-project');
@@ -40,7 +40,7 @@ export default async function () {
4040
document: '<app-root></app-root>'
4141
}).then(html => {
4242
fs.writeFileSync('dist/test-project/server/index.html', html);
43-
});
43+
})
4444
`,
4545
);
4646

0 commit comments

Comments
 (0)