Skip to content

feat(@angular/build): add headless mode for vitest browser mode #30685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion packages/angular/build/src/builders/unit-test/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ function findBrowserProvider(
}
}

function normalizeBrowserName(browserName: string): string {
// Normalize browser names to match Vitest's expectations for headless but also supports karma's names
// e.g., 'ChromeHeadless' -> 'chrome', 'FirefoxHeadless'
// and 'Chrome' -> 'chrome', 'Firefox' -> 'firefox'.
const normalized = browserName.toLowerCase();

return normalized.replace(/headless$/, '');
}

function setupBrowserConfiguration(
browsers: string[] | undefined,
debug: boolean,
Expand Down Expand Up @@ -378,8 +387,10 @@ function setupBrowserConfiguration(
const browser = {
enabled: true,
provider,
headless: browsers.some((name) => name.toLowerCase().includes('headless')),

instances: browsers.map((browserName) => ({
browser: browserName,
browser: normalizeBrowserName(browserName),
Comment on lines +390 to +393
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalize browser names to match Vitest's expectations for headless but also supports karmas names
e.g., 'ChromeHeadless' -> 'chrome', 'FirefoxHeadless'
and 'Chrome' -> 'chrome', 'Firefox' -> 'firefox'.

and activates the vitest configuration property headless: true

})),
};

Expand Down