Skip to content

Commit c44100b

Browse files
committed
test: use correct snapshot versions in add-pwa E2E test
When executing the add-pwa E2E test with Angular snapshots, the package versions need to be updated after the `ng add @angular/pwa` call to ensure that the correct version of `@angular/service-worker` is used.
1 parent 640a749 commit c44100b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

tests/legacy-cli/e2e/ng-snapshot/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@angular/platform-browser": "github:angular/platform-browser-builds#8a3b383485754ffe85453d972db8709484a56ab3",
1717
"@angular/platform-browser-dynamic": "github:angular/platform-browser-dynamic-builds#b6d2d193af01f8ac5951a5e6e945712a0d948fe5",
1818
"@angular/platform-server": "github:angular/platform-server-builds#7553899212283c15a3bd08661417b8c0b06f51f9",
19-
"@angular/router": "github:angular/router-builds#76cd3541b820ddac2416de5f1bb48c106b4973dc"
19+
"@angular/router": "github:angular/router-builds#76cd3541b820ddac2416de5f1bb48c106b4973dc",
20+
"@angular/service-worker": "github:angular/service-worker-builds#163cd9d311092d2358f33f2de0b3e8eb97a0f38e"
2021
}
2122
}

tests/legacy-cli/e2e/tests/commands/add/add-pwa.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { join } from 'path';
2+
import { getGlobalVariable } from '../../../utils/env';
23
import { expectFileToExist, readFile, rimraf } from '../../../utils/fs';
4+
import { installPackage } from '../../../utils/packages';
35
import { ng } from '../../../utils/process';
6+
import { updateJsonFile } from '../../../utils/project';
7+
8+
const snapshots = require('../../../ng-snapshot/package.json');
49

510
export default async function () {
611
// forcibly remove in case another test doesn't clean itself up
@@ -19,6 +24,24 @@ export default async function () {
1924
throw new Error(`Expected 'package.json' not to contain a dependency on '@angular/pwa'.`);
2025
}
2126

27+
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
28+
if (isSnapshotBuild) {
29+
const packagesToInstall = [];
30+
await updateJsonFile('package.json', (packageJson) => {
31+
const dependencies = packageJson['dependencies'];
32+
// Iterate over all of the packages to update them to the snapshot version.
33+
for (const [name, version] of Object.entries(snapshots.dependencies)) {
34+
if (name in dependencies && dependencies[name] !== version) {
35+
packagesToInstall.push(version);
36+
}
37+
}
38+
});
39+
40+
for (const pkg of packagesToInstall) {
41+
await installPackage(pkg);
42+
}
43+
}
44+
2245
// It should generate a SW configuration file (`ngsw.json`).
2346
const workspaceJson = JSON.parse(await readFile('angular.json'));
2447
const outputPath = workspaceJson.projects['test-project'].architect.build.options.outputPath;

0 commit comments

Comments
 (0)