|
| 1 | +import { |
| 2 | + killAllProcesses, |
| 3 | + waitForAnyProcessOutputToMatch, |
| 4 | + execAndWaitForOutputToMatch, |
| 5 | +} from '../../../utils/process'; |
| 6 | +import { appendToFile } from '../../../utils/fs'; |
| 7 | +import { getGlobalVariable } from '../../../utils/env'; |
| 8 | +import { request } from '../../../utils/http'; |
| 9 | +import { wait } from '../../../utils/utils'; |
| 10 | + |
| 11 | +const validBundleRegEx = /webpack: bundle is now VALID|webpack: Compiled successfully./; |
| 12 | + |
| 13 | +export default function () { |
| 14 | + if (process.platform.startsWith('win')) { |
| 15 | + return Promise.resolve(); |
| 16 | + } |
| 17 | + // Skip this in ejected tests. |
| 18 | + if (getGlobalVariable('argv').eject) { |
| 19 | + return Promise.resolve(); |
| 20 | + } |
| 21 | + |
| 22 | + return execAndWaitForOutputToMatch('ng', ['serve', '--aot'], validBundleRegEx) |
| 23 | + // Wait before editing a file. |
| 24 | + // Editing too soon seems to trigger a rebuild and throw polling/watch out of whack. |
| 25 | + .then(() => wait(2000)) |
| 26 | + // Check AOT templates are up to date with current code. |
| 27 | + .then(() => request('http://localhost:4200/main.bundle.js')) |
| 28 | + .then((body) => { |
| 29 | + if (body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) { |
| 30 | + throw new Error('Expected golden value 1 to not be present.'); |
| 31 | + } |
| 32 | + }) |
| 33 | + .then(() => appendToFile('src/app/app.component.html', '<p> $$_E2E_GOLDEN_VALUE_1 </p>')) |
| 34 | + .then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 20000)) |
| 35 | + .then(() => request('http://localhost:4200/main.bundle.js')) |
| 36 | + .then((body) => { |
| 37 | + if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) { |
| 38 | + throw new Error('Expected golden value 1.'); |
| 39 | + } |
| 40 | + }) |
| 41 | + .then(() => killAllProcesses(), (err: any) => { |
| 42 | + killAllProcesses(); |
| 43 | + throw err; |
| 44 | + }); |
| 45 | +} |
0 commit comments