|
| 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 | +} from '../setup'; |
| 16 | + |
| 17 | +const VITEST_CONFIG_CONTENT = ` |
| 18 | +import { defineConfig } from 'vitest/config'; |
| 19 | +export default defineConfig({ |
| 20 | + test: { |
| 21 | + reporters: [['junit', { outputFile: './vitest-results.xml' }]], |
| 22 | + }, |
| 23 | +}); |
| 24 | +`; |
| 25 | + |
| 26 | +describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { |
| 27 | + describe('Option: "runnerConfig"', () => { |
| 28 | + beforeEach(() => { |
| 29 | + setupApplicationTarget(harness); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('Vitest Runner', () => { |
| 33 | + it('should use a specified config file path', async () => { |
| 34 | + harness.writeFile('custom-vitest.config.ts', VITEST_CONFIG_CONTENT); |
| 35 | + harness.useTarget('test', { |
| 36 | + ...BASE_OPTIONS, |
| 37 | + runnerConfig: 'custom-vitest.config.ts', |
| 38 | + }); |
| 39 | + |
| 40 | + const { result } = await harness.executeOnce(); |
| 41 | + |
| 42 | + expect(result?.success).toBeTrue(); |
| 43 | + harness.expectFile('vitest-results.xml').toExist(); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should search for a config file when `true`', async () => { |
| 47 | + harness.writeFile('vitest.config.ts', VITEST_CONFIG_CONTENT); |
| 48 | + harness.useTarget('test', { |
| 49 | + ...BASE_OPTIONS, |
| 50 | + runnerConfig: true, |
| 51 | + }); |
| 52 | + |
| 53 | + const { result } = await harness.executeOnce(); |
| 54 | + |
| 55 | + expect(result?.success).toBeTrue(); |
| 56 | + harness.expectFile('vitest-results.xml').toExist(); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should ignore config file when `false`', async () => { |
| 60 | + harness.writeFile('vitest.config.ts', VITEST_CONFIG_CONTENT); |
| 61 | + harness.useTarget('test', { |
| 62 | + ...BASE_OPTIONS, |
| 63 | + runnerConfig: false, |
| 64 | + }); |
| 65 | + |
| 66 | + const { result } = await harness.executeOnce(); |
| 67 | + |
| 68 | + expect(result?.success).toBeTrue(); |
| 69 | + harness.expectFile('vitest-results.xml').toNotExist(); |
| 70 | + }); |
| 71 | + |
| 72 | + it('should ignore config file by default', async () => { |
| 73 | + harness.writeFile('vitest.config.ts', VITEST_CONFIG_CONTENT); |
| 74 | + harness.useTarget('test', { |
| 75 | + ...BASE_OPTIONS, |
| 76 | + }); |
| 77 | + |
| 78 | + const { result } = await harness.executeOnce(); |
| 79 | + |
| 80 | + expect(result?.success).toBeTrue(); |
| 81 | + harness.expectFile('vitest-results.xml').toNotExist(); |
| 82 | + }); |
| 83 | + }); |
| 84 | + }); |
| 85 | +}); |
0 commit comments