Skip to content

Commit 02a5d5d

Browse files
committed
refactor(@angular/build): provide karma runner for unit-test builder
The `runner` option for the `unit-test` builder can now be set to `karma`. This leverages the existing `karma` builder for test execution. The `karma` build related options are derived from the provided `buildTarget` option instead of being manually specified within the `unit-test` builder. In other areas, the test execution is the same with the exceptions of specifying either a custom configuration file and/or a custom main file.
1 parent cf31d19 commit 02a5d5d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/angular/build/src/builders/unit-test/builder.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ResultKind } from '../application/results';
2121
import { OutputHashing } from '../application/schema';
2222
import { writeTestFiles } from '../karma/application_builder';
2323
import { findTests, getTestEntrypoints } from '../karma/find-tests';
24+
import { useKarmaBuilder } from './karma-bridge';
2425
import { normalizeOptions } from './options';
2526
import type { Schema as UnitTestOptions } from './schema';
2627

@@ -51,6 +52,14 @@ export async function* execute(
5152
const normalizedOptions = await normalizeOptions(context, projectName, options);
5253
const { projectSourceRoot, workspaceRoot, runnerName } = normalizedOptions;
5354

55+
// Translate options and use karma builder directly if specified
56+
if (runnerName === 'karma') {
57+
const karmaBridge = await useKarmaBuilder(context, normalizedOptions);
58+
yield* karmaBridge;
59+
60+
return;
61+
}
62+
5463
if (runnerName !== 'vitest') {
5564
context.logger.error('Unknown test runner: ' + runnerName);
5665

packages/angular/build/src/builders/unit-test/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"runner": {
1717
"type": "string",
1818
"description": "The name of the test runner to use for test execution.",
19-
"enum": ["vitest"]
19+
"enum": ["karma", "vitest"]
2020
},
2121
"include": {
2222
"type": "array",

0 commit comments

Comments
 (0)