Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions packages/angular/build/src/builders/unit-test/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export async function* execute(
// Setup vitest browser options if configured
const { browser, errors } = setupBrowserConfiguration(
normalizedOptions.browsers,
normalizedOptions.debug,
projectSourceRoot,
);
if (errors?.length) {
Expand All @@ -196,6 +197,13 @@ export async function* execute(
if (buildTargetOptions?.polyfills?.length) {
setupFiles.push('polyfills.js');
}
const debugOptions = normalizedOptions.debug
? {
inspectBrk: true,
isolate: false,
fileParallelism: false,
}
: {};

try {
for await (const result of buildApplicationInternal(buildOptions, context, extensions)) {
Expand Down Expand Up @@ -226,6 +234,7 @@ export async function* execute(
exclude: normalizedOptions.codeCoverageExclude,
excludeAfterRemap: true,
},
...debugOptions,
},
});

Expand Down Expand Up @@ -259,6 +268,7 @@ function findBrowserProvider(

function setupBrowserConfiguration(
browsers: string[] | undefined,
debug: boolean,
projectSourceRoot: string,
): { browser?: import('vitest/node').BrowserConfigOptions; errors?: string[] } {
if (browsers === undefined) {
Expand Down Expand Up @@ -287,6 +297,15 @@ function setupBrowserConfiguration(
);
}

// Vitest current requires the playwright browser provider to use the inspect-brk option used by "debug"
if (debug && provider !== 'playwright') {
errors ??= [];
errors.push(
'Debugging browser mode tests currently requires the use of "playwright".' +
' Please install this package and rerun the test command.',
);
}

if (errors) {
return { errors };
}
Expand Down
6 changes: 6 additions & 0 deletions packages/angular/build/src/builders/unit-test/karma-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export async function useKarmaBuilder(
context: BuilderContext,
unitTestOptions: NormalizedUnitTestOptions,
): Promise<AsyncIterable<BuilderOutput>> {
if (unitTestOptions.debug) {
context.logger.warn(
'The "karma" test runner does not support the "debug" option. The option will be ignored.',
);
}

const buildTargetOptions = (await context.validateOptions(
await context.getTargetOptions(unitTestOptions.buildTarget),
await context.getBuilderNameForTarget(unitTestOptions.buildTarget),
Expand Down
1 change: 1 addition & 0 deletions packages/angular/build/src/builders/unit-test/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export async function normalizeOptions(
reporters,
browsers,
watch,
debug: options.debug ?? false,
providersFile: options.providersFile && path.join(workspaceRoot, options.providersFile),
};
}
Expand Down
5 changes: 5 additions & 0 deletions packages/angular/build/src/builders/unit-test/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
"type": "boolean",
"description": "Run build when files change."
},
"debug": {
"type": "boolean",
"description": "Initialize the test runner to support using the Node Inspector for test debugging.",
"default": false
},
"codeCoverage": {
"type": "boolean",
"description": "Output a code coverage report.",
Expand Down