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
1 change: 1 addition & 0 deletions goldens/public-api/angular/build/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export type NgPackagrBuilderOptions = {

// @public
export type UnitTestBuilderOptions = {
browserViewport?: string;
browsers?: string[];
buildTarget?: string;
coverage?: boolean;
Expand Down
4 changes: 3 additions & 1 deletion packages/angular/build/src/builders/unit-test/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export async function normalizeOptions(
const buildTargetSpecifier = options.buildTarget ?? `::development`;
const buildTarget = targetFromTargetString(buildTargetSpecifier, projectName, 'build');

const { runner, browsers, progress, filter } = options;
const { runner, browsers, progress, filter, browserViewport } = options;
const [width, height] = browserViewport?.split('x').map(Number) ?? [];

let tsConfig = options.tsConfig;
if (tsConfig) {
Expand Down Expand Up @@ -104,6 +105,7 @@ export async function normalizeOptions(
reporters: normalizeReporterOption(options.reporters),
outputFile: options.outputFile,
browsers,
browserViewport: width && height ? { width, height } : undefined,
watch: options.watch ?? isTTY(),
debug: options.debug ?? false,
providersFile: options.providersFile && path.join(workspaceRoot, options.providersFile),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export class KarmaExecutor implements TestExecutor {
async *execute(): AsyncIterable<BuilderOutput> {
const { context, options: unitTestOptions } = this;

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

if (unitTestOptions.debug) {
context.logger.warn(
'The "karma" test runner does not support the "debug" option. The option will be ignored.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function setupBrowserConfiguration(
browsers: string[] | undefined,
debug: boolean,
projectSourceRoot: string,
viewport: { width: number; height: number } | undefined,
): BrowserConfiguration {
if (browsers === undefined) {
return {};
Expand Down Expand Up @@ -91,6 +92,7 @@ export function setupBrowserConfiguration(
provider,
headless,
ui: !headless,
viewport,
instances: browsers.map((browserName) => ({
browser: normalizeBrowserName(browserName),
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ export class VitestExecutor implements TestExecutor {
}

private async initializeVitest(): Promise<Vitest> {
const { coverage, reporters, outputFile, workspaceRoot, browsers, debug, watch } = this.options;
const {
coverage,
reporters,
outputFile,
workspaceRoot,
browsers,
debug,
watch,
browserViewport,
} = this.options;
let vitestNodeModule;
try {
vitestNodeModule = await loadEsmModule<typeof import('vitest/node')>('vitest/node');
Expand All @@ -146,6 +155,7 @@ export class VitestExecutor implements TestExecutor {
browsers,
debug,
this.options.projectSourceRoot,
browserViewport,
);
if (browserOptions.errors?.length) {
throw new Error(browserOptions.errors.join('\n'));
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 @@ -26,6 +26,11 @@
},
"minItems": 1
},
"browserViewport": {
"description": "Specifies the browser viewport dimensions for browser-based tests in the format `widthxheight`.",
"type": "string",
"pattern": "^\\d+x\\d+$"
},
"include": {
"type": "array",
"items": {
Expand Down