|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google Inc. All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | +import { concatMap, count, take, timeout } from 'rxjs/operators'; |
| 9 | +import { buildWebpackBrowser } from '../../index'; |
| 10 | +import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup'; |
| 11 | + |
| 12 | +describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => { |
| 13 | + describe('Option: "watch"', () => { |
| 14 | + it('does not wait for file changes when false', (done) => { |
| 15 | + harness.useTarget('build', { |
| 16 | + ...BASE_OPTIONS, |
| 17 | + watch: false, |
| 18 | + }); |
| 19 | + |
| 20 | + // If the build waits then it will timeout with the custom timeout. |
| 21 | + // A single build should not take more than 15 seconds. |
| 22 | + let count = 0; |
| 23 | + harness |
| 24 | + .execute() |
| 25 | + .pipe(timeout(15000)) |
| 26 | + .subscribe({ |
| 27 | + complete() { |
| 28 | + expect(count).toBe(1); |
| 29 | + done(); |
| 30 | + }, |
| 31 | + next({ result }) { |
| 32 | + count++; |
| 33 | + expect(result?.success).toBe(true); |
| 34 | + }, |
| 35 | + error(error) { |
| 36 | + done.fail(error); |
| 37 | + }, |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + it('does not wait for file changes when not present', (done) => { |
| 42 | + harness.useTarget('build', { |
| 43 | + ...BASE_OPTIONS, |
| 44 | + }); |
| 45 | + |
| 46 | + // If the build waits then it will timeout with the custom timeout. |
| 47 | + // A single build should not take more than 15 seconds. |
| 48 | + let count = 0; |
| 49 | + harness |
| 50 | + .execute() |
| 51 | + .pipe(timeout(15000)) |
| 52 | + .subscribe({ |
| 53 | + complete() { |
| 54 | + expect(count).toBe(1); |
| 55 | + done(); |
| 56 | + }, |
| 57 | + next({ result }) { |
| 58 | + count++; |
| 59 | + expect(result?.success).toBe(true); |
| 60 | + }, |
| 61 | + error(error) { |
| 62 | + done.fail(error); |
| 63 | + }, |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + it('watches for file changes when true', async () => { |
| 68 | + harness.useTarget('build', { |
| 69 | + ...BASE_OPTIONS, |
| 70 | + main: 'src/main.ts', |
| 71 | + watch: true, |
| 72 | + }); |
| 73 | + |
| 74 | + const buildCount = await harness |
| 75 | + .execute() |
| 76 | + .pipe( |
| 77 | + timeout(30000), |
| 78 | + concatMap(async ({ result }, index) => { |
| 79 | + expect(result?.success).toBe(true); |
| 80 | + |
| 81 | + switch (index) { |
| 82 | + case 0: |
| 83 | + harness.expectFile('dist/main.js').content.not.toContain('abcd1234'); |
| 84 | + |
| 85 | + await harness.modifyFile( |
| 86 | + 'src/main.ts', |
| 87 | + (content) => content + 'console.log("abcd1234");', |
| 88 | + ); |
| 89 | + break; |
| 90 | + case 1: |
| 91 | + harness.expectFile('dist/main.js').content.toContain('abcd1234'); |
| 92 | + break; |
| 93 | + } |
| 94 | + }), |
| 95 | + take(2), |
| 96 | + count(), |
| 97 | + ) |
| 98 | + .toPromise(); |
| 99 | + |
| 100 | + expect(buildCount).toBe(2); |
| 101 | + }); |
| 102 | + }); |
| 103 | +}); |
0 commit comments