Commit 66df977
authored
Fix sinon.restore() cascade-restoring sub-sandboxes (#2704)
The ESM port of `createApi` (#2683, shipped in 21.1.0) replaced `createSandbox: createSandbox` with a wrapper that pushes every newly-created sandbox into the root sandbox's fake collection:
createSandbox: function createSandbox(config) {
const s = createConfiguredSandbox(config);
sandbox.getFakes().push(s);
return s;
}
`Sandbox#restore` then walks that collection and calls `.restore()` on each entry. Because a sub-sandbox is itself an entry, every top-level `sinon.restore()` cascades into every sub-sandbox and undoes its stubs/timers/etc. — defeating the whole point of having an isolated sub-sandbox. The same cascade hits `resetHistory` and
`verifyAndRestore`. This is the regression reported in #2701.
Restore the pre-21.1 behaviour: hand the root API a direct reference to `createConfiguredSandbox`. Sub-sandboxes are now isolated; only `subSandbox.restore()` (or `verifyAndRestore`) clears their fakes.
Also flip the four sandbox tests that were locking in the buggy cascade: they now assert the parent's restore/resetHistory leaves the child untouched, with an explicit child-side cleanup at the
end.
Closes #27011 parent f0bd6e1 commit 66df977
3 files changed
Lines changed: 40 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
25 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
26 | 40 | | |
27 | 41 | | |
28 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2048 | 2048 | | |
2049 | 2049 | | |
2050 | 2050 | | |
2051 | | - | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
2052 | 2056 | | |
2053 | 2057 | | |
2054 | 2058 | | |
| |||
2059 | 2063 | | |
2060 | 2064 | | |
2061 | 2065 | | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
2062 | 2069 | | |
2063 | 2070 | | |
2064 | 2071 | | |
2065 | | - | |
| 2072 | + | |
2066 | 2073 | | |
2067 | 2074 | | |
2068 | 2075 | | |
| |||
2073 | 2080 | | |
2074 | 2081 | | |
2075 | 2082 | | |
2076 | | - | |
| 2083 | + | |
2077 | 2084 | | |
2078 | 2085 | | |
2079 | | - | |
| 2086 | + | |
2080 | 2087 | | |
2081 | 2088 | | |
2082 | 2089 | | |
| |||
2087 | 2094 | | |
2088 | 2095 | | |
2089 | 2096 | | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
2090 | 2100 | | |
2091 | 2101 | | |
2092 | 2102 | | |
2093 | | - | |
| 2103 | + | |
2094 | 2104 | | |
2095 | 2105 | | |
2096 | 2106 | | |
| |||
2101 | 2111 | | |
2102 | 2112 | | |
2103 | 2113 | | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
2104 | 2117 | | |
2105 | 2118 | | |
2106 | 2119 | | |
| |||
0 commit comments