|
| 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 type { BuilderContext } from '@angular-devkit/architect'; |
| 10 | +import type { NormalizedUnitTestBuilderOptions } from '../../options'; |
| 11 | +import { KarmaExecutor } from './executor'; |
| 12 | + |
| 13 | +describe('KarmaExecutor', () => { |
| 14 | + async function getWarnings(options: Record<string, unknown>): Promise<string[]> { |
| 15 | + const warn = jasmine.createSpy('warn'); |
| 16 | + // The unsupported option warnings are logged before the build target is read, so stop there. |
| 17 | + const context = { |
| 18 | + logger: { warn }, |
| 19 | + getTargetOptions: () => Promise.reject(new Error('stop')), |
| 20 | + } as unknown as BuilderContext; |
| 21 | + |
| 22 | + const executor = new KarmaExecutor(context, { |
| 23 | + setupFiles: [], |
| 24 | + coverage: { enabled: false }, |
| 25 | + ...options, |
| 26 | + } as unknown as NormalizedUnitTestBuilderOptions); |
| 27 | + |
| 28 | + await expectAsync(executor.execute()[Symbol.asyncIterator]().next()).toBeRejectedWithError( |
| 29 | + 'stop', |
| 30 | + ); |
| 31 | + |
| 32 | + return warn.calls.allArgs().map(([message]) => message); |
| 33 | + } |
| 34 | + |
| 35 | + it('warns that the "providersFile" option is not supported', async () => { |
| 36 | + expect(await getWarnings({ providersFile: '/src/test-providers.ts' })).toContain( |
| 37 | + 'The "karma" test runner does not support the "providersFile" option. The option will be ignored.', |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + it('warns that the "outputFile" option is not supported', async () => { |
| 42 | + expect(await getWarnings({ outputFile: 'test-results.xml' })).toContain( |
| 43 | + 'The "karma" test runner does not support the "outputFile" option. The option will be ignored.', |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + it('warns that the "coverageReporters" option is not supported', async () => { |
| 48 | + expect(await getWarnings({ coverage: { enabled: true, reporters: [['lcov', {}]] } })).toContain( |
| 49 | + 'The "karma" test runner does not support the "coverageReporters" option. The option will be ignored.', |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + it('does not warn when no unsupported options are set', async () => { |
| 54 | + expect(await getWarnings({})).toEqual([]); |
| 55 | + }); |
| 56 | +}); |
0 commit comments