|
| 1 | +import { setTimeout } from 'node:timers/promises'; |
1 | 2 | import { getGlobalVariable } from '../../../utils/env'; |
2 | | -import { appendToFile, expectFileToMatch, writeFile } from '../../../utils/fs'; |
| 3 | +import { appendToFile, expectFileToMatch } from '../../../utils/fs'; |
3 | 4 | import { installPackage } from '../../../utils/packages'; |
4 | 5 | import { ng } from '../../../utils/process'; |
5 | 6 | import { updateJsonFile } from '../../../utils/project'; |
| 7 | +import { executeBrowserTest } from '../../../utils/puppeteer'; |
6 | 8 |
|
7 | 9 | const snapshots = require('../../../ng-snapshot/package.json'); |
8 | 10 |
|
@@ -31,26 +33,26 @@ export default async function () { |
31 | 33 | } |
32 | 34 | } |
33 | 35 |
|
34 | | - await writeFile( |
35 | | - 'e2e/app.e2e-spec.ts', |
36 | | - ` |
37 | | - import { browser, by, element } from 'protractor'; |
| 36 | + await ng('build'); |
| 37 | + await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/); |
38 | 38 |
|
39 | | - it('should have ngsw in normal state', () => { |
40 | | - browser.get('/'); |
| 39 | + await executeBrowserTest({ |
| 40 | + configuration: 'production', |
| 41 | + checkFn: async (page) => { |
41 | 42 | // 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 | | - ); |
| 43 | + await setTimeout(2000); |
51 | 44 |
|
52 | | - await ng('build'); |
53 | | - await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/); |
| 45 | + const baseUrl = page.url(); |
| 46 | + await page.goto(new URL('/ngsw/state', baseUrl).href); |
54 | 47 |
|
55 | | - await ng('e2e', '--configuration=production'); |
| 48 | + // Should have updated, and be in normal state. |
| 49 | + const preText = await page.$eval('pre', (el) => el.textContent); |
| 50 | + if (preText?.includes('Last update check: never')) { |
| 51 | + throw new Error(`Expected service worker to have checked for updates, but got: ${preText}`); |
| 52 | + } |
| 53 | + if (!preText?.includes('Driver state: NORMAL')) { |
| 54 | + throw new Error(`Expected service worker driver state to be NORMAL, but got: ${preText}`); |
| 55 | + } |
| 56 | + }, |
| 57 | + }); |
56 | 58 | } |
0 commit comments