Commit 331ebce
authored
chore(repo): stop update-package-json spec from writing to disk (#35395)
## Current Behavior
Running `nx run rollup:test` produces three unexpected writes to the
workspace root that are not declared as outputs:
- `dist/index.js/index.cjs.default.js`
- `dist/index.js/index.cjs.mjs`
- `dist/index.js/package.json`
These show up as sandbox violations because the spec file at
`packages/rollup/src/plugins/package-json/update-package-json.spec.ts`
is, in reality, writing to the filesystem during test runs:
1. `jest.spyOn(utils, 'writeJsonFile')` is used without
`.mockImplementation(...)`. `spyOn` wraps the function to record calls
but does not replace its behavior, so the real `writeJsonFile` runs and
writes `package.json`.
2. `update-package-json.ts` also calls `fs.writeFileSync` directly (for
the `.cjs.mjs` / `.cjs.default.js` CJS-interop shims), which the spec
never mocked at all.
Every run pollutes the workspace root with a `dist/index.js/` directory.
## Expected Behavior
Tests verify call arguments via the spies without touching the real
filesystem. No `dist/index.js/` directory is created, and the three
sandbox violations for `rollup:test` go away.
- All 11 `writeJsonFile` spies now use `.mockImplementation(() =>
undefined)`.
- A `beforeEach` / `afterEach` adds a `jest.spyOn(fs,
'writeFileSync').mockImplementation(() => undefined)` using
`require('fs')` so the spy lands on the real fs module (using `import *
as fs from 'fs'` would go through `esModuleInterop`'s `__importStar`
copy and miss the call site in `update-package-json.ts`).
- Assertions continue to work — `toHaveBeenCalledWith(...)` tracks calls
on spies with or without a mock implementation.
Verified: `nx test rollup --testPathPatterns=update-package-json.spec` →
11/11 passing, and no `dist/index.js/` is created during the run.
## Related Issue(s)
N/A — caught via the sandbox-violation report for `rollup:test`.1 parent 3027707 commit 331ebce
1 file changed
Lines changed: 48 additions & 11 deletions
Lines changed: 48 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
6 | 21 | | |
7 | 22 | | |
8 | 23 | | |
| |||
16 | 31 | | |
17 | 32 | | |
18 | 33 | | |
19 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
20 | 37 | | |
21 | 38 | | |
22 | 39 | | |
| |||
45 | 62 | | |
46 | 63 | | |
47 | 64 | | |
48 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
49 | 68 | | |
50 | 69 | | |
51 | 70 | | |
| |||
70 | 89 | | |
71 | 90 | | |
72 | 91 | | |
73 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
74 | 95 | | |
75 | 96 | | |
76 | 97 | | |
| |||
100 | 121 | | |
101 | 122 | | |
102 | 123 | | |
103 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
104 | 127 | | |
105 | 128 | | |
106 | 129 | | |
| |||
142 | 165 | | |
143 | 166 | | |
144 | 167 | | |
145 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
146 | 171 | | |
147 | 172 | | |
148 | 173 | | |
| |||
163 | 188 | | |
164 | 189 | | |
165 | 190 | | |
166 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
167 | 194 | | |
168 | 195 | | |
169 | 196 | | |
| |||
183 | 210 | | |
184 | 211 | | |
185 | 212 | | |
186 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
187 | 216 | | |
188 | 217 | | |
189 | 218 | | |
| |||
203 | 232 | | |
204 | 233 | | |
205 | 234 | | |
206 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
207 | 238 | | |
208 | 239 | | |
209 | 240 | | |
| |||
233 | 264 | | |
234 | 265 | | |
235 | 266 | | |
236 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
237 | 270 | | |
238 | 271 | | |
239 | 272 | | |
| |||
261 | 294 | | |
262 | 295 | | |
263 | 296 | | |
264 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
265 | 300 | | |
266 | 301 | | |
267 | 302 | | |
| |||
289 | 324 | | |
290 | 325 | | |
291 | 326 | | |
292 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
293 | 330 | | |
294 | 331 | | |
295 | 332 | | |
| |||
0 commit comments