|
| 1 | +import { |
| 2 | + killAllProcesses, |
| 3 | + waitForAnyProcessOutputToMatch, |
| 4 | + silentExecAndWaitForOutputToMatch, |
| 5 | +} from '../../utils/process'; |
| 6 | +import {writeFile, prependToFile, appendToFile} from '../../utils/fs'; |
| 7 | +import {wait} from '../../utils/utils'; |
| 8 | + |
| 9 | + |
| 10 | +export default function() { |
| 11 | + if (process.platform.startsWith('win')) { |
| 12 | + return Promise.resolve(); |
| 13 | + } |
| 14 | + |
| 15 | + return silentExecAndWaitForOutputToMatch('ng', ['serve'], /webpack: bundle is now VALID/) |
| 16 | + // Create and import files. |
| 17 | + .then(() => writeFile('src/funky2.ts', ` |
| 18 | + export function funky2(value: string): string { |
| 19 | + return value + 'hello'; |
| 20 | + } |
| 21 | + `)) |
| 22 | + .then(() => writeFile('src/funky.ts', ` |
| 23 | + export * from './funky2'; |
| 24 | + `)) |
| 25 | + .then(() => prependToFile('src/main.ts', ` |
| 26 | + import { funky } from './funky'; |
| 27 | + `)) |
| 28 | + .then(() => appendToFile('src/main.ts', ` |
| 29 | + console.log(funky('town')); |
| 30 | + `)) |
| 31 | + // Should trigger a rebuild, no error expected. |
| 32 | + .then(() => waitForAnyProcessOutputToMatch(/webpack: bundle is now VALID/, 5000)) |
| 33 | + // Create and import files. |
| 34 | + .then(() => wait(2000)) |
| 35 | + .then(() => writeFile('src/funky2.ts', ` |
| 36 | + export function funky(value: number): number { |
| 37 | + return value + 1; |
| 38 | + } |
| 39 | + `)) |
| 40 | + // Should trigger a rebuild, this time an error is expected. |
| 41 | + .then(() => waitForAnyProcessOutputToMatch(/webpack: bundle is now VALID/, 5000)) |
| 42 | + .then(({ stdout }) => { |
| 43 | + if (!/ERROR in .*\/src\/main\.ts \(/.test(stdout)) { |
| 44 | + throw new Error('Expected an error but none happened.'); |
| 45 | + } |
| 46 | + }) |
| 47 | + // Fix the error! |
| 48 | + .then(() => writeFile('src/funky2.ts', ` |
| 49 | + export function funky(value: string): string { |
| 50 | + return value + 'hello'; |
| 51 | + } |
| 52 | + `)) |
| 53 | + .then(() => waitForAnyProcessOutputToMatch(/webpack: bundle is now VALID/, 5000)) |
| 54 | + .then(({ stdout }) => { |
| 55 | + if (/ERROR in .*\/src\/main\.ts \(/.test(stdout)) { |
| 56 | + throw new Error('Expected no error but an error was shown.'); |
| 57 | + } |
| 58 | + }) |
| 59 | + .then(() => killAllProcesses(), (err: any) => { |
| 60 | + killAllProcesses(); |
| 61 | + throw err; |
| 62 | + }); |
| 63 | +} |
0 commit comments