|
1 | 1 | import { getGlobalVariable } from '../../../utils/env'; |
2 | | -import { appendToFile, expectFileToMatch, writeFile } from '../../../utils/fs'; |
| 2 | +import { appendToFile, expectFileToMatch } from '../../../utils/fs'; |
3 | 3 | import { installPackage } from '../../../utils/packages'; |
4 | 4 | import { ng } from '../../../utils/process'; |
5 | 5 | import { updateJsonFile } from '../../../utils/project'; |
| 6 | +import { executeBrowserTest } from '../../../utils/puppeteer'; |
6 | 7 |
|
7 | 8 | const snapshots = require('../../../ng-snapshot/package.json'); |
8 | 9 |
|
@@ -31,26 +32,26 @@ export default async function () { |
31 | 32 | } |
32 | 33 | } |
33 | 34 |
|
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!/); |
38 | 37 |
|
39 | | - it('should have ngsw in normal state', () => { |
40 | | - browser.get('/'); |
| 38 | + await executeBrowserTest({ |
| 39 | + configuration: 'production', |
| 40 | + checkFn: async (page) => { |
41 | 41 | // 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)); |
51 | 43 |
|
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); |
54 | 46 |
|
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 | + }); |
56 | 57 | } |
0 commit comments