René's URL Explorer Experiment


Title: unit-test (vitest): isolate:false default silently breaks cross-file vi.mock() of shared modules on low-CPU workers · Issue #33570 · angular/angular-cli · GitHub

Open Graph Title: unit-test (vitest): isolate:false default silently breaks cross-file vi.mock() of shared modules on low-CPU workers · Issue #33570 · angular/angular-cli

X Title: unit-test (vitest): isolate:false default silently breaks cross-file vi.mock() of shared modules on low-CPU workers · Issue #33570 · angular/angular-cli

Description: Which @angular/* package(s) are the source of the bug? build Is this a regression? No Description @angular/build:unit-test (Vitest runner) sets test.isolate: false by default (to match the historical Karma/Jasmine experience — src/builde...

Open Graph Description: Which @angular/* package(s) are the source of the bug? build Is this a regression? No Description @angular/build:unit-test (Vitest runner) sets test.isolate: false by default (to match the historic...

X Description: Which @angular/* package(s) are the source of the bug? build Is this a regression? No Description @angular/build:unit-test (Vitest runner) sets test.isolate: false by default (to match the historic...

Opengraph URL: https://github.com/angular/angular-cli/issues/33570

X: @github

direct link

Domain: Github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"unit-test (vitest): isolate:false default silently breaks cross-file vi.mock() of shared modules on low-CPU workers","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\nbuild\n\n### Is this a regression?\n\nNo\n\n### Description\n\n`@angular/build:unit-test` (Vitest runner) sets **`test.isolate: false`** by default (to match the historical Karma/Jasmine experience — `src/builders/unit-test/runners/vitest/plugins.js`, and again in `executor.js`). Combined with the builder's pre-bundled test entry points that **share esbuild chunks**, this silently breaks `vi.mock()` of a bare (node_modules) module across spec files that land on the same worker.\n\n**Mechanism**\n\n1. Each spec is pre-bundled by esbuild. A component/service imported by more than one spec is hoisted into a **shared chunk** (`chunk-*.js`), and third-party packages are kept external (`externalPackages: true`).\n2. With `isolate: false`, Vitest **reuses a worker (and its module registry) across spec files**.\n3. Spec **A** and spec **B** both `vi.mock('some-pkg', factory)` (different factories) and both import the same shared component that imports `some-pkg`. Whichever spec runs **first** on a worker instantiates the shared chunk bound to **its** mock. When the other spec later runs on the same worker, the cached shared-chunk module is reused, so **its own `vi.mock('some-pkg')` never intercepts the component's import** — its mock handles stay empty while the component silently runs against the *first* spec's mock (or the real module).\n\nBecause Vitest's worker count follows `os.availableParallelism()`, the failure is **CPU-count dependent**: green on high-core dev machines / CI, but **deterministically red on low-core CI runners** (e.g. a 2-vCPU Kubernetes/ARC pod), where many spec files share each worker in a stable, size-ordered sequence. This makes it a nasty \"works on my machine / fails only on constrained CI\" trap.\n\n### Minimal reproduction\n\nConditions (no third-party lib needed — any bare module works):\n\n- `pkg` — a trivial node_modules package exporting a factory function, e.g. `makeThing()`.\n- `SharedCmp` — a standalone component that imports `pkg` and calls `makeThing()` in `ngAfterViewInit`.\n- `a.spec.ts` — `vi.mock('pkg', () =\u003e ({ makeThing: () =\u003e handlesA }))`, imports `SharedCmp` (e.g. via a page that renders it), asserts against `handlesA`.\n- `b.spec.ts` — `vi.mock('pkg', () =\u003e ({ makeThing: () =\u003e handlesB }))`, creates `SharedCmp` directly, asserts against `handlesB`.\n\nRun `ng test` with the two specs while constraining workers so both files share one worker (e.g. on a 2-CPU machine, or `VITEST_MAX_THREADS=1`), with `a.spec.ts` scheduled before `b.spec.ts`. `b.spec.ts`'s assertions fail because `SharedCmp` is bound to `handlesA` (or the real module), and `handlesB` is never called. Adding a project `vitest-base.config.ts` with `test: { isolate: true }` (via `\"runnerConfig\": true`) makes both pass.\n\n### Exception or Error\n\n```\nNo thrown error — the component runs against the wrong (foreign) mock instance.\nSymptom: the later spec's own mock handles are never invoked\n(e.g. \"expected 1, got 0\" / \"undefined is not a spy\"), only on low-CPU workers.\n```\n\n### Your Environment\n\n```\n@angular/build: 21.2.12\nvitest: 4.1.7\nNode: 24.15.0\nRunner: vitest (unit-test builder), jsdom environment\nRepro trigger: low worker count (2-vCPU CI runner) — deterministic;\nhigh-core machines mask it.\n```\n\n### Anything else relevant?\n\n**Workaround (works):** opt into an external runner config and re-enable isolation —\n\n`angular.json`:\n```json\n\"test\": {\n  \"builder\": \"@angular/build:unit-test\",\n  \"options\": { \"runnerConfig\": true }\n}\n```\n`vitest-base.config.ts`:\n```ts\nimport { defineConfig } from 'vitest/config';\nexport default defineConfig({ test: { isolate: true } });\n```\n\n**Suggested fixes for consideration:**\n- Document prominently that `vi.mock()` of shared/bare modules is unsafe under the default `isolate: false` (the current in-repo guard only rejects *relative* `vi.mock` paths — `angular:vitest-mock-patch` — but bare-specifier mocks are the ones that break cross-file).\n- Consider detecting `vi.mock` usage and warning (or auto-isolating) when specs share chunks, or make isolation the default for the Vitest runner.\n\nHappy to package a StackBlitz/minimal repo if that would help triage.\n","author":{"url":"https://github.com/rommelandrea","@type":"Person","name":"rommelandrea"},"datePublished":"2026-07-15T06:10:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/33570/angular-cli/issues/33570"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:21686537-955a-d8f2-5509-4e16af87f548
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8298:E0378:54CFBA:747524:6A6274AB
html-safe-nonce417de73a8cc8b0add041edd74dc23385dceec07f0651424f899304207afab958
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Mjk4OkUwMzc4OjU0Q0ZCQTo3NDc1MjQ6NkE2Mjc0QUIiLCJ2aXNpdG9yX2lkIjoiNTMzNDAyMTc3NjE5NjQwMDI5OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac35e3ab63261f88024f654624228be6dea67881eb0ac9104edee1f29b7545d431
hovercard-subject-tagissue:4889826245
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/33570/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9d9923e74530bc347018d0f8ac2e3310e31be55fcedac08797f00f510d9d4d31/angular/angular-cli/issues/33570
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9d9923e74530bc347018d0f8ac2e3310e31be55fcedac08797f00f510d9d4d31/angular/angular-cli/issues/33570
og:image:altWhich @angular/* package(s) are the source of the bug? build Is this a regression? No Description @angular/build:unit-test (Vitest runner) sets test.isolate: false by default (to match the historic...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerommelandrea
hostnamegithub.com
expected-hostnamegithub.com
None838e87bd0e4f5415707a930bc14e89e382dc2ea046e50ff575252eb2f2cb06a2
turbo-cache-controlno-preview
go-importgithub.com/angular/angular-cli git https://github.com/angular/angular-cli.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id36891867
octolytics-dimension-repository_nwoangular/angular-cli
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id36891867
octolytics-dimension-repository_network_root_nwoangular/angular-cli
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef0081192f88523d2bf4cfdf22bb3e138affc4cd1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://Github.com/angular/angular-cli/issues/33570#start-of-content
https://Github.com/
Sign in https://Github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular-cli%2Fissues%2F33570
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://Github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular-cli%2Fissues%2F33570
Sign up https://Github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular-cli
Reloadhttps://Github.com/angular/angular-cli/issues/33570
Reloadhttps://Github.com/angular/angular-cli/issues/33570
Reloadhttps://Github.com/angular/angular-cli/issues/33570
Please reload this pagehttps://Github.com/angular/angular-cli/issues/33570
angular https://Github.com/angular
angular-clihttps://Github.com/angular/angular-cli
Notifications https://Github.com/login?return_to=%2Fangular%2Fangular-cli
Fork 11.9k https://Github.com/login?return_to=%2Fangular%2Fangular-cli
Star 27k https://Github.com/login?return_to=%2Fangular%2Fangular-cli
Code https://Github.com/angular/angular-cli
Issues 269 https://Github.com/angular/angular-cli/issues
Pull requests 29 https://Github.com/angular/angular-cli/pulls
Actions https://Github.com/angular/angular-cli/actions
Security and quality 5 https://Github.com/angular/angular-cli/security
Insights https://Github.com/angular/angular-cli/pulse
Code https://Github.com/angular/angular-cli
Issues https://Github.com/angular/angular-cli/issues
Pull requests https://Github.com/angular/angular-cli/pulls
Actions https://Github.com/angular/angular-cli/actions
Security and quality https://Github.com/angular/angular-cli/security
Insights https://Github.com/angular/angular-cli/pulse
unit-test (vitest): isolate:false default silently breaks cross-file vi.mock() of shared modules on low-CPU workershttps://Github.com/angular/angular-cli/issues/33570#top
area: @angular/buildhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22area%3A%20%40angular%2Fbuild%22
gemini-triagedLabel noting that an issue has been triaged by geminihttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22gemini-triaged%22
needsTriagehttps://github.com/angular/angular-cli/milestone/11
https://github.com/rommelandrea
rommelandreahttps://github.com/rommelandrea
on Jul 15, 2026https://github.com/angular/angular-cli/issues/33570#issue-4889826245
area: @angular/buildhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22area%3A%20%40angular%2Fbuild%22
gemini-triagedLabel noting that an issue has been triaged by geminihttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22gemini-triaged%22
needsTriageNo due datehttps://github.com/angular/angular-cli/milestone/11
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.