Commit b58b88d
committed
refactor(test): swap sinon for vitest's native vi.fn / vi.spyOn
Replaces ~1,500 sinon call sites across 45 test files with vitest's
native mocking API. Drops `sinon` + `@types/sinon` devDeps from
pure-vitest packages. Hybrid packages (sdk, rebalancer, cli, infra,
svm-sdk, tron-sdk, relayer) keep sinon for hardhat/e2e paths that
stay on mocha.
## Mapping
### Stubs / spies
- `sinon.stub()` → `vi.fn()`
- `sinon.stub(obj, 'm')` → `vi.spyOn(obj, 'm').mockImplementation(...)`
- `sinon.spy(obj, 'm')` → `vi.spyOn(obj, 'm')`
- `.returns(x)` → `.mockReturnValue(x)`
- `.resolves(x)` → `.mockResolvedValue(x)` (argument now required —
`.mockResolvedValue(undefined)` for void-returning stubs)
- `.rejects(err)` → `.mockRejectedValue(err)`
- `.callsFake(fn)` → `.mockImplementation(fn)`
- `.onFirstCall().X()` / `.onSecondCall().X()` chains →
`.mockXOnce(...).mockXOnce(...)`
### Assertions
- `sinon.assert.calledOnce(s)` → `expect(s).toHaveBeenCalledOnce()`
- `sinon.assert.calledTwice(s)` → `expect(s).toHaveBeenCalledTimes(2)`
- `sinon.assert.callCount(s, n)` → `expect(s).toHaveBeenCalledTimes(n)`
- `sinon.assert.calledWith(s, ...args)` → `expect(s).toHaveBeenCalledWith(...args)`
- `sinon.assert.calledOnceWithExactly(s, ...a)` →
`expect(s).toHaveBeenCalledExactlyOnceWith(...a)`
- `sinon.assert.calledWithMatch(s, obj)` →
`expect(s).toHaveBeenCalledWith(expect.objectContaining(obj))`
- `sinon.assert.notCalled(s)` → `expect(s).not.toHaveBeenCalled()`
- `s.callCount` → `s.mock.calls.length`
- `s.firstCall.args[n]` / `s.getCall(n).args[m]` → `s.mock.calls[n][m]`
- `s.returnValues[n]` → `s.mock.results[n].value`
### Matchers
- `sinon.match.any` → `expect.anything()`
- `sinon.match.string` → `expect.any(String)`
- `sinon.match.object` → `expect.any(Object)` / `expect.objectContaining(...)`
### Sandbox lifecycle
7 files in sdk previously used `sandbox = sinon.createSandbox()` +
`sandbox.stub(...)` + `sandbox.restore()`. Converted to direct
`vi.spyOn(...)` calls with `afterEach(() => vi.restoreAllMocks())`.
### Fake timers (11 sites in http-registry-server)
- `sinon.useFakeTimers({ now: date })` → `vi.useFakeTimers({ now: date })`
- `clock.tick(ms)` → `vi.advanceTimersByTime(ms)`
- `clock.restore()` → `vi.useRealTimers()`
- The local `clock` variable is dropped — vitest uses module-level
`vi` accessors.
### Restoration
- `sinon.restore()` → `vi.restoreAllMocks()`
- `stub.restore()` → `stub.mockRestore()`
- `stub.resetHistory()` → `stub.mockClear()`
- `stub.reset()` → `stub.mockReset()`
### Types
- `sinon.SinonStub` → `MockInstance` from `vitest`
- `sinon.SinonStub<[Args], Ret>` → `MockInstance<(...args: Args) => Ret>`
- `sinon.SinonSandbox` — removed (no vitest equivalent)
- `sinon.SinonFakeTimers` — removed (vi is module-level)
## Tricky patterns
### `sinon.createStubInstance(Class)` (http-registry-server, rebalancer, keyfunder)
Replaced with hand-rolled partial mocks typed as the class interface:
```ts
// Before: const mock = sinon.createStubInstance(Registry);
// After:
const mock = { getUri: vi.fn(), getChains: vi.fn(), ... } as unknown as IRegistry;
```
For MultiProvider/MultiProtocolProvider (rebalancer) a prototype-walking
helper auto-mocks every prototype method with `vi.fn()`.
### `.withArgs(x).returns(y)` (rebalancer, cli)
No vitest equivalent. Replaced with a single `mockImplementation` that
branches on the argument:
```ts
vi.fn(async (id) => routes[id]?.coreConfig)
```
### Typed factory pattern for mock objects (rebalancer)
`createMockActionTracker()` now returns a mapped type
`{ [K in keyof IActionTracker]: Mock<IActionTracker[K]> }` so callers
can invoke `actionTracker.syncTransfers.mockRejectedValue(err)` without
casts.
### `IExternalBridge` mock (rebalancer)
`bridge: any` retained in `InventoryRebalancer.test.ts` — the existing
pre-migration typing. Downstream annotations use targeted `unknown[]`
+ narrow `as QuoteParams` rather than `any` for `.mock.calls` access.
### `getChainMetadata` stub (rebalancer RebalancerContextFactory)
SUT reads only `.protocol` off the return. Rather than fabricating a
full `ChainMetadata`, cast the partial return `as unknown as ChainMetadata`
to make the mock's intent explicit.
## cli setup file fix
Previous PR deleted `vitest.setup.ts` but the cli's `vitest.config.ts`
still referenced it. Dropped the `../../vitest.setup.ts` entry from
cli's setupFiles — only `./src/tests/test-setup.ts` remains.
## devDeps dropped (pure-vitest packages)
ccip-server, deploy-sdk, http-registry-server, keyfunder, metrics,
provider-sdk (no sinon usage), utils, warp-monitor.
Hybrid packages retain `sinon` + `@types/sinon` for hardhat/e2e:
sdk, rebalancer, cli, infra, svm-sdk, tron-sdk, relayer.
Catalog: `sinon` and `@types/sinon` entries retained (still used by
hybrid packages' mocha-run test paths).
## Tests
All 1,654+ migrated vitest tests pass. `pnpm build` green at repo root.
`pnpm format:check` + `pnpm lint` clean.1 parent 962904f commit b58b88d
38 files changed
Lines changed: 1817 additions & 1794 deletions
File tree
- typescript
- ccip-server
- tests/services
- cli/src
- deploy
- tests/context
- keyfunder
- src
- config
- core
- rebalancer/src
- core
- factories
- tracking
- utils
- sdk/src
- gas
- hook
- ism
- middleware/account
- predicate
- providers
- test
- token
- adapters
- warp
- svm-sdk/src/tests
- utils
- src
- warp-monitor
- src
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
61 | | - | |
62 | 60 | | |
63 | 61 | | |
64 | 62 | | |
| |||
Lines changed: 28 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
21 | 20 | | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
116 | | - | |
117 | | - | |
| 117 | + | |
| 118 | + | |
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
123 | | - | |
| 124 | + | |
124 | 125 | | |
125 | 126 | | |
126 | | - | |
127 | | - | |
| 127 | + | |
| 128 | + | |
128 | 129 | | |
129 | 130 | | |
130 | | - | |
| 131 | + | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
138 | | - | |
| 138 | + | |
| 139 | + | |
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
143 | | - | |
144 | | - | |
145 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| |||
153 | 154 | | |
154 | 155 | | |
155 | 156 | | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
48 | 47 | | |
49 | 48 | | |
50 | 49 | | |
51 | | - | |
52 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
53 | 56 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 57 | + | |
| 58 | + | |
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
| |||
87 | 85 | | |
88 | 86 | | |
89 | 87 | | |
90 | | - | |
| 88 | + | |
91 | 89 | | |
92 | 90 | | |
93 | 91 | | |
| |||
137 | 135 | | |
138 | 136 | | |
139 | 137 | | |
140 | | - | |
| 138 | + | |
141 | 139 | | |
142 | 140 | | |
143 | 141 | | |
144 | 142 | | |
145 | 143 | | |
146 | 144 | | |
147 | 145 | | |
148 | | - | |
149 | | - | |
| 146 | + | |
| 147 | + | |
150 | 148 | | |
151 | 149 | | |
152 | 150 | | |
| |||
155 | 153 | | |
156 | 154 | | |
157 | 155 | | |
158 | | - | |
| 156 | + | |
159 | 157 | | |
160 | 158 | | |
161 | 159 | | |
| |||
Lines changed: 19 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | | - | |
| 62 | + | |
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
| |||
213 | 212 | | |
214 | 213 | | |
215 | 214 | | |
216 | | - | |
217 | | - | |
218 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
219 | 218 | | |
220 | 219 | | |
221 | 220 | | |
| |||
235 | 234 | | |
236 | 235 | | |
237 | 236 | | |
238 | | - | |
| 237 | + | |
239 | 238 | | |
240 | 239 | | |
241 | 240 | | |
| |||
244 | 243 | | |
245 | 244 | | |
246 | 245 | | |
247 | | - | |
| 246 | + | |
248 | 247 | | |
249 | 248 | | |
250 | 249 | | |
| |||
272 | 271 | | |
273 | 272 | | |
274 | 273 | | |
275 | | - | |
| 274 | + | |
276 | 275 | | |
277 | 276 | | |
278 | 277 | | |
279 | 278 | | |
280 | | - | |
| 279 | + | |
281 | 280 | | |
282 | 281 | | |
283 | 282 | | |
| |||
306 | 305 | | |
307 | 306 | | |
308 | 307 | | |
309 | | - | |
| 308 | + | |
310 | 309 | | |
311 | 310 | | |
312 | 311 | | |
313 | 312 | | |
314 | | - | |
315 | | - | |
316 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
317 | 316 | | |
318 | 317 | | |
319 | 318 | | |
| |||
341 | 340 | | |
342 | 341 | | |
343 | 342 | | |
344 | | - | |
| 343 | + | |
345 | 344 | | |
346 | 345 | | |
347 | 346 | | |
| |||
354 | 353 | | |
355 | 354 | | |
356 | 355 | | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
363 | 360 | | |
364 | 361 | | |
365 | 362 | | |
| |||
373 | 370 | | |
374 | 371 | | |
375 | 372 | | |
376 | | - | |
| 373 | + | |
377 | 374 | | |
378 | 375 | | |
379 | 376 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | 54 | | |
56 | 55 | | |
57 | | - | |
58 | 56 | | |
59 | 57 | | |
60 | 58 | | |
| |||
0 commit comments