Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ export class KarmaExecutor implements TestExecutor {
);
}

if (unitTestOptions.providersFile) {
context.logger.warn(
'The "karma" test runner does not support the "providersFile" option. The option will be ignored.',
);
}

if (unitTestOptions.outputFile) {
context.logger.warn(
'The "karma" test runner does not support the "outputFile" option. The option will be ignored.',
);
}

if (unitTestOptions.coverage.reporters) {
Comment thread
MeAkib marked this conversation as resolved.
Resolved
context.logger.warn(
'The "karma" test runner does not support the "coverageReporters" option. The option will be ignored.',
);
}

const buildTargetOptions = (await context.validateOptions(
await context.getTargetOptions(unitTestOptions.buildTarget),
await context.getBuilderNameForTarget(unitTestOptions.buildTarget),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
Comment thread
alan-agius4 marked this conversation as resolved.
Resolved
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import type { BuilderContext } from '@angular-devkit/architect';
import type { NormalizedUnitTestBuilderOptions } from '../../options';
import { KarmaExecutor } from './executor';

describe('KarmaExecutor', () => {
async function getWarnings(options: Record<string, unknown>): Promise<string[]> {
const warn = jasmine.createSpy('warn');
// The unsupported option warnings are logged before the build target is read, so stop there.
const context = {
logger: { warn },
getTargetOptions: () => Promise.reject(new Error('stop')),
} as unknown as BuilderContext;

const executor = new KarmaExecutor(context, {
setupFiles: [],
coverage: { enabled: false },
...options,
} as unknown as NormalizedUnitTestBuilderOptions);

await expectAsync(executor.execute()[Symbol.asyncIterator]().next()).toBeRejectedWithError(
'stop',
);

return warn.calls.allArgs().map(([message]) => message);
}

it('warns that the "providersFile" option is not supported', async () => {
expect(await getWarnings({ providersFile: '/src/test-providers.ts' })).toContain(
'The "karma" test runner does not support the "providersFile" option. The option will be ignored.',
);
});

it('warns that the "outputFile" option is not supported', async () => {
expect(await getWarnings({ outputFile: 'test-results.xml' })).toContain(
'The "karma" test runner does not support the "outputFile" option. The option will be ignored.',
);
});

it('warns that the "coverageReporters" option is not supported', async () => {
expect(await getWarnings({ coverage: { enabled: true, reporters: [['lcov', {}]] } })).toContain(
'The "karma" test runner does not support the "coverageReporters" option. The option will be ignored.',
);
});

it('does not warn when no unsupported options are set', async () => {
expect(await getWarnings({})).toEqual([]);
});
});
Loading