René's URL Explorer Experiment


Title: `@angular/build:unit-test` virtual `init-testbed.js` guards `initTestEnvironment()` behind a once-per-worker symbol → stale DomAdapter under vitest ≥4.0.5 + `isolate: false` · Issue #33047 · angular/angular-cli · GitHub

Open Graph Title: `@angular/build:unit-test` virtual `init-testbed.js` guards `initTestEnvironment()` behind a once-per-worker symbol → stale DomAdapter under vitest ≥4.0.5 + `isolate: false` · Issue #33047 · angular/angular-cli

X Title: `@angular/build:unit-test` virtual `init-testbed.js` guards `initTestEnvironment()` behind a once-per-worker symbol → stale DomAdapter under vitest ≥4.0.5 + `isolate: false` · Issue #33047 · angular/angular-cli

Description: This is a follow-up to the now-closed/auto-locked #32754 with the missing details. That issue was dismissed as potentially analog-specific because the reporter had @analogjs/vitest-angular in their deps. This report uses @angular/build:u...

Open Graph Description: This is a follow-up to the now-closed/auto-locked #32754 with the missing details. That issue was dismissed as potentially analog-specific because the reporter had @analogjs/vitest-angular in their...

X Description: This is a follow-up to the now-closed/auto-locked #32754 with the missing details. That issue was dismissed as potentially analog-specific because the reporter had @analogjs/vitest-angular in their...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`@angular/build:unit-test` virtual `init-testbed.js` guards `initTestEnvironment()` behind a once-per-worker symbol → stale DomAdapter under vitest ≥4.0.5 + `isolate: false`","articleBody":"> This is a follow-up to the now-closed/auto-locked [#32754](https://github.com/angular/angular-cli/issues/32754) with the missing details. That issue was dismissed as potentially analog-specific because the reporter had `@analogjs/vitest-angular` in their deps. This report uses **`@angular/build:unit-test` only** and pins the bug to specific lines in `@angular/build`'s own source.\n\n### Which `@angular/*` package(s) are the source of the bug?\n\n`@angular/build`\n\n### Is this a regression?\n\nYes — surfaces with vitest ≥4.0.5 (see vitest-dev/vitest#8944).\n\n### Description\n\n`@angular/build:unit-test`'s vitest runner combines two defaults that interact badly under vitest ≥4.0.5:\n\n- [`plugins.ts:254`](https://github.com/angular/angular-cli/blob/main/packages/angular/build/src/builders/unit-test/runners/vitest/plugins.ts#L254) hardcodes `isolate: false` for the vitest pool (intentional, \"align with the Karma/Jasmine experience\"). Worker module graphs are therefore reused across spec files.\n- [`build-options.ts:73-89`](https://github.com/angular/angular-cli/blob/main/packages/angular/build/src/builders/unit-test/runners/vitest/build-options.ts#L73) — the injected virtual `init-testbed.js` wraps `getTestBed().initTestEnvironment(...)` in an `if (!globalThis[ANGULAR_TESTBED_SETUP])` guard. The comment on line 79 explicitly says *\"the guard condition above ensures that the setup is only performed once\"*. That's the anti-pattern.\n\nThe first spec file in a worker initializes a `platformBrowserTesting` whose `DomAdapter` captures the jsdom `document` as a closure reference. Subsequent spec files in the same worker skip the init block entirely, so the `DomAdapter` keeps being reused. When jsdom's document swaps between spec files — and vitest ≥4.0.5 no longer re-executes setup files between spec files under `isolate: false` (vitest-dev/vitest#8944) — `_getDOM().getDefaultDocument().createElement(tagName)` returns something that is not a real `HTMLElement`, and `DOMTestComponentRenderer.insertRootElement` crashes:\n\n\\`\\`\\`\nTypeError: rootElement.setAttribute is not a function\n  at DOMTestComponentRenderer.insertRootElement (@angular/platform-browser/testing)\n  at _TestBedImpl.createComponent\n\\`\\`\\`\n\nDifferent spec files fail each run; each failing spec passes in isolation. Classic test-isolation bug.\n\nThe analog project had the analogous pattern in `setupTestBed()` and fixed it in [analogjs/analog#2244](https://github.com/analogjs/analog/pull/2244) by calling `resetTestEnvironment()` + `initTestEnvironment()` on every setup invocation instead of guarding with a once-only singleton.\n\n### Reproduction\n\nI can put up a public minimal repro if helpful, but the bug is visible from the builder source alone — the conditions are:\n\n- Angular 22 (or 21 with vitest ≥4.0.5) monorepo using `@angular/build:unit-test` with jsdom.\n- `runnerConfig` unset, so the builder's default `isolate: false` applies.\n- Suite of ~50+ spec files to make the race frequent.\n- Run `ng test --force` (or equivalent) several times. A different 1–10 specs crash each run with the `setAttribute` trace.\n\nConfirmed environment:\n\n\\`\\`\\`\nAngular CLI:      22.0.0-next.6\n@angular/build:   22.0.0-next.6\n@angular/core:    22.0.0-next.9\nvitest:           4.1.4 (via ^4.0.17)\nEnvironment:      jsdom\nRuntime:          Node 22 / Bun 1.x\nOS:               Windows 11 (also reported on Ubuntu CI via analogjs/analog#2222)\n\\`\\`\\`\n\n### Exception\n\n\\`\\`\\`\nTypeError: rootElement.setAttribute is not a function\n  ❯ DOMTestComponentRenderer.insertRootElement node_modules/@angular/platform-browser/fesm2022/testing.mjs:24\n  ❯ _TestBedImpl.createComponent packages/core/testing/src/test_bed.ts:420\n\\`\\`\\`\n\n(The #32754 variant `Cannot set base providers because it has already been called` is the same root cause but a different downstream symptom — it fires when the user's own `test-setup.ts` re-calls `initTestEnvironment`. Projects that don't re-call it land on `setAttribute is not a function` instead.)\n\n### Proposed fix\n\n**Primary** — mirror [analogjs/analog#2244](https://github.com/analogjs/analog/pull/2244). Replace the `if (!globalThis[ANGULAR_TESTBED_SETUP])` guard in `build-options.ts:73-89` with a reset-and-reinit pattern:\n\n\\`\\`\\`ts\ngetTestBed().resetTestEnvironment();\ngetTestBed().initTestEnvironment([BrowserTestingModule, TestModule], platformBrowserTesting(), {\n  errorOnUnknownElements: true,\n  errorOnUnknownProperties: true,\n  // ...\n});\n\\`\\`\\`\n\nEven under `isolate: false`, if the setup file re-runs (or a user hook calls it), each spec file gets a fresh platform targeting the current jsdom.\n\n**Secondary (defensive)** — either flip the default to `isolate: true` with a documented opt-out for projects that want the Karma-style speed, or make `DOMTestComponentRenderer.insertRootElement` throw a clearer error when `rootElement.setAttribute` is not callable (e.g. *\"TestBed's DOM adapter is referencing a document that has been torn down — check your vitest \\`isolate\\` setting\"*). Today the `TypeError` has no breadcrumb to the root cause.\n\n**Docs** — the unit-test builder docs should warn that `isolate: false` + vitest ≥4.0.5 + jsdom silently bleeds DOM state across spec files.\n\n### Local workaround\n\nOverride to `isolate: true` via a project-level `vitest-base.config.ts` (possible because `runnerConfig: true` merges user config on top of the builder defaults). 10 consecutive `ng test --force` runs then pass deterministically. Wall-time cost is ~10–30%. This is a workaround, not a fix — the builder's guard is what should change.\n\n### References\n\n- [vitest-dev/vitest#8944](https://github.com/vitest-dev/vitest/issues/8944) — vitest 4.0.5 regression that triggers this class of flake.\n- [angular/angular-cli#32754](https://github.com/angular/angular-cli/issues/32754) — closed/auto-locked predecessor of this report. Same root cause, different surface symptom, closed as \"insufficient information.\"\n- [analogjs/analog#2222](https://github.com/analogjs/analog/issues/2222) — same error stack downstream in analog's vitest-angular stack.\n- [analogjs/analog#2244](https://github.com/analogjs/analog/pull/2244) — reference fix pattern.","author":{"url":"https://github.com/michael-dg","@type":"Person","name":"michael-dg"},"datePublished":"2026-04-24T09:24:33Z","url":"https://github.com/angular/angular-cli/issues/33047"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:60211fd2-50a0-3c3e-6303-69ab0c429bcf
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9510:8AE25:11B0C2B:1775B86:6B01E84B
html-safe-nonce81437fd0882ed7e7efb67590caffbd601ff814a21912df48398eff8c601275fd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTEwOjhBRTI1OjExQjBDMkI6MTc3NUI4Njo2QjAxRTg0QiIsInZpc2l0b3JfaWQiOiIyNDg2OTI5NTE4MDg2OTczNTE1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac522fa93c9455687ec7908e2a12aae814aea241e440b4ce7379ba74f86b7ebd84
hovercard-subject-tagissue:4321949093
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/33047/issue_layout
twitter:imagehttps://opengraph.githubassets.com/db166c23b2f264a51a0113e2bc8aceb9347fa3785c881f797da8692a6c0db96e/angular/angular-cli/issues/33047
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/db166c23b2f264a51a0113e2bc8aceb9347fa3785c881f797da8692a6c0db96e/angular/angular-cli/issues/33047
og:image:altThis is a follow-up to the now-closed/auto-locked #32754 with the missing details. That issue was dismissed as potentially analog-specific because the reporter had @analogjs/vitest-angular in their...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemichael-dg
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular-cli/issues/33047#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular-cli%2Fissues%2F33047
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular-cli%2Fissues%2F33047
Sign uphttps://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/33047
Reloadhttps://github.com/angular/angular-cli/issues/33047
Reloadhttps://github.com/angular/angular-cli/issues/33047
angularhttps://github.com/angular
angular-clihttps://github.com/angular/angular-cli
Codehttps://github.com/angular/angular-cli
Issues198 (198)https://github.com/angular/angular-cli/issues
Pull requests23 (23)https://github.com/angular/angular-cli/pulls
Actionshttps://github.com/angular/angular-cli/actions
Security and quality8 (8)https://github.com/angular/angular-cli/security
Insightshttps://github.com/angular/angular-cli/insights
https://github.com/angular/angular-cli
New issuehttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/33047
New issuehttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/33047
@angular/build:unit-test virtual init-testbed.js guards initTestEnvironment() behind a once-per-worker symbol → stale DomAdapter under vitest ≥4.0.5 + isolate: falsehttps://github.com/angular/angular-cli/issues/33047#top
angular/build:unit-testhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22angular%2Fbuild%3Aunit-test%22
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
https://github.com/michael-dg
michael-dghttps://github.com/michael-dg
on Apr 24, 2026https://github.com/angular/angular-cli/issues/33047#issue-4321949093
#32754https://github.com/angular/angular-cli/issues/32754
vitest-dev/vitest#8944https://github.com/vitest-dev/vitest/issues/8944
plugins.ts:254https://github.com/angular/angular-cli/blob/main/packages/angular/build/src/builders/unit-test/runners/vitest/plugins.ts#L254
build-options.ts:73-89https://github.com/angular/angular-cli/blob/main/packages/angular/build/src/builders/unit-test/runners/vitest/build-options.ts#L73
vitest-dev/vitest#8944https://github.com/vitest-dev/vitest/issues/8944
analogjs/analog#2244https://github.com/analogjs/analog/pull/2244
analogjs/analog#2222https://github.com/analogjs/analog/issues/2222
#32754https://github.com/angular/angular-cli/issues/32754
analogjs/analog#2244https://github.com/analogjs/analog/pull/2244
vitest-dev/vitest#8944https://github.com/vitest-dev/vitest/issues/8944
angular/angular-cli#32754https://github.com/angular/angular-cli/issues/32754
analogjs/analog#2222https://github.com/analogjs/analog/issues/2222
analogjs/analog#2244https://github.com/analogjs/analog/pull/2244
angular-robothttps://github.com/apps/angular-robot
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
on Apr 24, 2026https://github.com/angular/angular-cli/issues/33047#event-24831295252
clydinhttps://github.com/clydin
angular/build:unit-testhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22angular%2Fbuild%3Aunit-test%22
on Aug 13, 2026https://github.com/angular/angular-cli/issues/33047#event-29424319142
mikalai-adamovichhttps://github.com/mikalai-adamovich
on Aug 30, 2026https://github.com/angular/angular-cli/issues/33047#event-30247184607
test(ui): migrate suite to canonical zoneless pattern, fix flaky testshttps://github.com/mikalai-adamovich/task-board/commit/dcb4de37da9a61a9d7f62f05a9fb961fa0a3546a
dcb4de3https://github.com/mikalai-adamovich/task-board/commit/dcb4de37da9a61a9d7f62f05a9fb961fa0a3546a
test(ui): isolate spec files, pin @angular/build 22.1.2https://github.com/mikalai-adamovich/task-board/commit/eb4069918bec93d037a75a140f91c2ea55914a0b
eb40699https://github.com/mikalai-adamovich/task-board/commit/eb4069918bec93d037a75a140f91c2ea55914a0b
https://github.com/clydin
clydinhttps://github.com/clydin
on Oct 28, 2026https://github.com/angular/angular-cli/issues/33047#issuecomment-6474578661
clydinhttps://github.com/clydin
completedhttps://github.com/angular/angular-cli/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Oct 28, 2026https://github.com/angular/angular-cli/issues/33047#event-34496381533
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular-cli/issues/33047
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/33047
angular/build:unit-testhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22angular%2Fbuild%3Aunit-test%22
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
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.