Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 247cd33

Browse filesBrowse files
committed
fix(@angular/build): show unit-test error for missing vitest package
When using the experimental `unit-test` builder with `vitest` as the runner, an error message will now be shown if the `vitest` package cannot be loaded. The error message includes a suggestion to install the package if not present. (cherry picked from commit 48f84ca)
1 parent 769961e commit 247cd33
Copy full SHA for 247cd33

File tree

1 file changed

+18
-1
lines changed
Filter options
  • packages/angular/build/src/builders/unit-test

1 file changed

+18
-1
lines changed

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

Copy file name to clipboardExpand all lines: packages/angular/build/src/builders/unit-test/builder.ts
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { randomUUID } from 'node:crypto';
1212
import { createRequire } from 'node:module';
1313
import path from 'node:path';
1414
import { createVirtualModulePlugin } from '../../tools/esbuild/virtual-module-plugin';
15+
import { assertIsError } from '../../utils/error';
1516
import { loadEsmModule } from '../../utils/load-esm';
1617
import { buildApplicationInternal } from '../application';
1718
import type {
@@ -31,6 +32,7 @@ export type { UnitTestOptions };
3132
/**
3233
* @experimental Direct usage of this function is considered experimental.
3334
*/
35+
// eslint-disable-next-line max-lines-per-function
3436
export async function* execute(
3537
options: UnitTestOptions,
3638
context: BuilderContext,
@@ -84,7 +86,22 @@ export async function* execute(
8486
const entryPoints = getTestEntrypoints(testFiles, { projectSourceRoot, workspaceRoot });
8587
entryPoints.set('init-testbed', 'angular:test-bed-init');
8688

87-
const { startVitest } = await loadEsmModule<typeof import('vitest/node')>('vitest/node');
89+
let vitestNodeModule;
90+
try {
91+
vitestNodeModule = await loadEsmModule<typeof import('vitest/node')>('vitest/node');
92+
} catch (error: unknown) {
93+
assertIsError(error);
94+
if (error.code !== 'ERR_MODULE_NOT_FOUND') {
95+
throw error;
96+
}
97+
98+
context.logger.error(
99+
'The `vitest` package was not found. Please install the package and rerun the test command.',
100+
);
101+
102+
return;
103+
}
104+
const { startVitest } = vitestNodeModule;
88105

89106
// Setup test file build options based on application build target options
90107
const buildTargetOptions = (await context.validateOptions(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.