Skip to content

Commit fe12723

Browse files
committed
test: update ssr test to use correct sha when testing ng add @angular/ssr
Before this change when running snapshot test, the schematic would add `@angular/platform-server` with the same version of `@angular/core`. This causing a problem when testing snapshots as the version is not a semver specifier but rather the path to the Github build repo. With this change, we ensure that the correct SHA is used for platform-server when running snapshot tests.
1 parent 26778bd commit fe12723

File tree

4 files changed

+67
-49
lines changed

4 files changed

+67
-49
lines changed

tests/legacy-cli/e2e/tests/ssr/express-engine-csp-nonce.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { rimraf, writeMultipleFiles } from '../../utils/fs';
22
import { findFreePort } from '../../utils/network';
3+
import { installWorkspacePackages } from '../../utils/packages';
34
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../utils/process';
5+
import { useSha } from '../../utils/project';
46

57
export default async function () {
68
// forcibly remove in case another test doesn't clean itself up
79
await rimraf('node_modules/@angular/ssr');
10+
await ng('add', '@angular/ssr', '--skip-confirmation', '--skip-install');
811

9-
await ng('add', '@angular/ssr', '--skip-confirmation');
12+
await useSha();
13+
await installWorkspacePackages();
1014

1115
await writeMultipleFiles({
1216
'src/styles.css': `* { color: #000 }`,

tests/legacy-cli/e2e/tests/ssr/express-engine-ngmodule.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { rimraf, writeMultipleFiles } from '../../utils/fs';
22
import { findFreePort } from '../../utils/network';
3+
import { installWorkspacePackages } from '../../utils/packages';
34
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../utils/process';
5+
import { useSha } from '../../utils/project';
46

57
export default async function () {
68
// forcibly remove in case another test doesn't clean itself up
79
await rimraf('node_modules/@angular/ssr');
8-
await ng('add', '@angular/ssr', '--skip-confirmation');
10+
await ng('add', '@angular/ssr', '--skip-confirmation', '--skip-install');
11+
12+
await useSha();
13+
await installWorkspacePackages();
914

1015
await writeMultipleFiles({
1116
'src/styles.css': `* { color: #000 }`,

tests/legacy-cli/e2e/tests/ssr/express-engine-standalone.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
import { rimraf, writeMultipleFiles } from '../../utils/fs';
22
import { findFreePort } from '../../utils/network';
3+
import { installWorkspacePackages } from '../../utils/packages';
34
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../utils/process';
4-
import { useCIChrome, useCIDefaults } from '../../utils/project';
5+
import { useCIChrome, useCIDefaults, useSha } from '../../utils/project';
56

67
export default async function () {
78
// forcibly remove in case another test doesn't clean itself up
89
await rimraf('node_modules/@angular/ssr');
910

1011
await ng('generate', 'app', 'test-project-two', '--standalone', '--skip-install');
11-
1212
await ng('generate', 'e2e', '--related-app-name=test-project-two');
13+
1314
// Setup testing to use CI Chrome.
1415
await useCIChrome('test-project-two', 'projects/test-project-two/e2e/');
1516
await useCIDefaults('test-project-two');
1617

17-
await ng('add', '@angular/ssr', '--skip-confirmation', '--project=test-project-two');
18+
await ng(
19+
'add',
20+
'@angular/ssr',
21+
'--skip-confirmation',
22+
'--project=test-project-two',
23+
'--skip-install',
24+
);
25+
26+
await useSha();
27+
await installWorkspacePackages();
1828

1929
await writeMultipleFiles({
2030
'projects/test-project-two/src/styles.css': `* { color: #000 }`,

tests/legacy-cli/e2e/utils/project.ts

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -82,53 +82,52 @@ export function useBuiltPackagesVersions(): Promise<void> {
8282
});
8383
}
8484

85-
export function useSha() {
85+
export async function useSha(): Promise<void> {
8686
const argv = getGlobalVariable('argv');
87-
if (argv['ng-snapshots'] || argv['ng-tag']) {
88-
// We need more than the sha here, version is also needed. Examples of latest tags:
89-
// 7.0.0-beta.4+dd2a650
90-
// 6.1.6+4a8d56a
91-
const label = argv['ng-tag'] ? argv['ng-tag'] : '';
92-
const ngSnapshotVersions = require('../ng-snapshot/package.json');
93-
return updateJsonFile('package.json', (json) => {
94-
// Install over the project with snapshot builds.
95-
function replaceDependencies(key: string) {
96-
const missingSnapshots: string[] = [];
97-
Object.keys(json[key] || {})
98-
.filter((name) => name.match(/^@angular\//))
99-
.forEach((name) => {
100-
const pkgName = name.split(/\//)[1];
101-
if (pkgName == 'cli') {
102-
return;
103-
}
104-
if (label) {
105-
json[key][`@angular/${pkgName}`] = `github:angular/${pkgName}-builds${label}`;
106-
} else {
107-
const replacement = ngSnapshotVersions.dependencies[`@angular/${pkgName}`];
108-
if (!replacement) {
109-
missingSnapshots.push(`missing @angular/${pkgName}`);
110-
}
111-
json[key][`@angular/${pkgName}`] = replacement;
87+
if (!argv['ng-snapshots'] && !argv['ng-tag']) {
88+
return;
89+
}
90+
91+
// We need more than the sha here, version is also needed. Examples of latest tags:
92+
// 7.0.0-beta.4+dd2a650
93+
// 6.1.6+4a8d56a
94+
const label = argv['ng-tag'] || '';
95+
const ngSnapshotVersions = require('../ng-snapshot/package.json');
96+
97+
return updateJsonFile('package.json', (json) => {
98+
// Install over the project with snapshot builds.
99+
function replaceDependencies(key: string) {
100+
const missingSnapshots: string[] = [];
101+
Object.keys(json[key] || {})
102+
.filter((name) => name.startsWith('@angular/'))
103+
.forEach((name) => {
104+
const pkgName = name.split(/\//)[1];
105+
if (pkgName === 'cli' || pkgName === 'ssr') {
106+
return;
107+
}
108+
109+
if (label) {
110+
json[key][`@angular/${pkgName}`] = `github:angular/${pkgName}-builds${label}`;
111+
} else {
112+
const replacement = ngSnapshotVersions.dependencies[`@angular/${pkgName}`];
113+
if (!replacement) {
114+
missingSnapshots.push(`missing @angular/${pkgName}`);
112115
}
113-
});
114-
if (missingSnapshots.length > 0) {
115-
throw new Error(
116-
'e2e test with --ng-snapshots requires all angular packages be ' +
117-
'listed in tests/legacy-cli/e2e/ng-snapshot/package.json.\nErrors:\n' +
118-
missingSnapshots.join('\n '),
119-
);
120-
}
116+
json[key][`@angular/${pkgName}`] = replacement;
117+
}
118+
});
119+
if (missingSnapshots.length > 0) {
120+
throw new Error(
121+
'e2e test with --ng-snapshots requires all angular packages be ' +
122+
'listed in tests/legacy-cli/e2e/ng-snapshot/package.json.\nErrors:\n' +
123+
missingSnapshots.join('\n '),
124+
);
121125
}
122-
try {
123-
replaceDependencies('dependencies');
124-
replaceDependencies('devDependencies');
125-
} catch (e) {
126-
return Promise.reject(e);
127-
}
128-
});
129-
} else {
130-
return Promise.resolve();
131-
}
126+
}
127+
128+
replaceDependencies('dependencies');
129+
replaceDependencies('devDependencies');
130+
});
132131
}
133132

134133
export function useCIDefaults(projectName = 'test-project'): Promise<void> {

0 commit comments

Comments
 (0)