|
| 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 { execute } from '../../index'; |
| 10 | +import { |
| 11 | + BASE_OPTIONS, |
| 12 | + describeBuilder, |
| 13 | + UNIT_TEST_BUILDER_INFO, |
| 14 | + setupApplicationTarget, |
| 15 | + expectLog, |
| 16 | + expectNoLog, |
| 17 | +} from '../setup'; |
| 18 | + |
| 19 | +describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { |
| 20 | + describe('Option: "quiet"', () => { |
| 21 | + let originalCI: string | undefined; |
| 22 | + |
| 23 | + beforeEach(async () => { |
| 24 | + setupApplicationTarget(harness); |
| 25 | + originalCI = process.env['CI']; |
| 26 | + }); |
| 27 | + |
| 28 | + afterEach(() => { |
| 29 | + if (originalCI !== undefined) { |
| 30 | + process.env['CI'] = originalCI; |
| 31 | + } else { |
| 32 | + delete process.env['CI']; |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + it('should default to true (quiet) when CI is not set', async () => { |
| 37 | + delete process.env['CI']; |
| 38 | + |
| 39 | + harness.useTarget('test', { |
| 40 | + ...BASE_OPTIONS, |
| 41 | + }); |
| 42 | + |
| 43 | + const { result, logs } = await harness.executeOnce(); |
| 44 | + expect(result?.success).toBeTrue(); |
| 45 | + // Should not contain the stats table headers |
| 46 | + expectNoLog(logs, /Initial chunk files/); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should default to false (verbose) when CI is set', async () => { |
| 50 | + process.env['CI'] = 'true'; |
| 51 | + |
| 52 | + harness.useTarget('test', { |
| 53 | + ...BASE_OPTIONS, |
| 54 | + }); |
| 55 | + |
| 56 | + const { result, logs } = await harness.executeOnce(); |
| 57 | + expect(result?.success).toBeTrue(); |
| 58 | + // Should contain the stats table headers or file listing |
| 59 | + expectLog(logs, /Application bundle generation complete/); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should respect quiet: true explicitly', async () => { |
| 63 | + process.env['CI'] = 'false'; // Ensure CI doesn't interfere if it defaults to false |
| 64 | + |
| 65 | + harness.useTarget('test', { |
| 66 | + ...BASE_OPTIONS, |
| 67 | + quiet: true, |
| 68 | + }); |
| 69 | + |
| 70 | + const { result, logs } = await harness.executeOnce(); |
| 71 | + expect(result?.success).toBeTrue(); |
| 72 | + expectNoLog(logs, /Initial chunk files/); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should respect quiet: false explicitly', async () => { |
| 76 | + harness.useTarget('test', { |
| 77 | + ...BASE_OPTIONS, |
| 78 | + quiet: false, |
| 79 | + }); |
| 80 | + |
| 81 | + const { result, logs } = await harness.executeOnce(); |
| 82 | + expect(result?.success).toBeTrue(); |
| 83 | + // On initial build, it should print the file list |
| 84 | + expectLog(logs, /Initial/); |
| 85 | + }); |
| 86 | + }); |
| 87 | +}); |
0 commit comments