Skip to content

CHROME_BIN environment variable doesn't work for Vitest runner on build:unit-test #32697

@Naitronbot

Description

@Naitronbot

Command

test

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When using the Karma runner for @angular/build:unit-test, you can specify the path that the chrome binary is located at using the CHROME_BIN environment-variable.

CHROME_BIN="/path/to/chrome" npx ng test

This functionality does not work on the Vitest runner, which will always look in ~/.cache/ms-playwright.

For the playwright provider, there is a hardcoded check for when CHROME_BIN contains "rules_browsers". When the CHROME_BIN path contains this string, specifying a custom binary path works.

https://github.com/angular/angular-cli/blob/main/packages/angular/build/src/builders/unit-test/runners/vitest/browser-provider.ts#L93

Minimal Reproduction

  1. (Optional) Use the NodeJS Docker image for a consistent environment
docker pull node:latest
docker run --rm -it -w /root node:latest bash
  1. Ensure AngularCLI is installed npm i -g @angular/cli
  2. Create a new project: ng new MyProject
    • cd MyProject
  3. Configure build:unit-test to use browser mode
    • Install playwright npm i -D @vitest/browser-playwright
    • Edit angular.json, add "ChromiumHeadless" as a browser target
"test": {
    "builder": "@angular/build:unit-test",
    "options": { "browsers": ["ChromiumHeadless"] }
}
  1. Install playwright chrome binary npx playwright install --with-deps
  2. Move playwright binary: mv ~/.cache/ms-playwright/ /root/playwright
  3. Run tests with CHROME_BIN pointing to new binary location CHROME_BIN="/root/playwright/chromium-1208/chrome-linux64/chrome" npx ng test
    • Note: you might need to change "1208" to whichever version of chromium playwright installs
  4. Observe the loader is still attempting to load the binary from /root/.cache
  5. Update the path to contain the string "rules_browsers": mv /root/playwright /root/rules_browsers
  6. Re-run the tests: CHROME_BIN="/root/rules_browsers/chromium-1208/chrome-linux64/chrome" npx ng test
  7. Observe tests pass

Exception or Error


Your Environment

Angular CLI       : 21.2.0
Angular           : 21.2.1
Node.js           : 25.8.0 (Unsupported)
Package Manager   : npm 11.11.0
Operating System  : linux x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 21.2.0            │ ^21.2.0           │
│ @angular/cli              │ 21.2.0            │ ^21.2.0           │
│ @angular/common           │ 21.2.1            │ ^21.2.0           │
│ @angular/compiler         │ 21.2.1            │ ^21.2.0           │
│ @angular/compiler-cli     │ 21.2.1            │ ^21.2.0           │
│ @angular/core             │ 21.2.1            │ ^21.2.0           │
│ @angular/forms            │ 21.2.1            │ ^21.2.0           │
│ @angular/platform-browser │ 21.2.1            │ ^21.2.0           │
│ @angular/router           │ 21.2.1            │ ^21.2.0           │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 5.9.3             │ ~5.9.2            │
│ vitest                    │ 4.0.18            │ ^4.0.8            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions