|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC 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.dev/license |
| 7 | + */ |
| 8 | + |
| 9 | +import { concatMap, count, take, timeout } from 'rxjs'; |
| 10 | +import { buildApplication } from '../../index'; |
| 11 | +import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; |
| 12 | + |
| 13 | +/** |
| 14 | + * Maximum time in milliseconds for single build/rebuild |
| 15 | + * This accounts for CI variability. |
| 16 | + */ |
| 17 | +const BUILD_TIMEOUT = 10_000; |
| 18 | + |
| 19 | +describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { |
| 20 | + describe('Behavior: "Rebuilds when input asset changes"', () => { |
| 21 | + beforeEach(async () => { |
| 22 | + // Application code is not needed for styles tests |
| 23 | + await harness.writeFile('src/main.ts', 'console.log("TEST");'); |
| 24 | + await harness.writeFile('public/asset.txt', 'foo'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('emits updated asset', async () => { |
| 28 | + harness.useTarget('build', { |
| 29 | + ...BASE_OPTIONS, |
| 30 | + assets: [ |
| 31 | + { |
| 32 | + glob: '**/*', |
| 33 | + input: 'public', |
| 34 | + }, |
| 35 | + ], |
| 36 | + watch: true, |
| 37 | + }); |
| 38 | + |
| 39 | + const buildCount = await harness |
| 40 | + .execute({ outputLogsOnFailure: false }) |
| 41 | + .pipe( |
| 42 | + timeout(BUILD_TIMEOUT), |
| 43 | + concatMap(async ({ result }, index) => { |
| 44 | + switch (index) { |
| 45 | + case 0: |
| 46 | + expect(result?.success).toBeTrue(); |
| 47 | + harness.expectFile('dist/browser/asset.txt').content.toContain('foo'); |
| 48 | + |
| 49 | + await harness.writeFile('public/asset.txt', 'bar'); |
| 50 | + break; |
| 51 | + case 1: |
| 52 | + expect(result?.success).toBeTrue(); |
| 53 | + harness.expectFile('dist/browser/asset.txt').content.toContain('bar'); |
| 54 | + break; |
| 55 | + } |
| 56 | + }), |
| 57 | + take(2), |
| 58 | + count(), |
| 59 | + ) |
| 60 | + .toPromise(); |
| 61 | + |
| 62 | + expect(buildCount).toBe(2); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
0 commit comments