Skip to content

Commit b2f0487

Browse files
committed
fix(@angular/build): add --ui option for Vitest runner
Adds a new `--ui` option to the `unit-test` builder to enable the Vitest UI for interactive test execution. This provides a rich, browser-based interface for viewing, filtering, and re-running tests, improving the overall developer experience. The UI option implicitly enables watch mode to provide a live dashboard. If a user explicitly disables watch mode via `--no-watch` while the UI is enabled, a warning will be logged, and watch mode will be enforced to ensure the UI functions as expected. This option is only available for the Vitest runner. An error will be thrown if used with the Karma runner. (cherry picked from commit f2248ba)
1 parent 6b1b03d commit b2f0487

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

goldens/public-api/angular/build/index.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export type UnitTestBuilderOptions = {
237237
runner?: Runner;
238238
setupFiles?: string[];
239239
tsConfig?: string;
240+
ui?: boolean;
240241
watch?: boolean;
241242
};
242243

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ export async function normalizeOptions(
5454
const buildTargetSpecifier = options.buildTarget ?? `::development`;
5555
const buildTarget = targetFromTargetString(buildTargetSpecifier, projectName, 'build');
5656

57-
const { runner, browsers, progress, filter, browserViewport } = options;
57+
const { runner, browsers, progress, filter, browserViewport, ui } = options;
58+
59+
if (ui && runner !== 'vitest') {
60+
throw new Error('The "ui" option is only available for the "vitest" runner.');
61+
}
62+
5863
const [width, height] = browserViewport?.split('x').map(Number) ?? [];
5964

6065
let tsConfig = options.tsConfig;
@@ -71,6 +76,14 @@ export async function normalizeOptions(
7176
}
7277
}
7378

79+
let watch = options.watch ?? isTTY();
80+
if (options.ui && options.watch === false) {
81+
context.logger.warn(
82+
`The '--ui' option requires watch mode. The '--no-watch' flag will be ignored.`,
83+
);
84+
watch = true;
85+
}
86+
7487
return {
7588
// Project/workspace information
7689
workspaceRoot,
@@ -105,8 +118,9 @@ export async function normalizeOptions(
105118
outputFile: options.outputFile,
106119
browsers,
107120
browserViewport: width && height ? { width, height } : undefined,
108-
watch: options.watch ?? isTTY(),
121+
watch,
109122
debug: options.debug ?? false,
123+
ui: options.ui ?? false,
110124
providersFile: options.providersFile && path.join(workspaceRoot, options.providersFile),
111125
setupFiles: options.setupFiles
112126
? options.setupFiles.map((setupFile) => path.join(workspaceRoot, setupFile))

packages/angular/build/src/builders/unit-test/runners/vitest/executor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export class VitestExecutor implements TestExecutor {
137137
debug,
138138
watch,
139139
browserViewport,
140+
ui,
140141
} = this.options;
141142
let vitestNodeModule;
142143
try {
@@ -201,6 +202,7 @@ export class VitestExecutor implements TestExecutor {
201202
reporters: reporters ?? ['default'],
202203
outputFile,
203204
watch,
205+
ui,
204206
coverage: await generateCoverageOption(coverage, this.projectName),
205207
...debugOptions,
206208
},

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
"description": "Enables debugging mode for tests, allowing the use of the Node Inspector.",
6161
"default": false
6262
},
63+
"ui": {
64+
"type": "boolean",
65+
"description": "Enables the Vitest UI for interactive test execution. This option is only available for the Vitest runner.",
66+
"default": false
67+
},
6368
"coverage": {
6469
"type": "boolean",
6570
"description": "Enables coverage reporting for tests.",

0 commit comments

Comments
 (0)