|
| 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 '../../builder'; |
| 10 | +import { |
| 11 | + BASE_OPTIONS, |
| 12 | + describeBuilder, |
| 13 | + UNIT_TEST_BUILDER_INFO, |
| 14 | + setupApplicationTarget, |
| 15 | +} from '../setup'; |
| 16 | + |
| 17 | +describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { |
| 18 | + describe('Option: "filter"', () => { |
| 19 | + beforeEach(async () => { |
| 20 | + setupApplicationTarget(harness); |
| 21 | + |
| 22 | + await harness.writeFiles({ |
| 23 | + 'src/app/pass.spec.ts': ` |
| 24 | + describe('Passing Suite', () => { |
| 25 | + it('should pass', () => { |
| 26 | + expect(true).toBe(true); |
| 27 | + }); |
| 28 | + }); |
| 29 | + `, |
| 30 | + 'src/app/fail.spec.ts': ` |
| 31 | + describe('Failing Suite', () => { |
| 32 | + it('should fail', () => { |
| 33 | + expect(true).toBe(false); |
| 34 | + }); |
| 35 | + }); |
| 36 | + `, |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should only run tests that match the filter regex', async () => { |
| 41 | + harness.useTarget('test', { |
| 42 | + ...BASE_OPTIONS, |
| 43 | + // This filter should only match the 'should pass' test |
| 44 | + filter: 'pass$', |
| 45 | + }); |
| 46 | + |
| 47 | + const { result } = await harness.executeOnce(); |
| 48 | + // The overall result should be success because the failing test was filtered out. |
| 49 | + expect(result?.success).toBe(true); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should run all tests when no filter is provided', async () => { |
| 53 | + harness.useTarget('test', { |
| 54 | + ...BASE_OPTIONS, |
| 55 | + }); |
| 56 | + |
| 57 | + const { result } = await harness.executeOnce(); |
| 58 | + // The overall result should be failure because the failing test was included. |
| 59 | + expect(result?.success).toBe(false); |
| 60 | + }); |
| 61 | + }); |
| 62 | +}); |
0 commit comments