Commit b1ce21d
committed
fix(@angular/build): dynamically select Vitest DOM environment
This change enhances the Vitest unit test builder to intelligently select the default DOM test environment (`jsdom` or `happy-dom`) based on which package is installed in the user's project.
Previously, the builder strictly defaulted to `jsdom`. With this update:
- The `validateDependencies` function now checks for the presence of either `jsdom` or `happy-dom` when browser-based tests are not configured, providing a more flexible dependency requirement.
- A new `findTestEnvironment` helper function is introduced to detect the available DOM environment (`happy-dom` is preferred if installed, otherwise `jsdom`).
- The `createVitestConfigPlugin` now uses this helper to dynamically set the `environment` in the Vitest configuration, ensuring a smart default if the user has not explicitly specified one.
This improves the out-of-the-box experience by adapting to common project setups and offering more choice in DOM emulation.1 parent d6b3074 commit b1ce21d
File tree
3 files changed
+36
-5
lines changed- packages/angular/build/src/builders/unit-test/runners/vitest
3 files changed
+36
-5
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
| |||
Lines changed: 30 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
45 | 60 | | |
46 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
47 | 70 | | |
48 | 71 | | |
49 | 72 | | |
50 | 73 | | |
51 | 74 | | |
52 | 75 | | |
| 76 | + | |
| 77 | + | |
53 | 78 | | |
54 | 79 | | |
55 | 80 | | |
| |||
58 | 83 | | |
59 | 84 | | |
60 | 85 | | |
61 | | - | |
62 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
63 | 90 | | |
64 | 91 | | |
65 | 92 | | |
| |||
0 commit comments