Skip to content

Commit 31217f4

Browse files
committed
test: migrate app-shell-with-service-worker E2E test to Puppeteer
Replaces the Protractor-based ng e2e execution with the new Puppeteer executeBrowserTest utility in `build/app-shell/app-shell-with-service-worker.ts` E2E test.
1 parent 164e7db commit 31217f4

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

tests/e2e/tests/build/app-shell/app-shell-with-service-worker.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { getGlobalVariable } from '../../../utils/env';
2-
import { appendToFile, expectFileToMatch, writeFile } from '../../../utils/fs';
2+
import { appendToFile, expectFileToMatch } from '../../../utils/fs';
33
import { installPackage } from '../../../utils/packages';
44
import { ng } from '../../../utils/process';
55
import { updateJsonFile } from '../../../utils/project';
6+
import { executeBrowserTest } from '../../../utils/puppeteer';
67

78
const snapshots = require('../../../ng-snapshot/package.json');
89

@@ -31,26 +32,26 @@ export default async function () {
3132
}
3233
}
3334

34-
await writeFile(
35-
'e2e/app.e2e-spec.ts',
36-
`
37-
import { browser, by, element } from 'protractor';
35+
await ng('build');
36+
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);
3837

39-
it('should have ngsw in normal state', () => {
40-
browser.get('/');
38+
await executeBrowserTest({
39+
configuration: 'production',
40+
checkFn: async (page) => {
4141
// Wait for service worker to load.
42-
browser.sleep(2000);
43-
browser.waitForAngularEnabled(false);
44-
browser.get('/ngsw/state');
45-
// Should have updated, and be in normal state.
46-
expect(element(by.css('pre')).getText()).not.toContain('Last update check: never');
47-
expect(element(by.css('pre')).getText()).toContain('Driver state: NORMAL');
48-
});
49-
`,
50-
);
42+
await new Promise((resolve) => setTimeout(resolve, 2000));
5143

52-
await ng('build');
53-
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);
44+
const baseUrl = page.url();
45+
await page.goto(new URL('/ngsw/state', baseUrl).href);
5446

55-
await ng('e2e', '--configuration=production');
47+
// Should have updated, and be in normal state.
48+
const preText = await page.$eval('pre', (el) => el.textContent);
49+
if (preText?.includes('Last update check: never')) {
50+
throw new Error(`Expected service worker to have checked for updates, but got: ${preText}`);
51+
}
52+
if (!preText?.includes('Driver state: NORMAL')) {
53+
throw new Error(`Expected service worker driver state to be NORMAL, but got: ${preText}`);
54+
}
55+
},
56+
});
5657
}

0 commit comments

Comments
 (0)