Commit 61e25fb
fix(@angular/build): load zone.js dynamically for library unit tests
When unit testing library targets with the unit-test builder, the build
target (ng-packagr) does not have a 'polyfills' configuration. This
caused the builder to fall back to the 'dynamic' zone testing strategy,
which only dynamically imports zone.js/testing at runtime if Zone is
already defined. Since the main zone.js library was never loaded, Zone
was undefined, and library tests relying on TestBed/fakeAsync failed.
This commit introduces a new 'dynamic-zone' zone testing strategy. If
polyfills is undefined (meaning we are running a library target) and
zone.js is installed/resolvable, both zone.js and zone.js/testing are
dynamically imported at startup, resolving the failure.
Fixes #334771 parent 2d3eb7f commit 61e25fbCopy full SHA for 61e25fb
2 files changed
+56-3Lines changed: 56 additions & 3 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- packages/angular/build/src/builders/unit-test
- runners/vitest
- tests/behavior
Expand file treeCollapse file tree
Open diff view settings
Collapse file
packages/angular/build/src/builders/unit-test/runners/vitest/build-options.ts
Copy file name to clipboardExpand all lines: packages/angular/build/src/builders/unit-test/runners/vitest/build-options.ts+13-3Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
33 | 33 | |
34 | 34 | |
35 | 35 | |
36 | | - |
| 36 | + |
37 | 37 | |
38 | 38 | |
39 | 39 | |
| ||
53 | 53 | |
54 | 54 | |
55 | 55 | |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
56 | 60 | |
57 | 61 | |
58 | 62 | |
| ||
150 | 154 | |
151 | 155 | |
152 | 156 | |
153 | | - |
| 157 | + |
154 | 158 | |
155 | 159 | |
156 | 160 | |
157 | 161 | |
158 | | - |
| 162 | + |
159 | 163 | |
160 | 164 | |
161 | 165 | |
| ||
168 | 172 | |
169 | 173 | |
170 | 174 | |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | + |
171 | 181 | |
172 | 182 | |
173 | 183 | |
|
Collapse file
packages/angular/build/src/builders/unit-test/tests/behavior/vitest-zone-init_spec.ts
Copy file name to clipboardExpand all lines: packages/angular/build/src/builders/unit-test/tests/behavior/vitest-zone-init_spec.ts+43Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
67 | 67 | |
68 | 68 | |
69 | 69 | |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
70 | 113 | |
71 | 114 | |
0 commit comments