Skip to content

Commit 7cded72

Browse files
committed
refactor(test): swap chai assertions for vitest's native expect
Replaces ~3,400 chai assertions across 170 test files with vitest's native `expect` matchers. Unlocks vitest's diff rendering, snapshot testing, typed matchers, and drops chai/chai-as-promised devDeps from pure-vitest packages. ## Conversions (mechanical, per a shared mapping) - `to.equal` → `toBe`, `to.deep.equal` → `toEqual` - `to.be.true/false/null/undefined` → `toBe(true/false)`, `toBeNull`, `toBeUndefined` - `to.exist` → `toBeDefined` (each site verified — chai's .exist also checks truthy) - `to.have.length(Of)(n)` → `toHaveLength(n)` - `to.have.property(p[, v])` → `toHaveProperty(p[, v])` - `to.match(/r/)` → `toMatch(/r/)`, `to.include`/`to.contain` → `toContain` - `to.deep.include` → `toContainEqual` (arrays) or `toMatchObject` (objects) - `to.throw(msg)` → `toThrow(msg)` - `to.be.{greaterThan,at.least,at.most}` → `toBeGreaterThan(OrEqual)`, etc - `to.be.closeTo(x, delta)` → `toBeCloseTo(x, precision)` (2 sites; delta→precision) - `to.be.oneOf([...])` → swap sides: `expect([...]).toContain(x)` - `to.be.empty` → `toHaveLength(0)` - `to.be.a('type')` → `toBeTypeOf('type')` - `to.be.instanceOf(C)` → `toBeInstanceOf(C)` - `to.have.members(arr)` → `Set` equality - `to.include.members(arr)` → `expect.arrayContaining(arr)` ## chai-as-promised - `await expect(p).to.be.rejectedWith(msg)` → `await expect(p).rejects.toThrow(msg)` - 4× chained `rejectedWith(Err).and.eventually.have.property(...)` in http-registry-server restructured into `rejects.toThrow(...)` + `try/catch` with `expect(err).toBeInstanceOf(...)` + `expect(err).toHaveProperty(...)` - `.should.eventually.be.rejectedWith(...)` (1 site in infra/warp-configs) → `.rejects.toThrow(...)` - All `chai.use(chaiAsPromised)` and `import chaiAsPromised` lines removed - Shared root `vitest.setup.ts` deleted (only purpose was chai-as-promised registration); `setupFiles` references removed from 19 per-package configs ## Assertion messages vitest matchers don't accept a 2nd-arg message; `expect(val, msg)` does. Moved messages from `.toBeGreaterThanOrEqual(n, msg)` to `expect(x, msg).toBeGreaterThanOrEqual(n)` in sdk multisigIsm, rebalancer-sim full-simulation, infra gitleaks tests. oxlint `jest/valid-expect` disabled for test files since vitest supports the 2-arg expect signature that jest doesn't. Also disabled `no-conditional-expect`, `require-to-throw-message`, `no-standalone-expect` — these jest plugin rules are style-level, don't apply to vitest idioms in this codebase, and start firing because `expect().toBe()` now looks like jest syntax. ## expect.fail() 22 occurrences in rebalancer LiFiBridge.test.ts (inside try/catch blocks), plus a handful elsewhere → `throw new Error(msg)`. In .then() callbacks (cli create-altvm-signers.test.ts) rendered as `.then(() => { throw new Error(msg) })`. ## devDeps cleanup Pure-vitest packages had `chai`, `chai-as-promised`, `@types/chai`, `@types/chai-as-promised`, `@types/sinon-chai` removed from devDependencies: ccip-server, deploy-sdk, fee-quoting, github-proxy, http-registry-server, keyfunder, metrics, provider-sdk, rebalancer-sim, utils, warp-monitor. Hybrid packages KEEP chai devDeps for hardhat/e2e suites: cli, infra, rebalancer, relayer, sdk, plus starknet-sdk/svm-sdk/tron-sdk/ radix-sdk/cosmos-sdk/aleo-sdk/helloworld whose e2e or hardhat paths stay on mocha. Root `package.json` drops chai/chai-as-promised/vitest devDeps (only added in the previous PR to support the shared setup file). Catalog: `chai`, `chai-as-promised`, `sinon` entries retained — still used by hardhat/e2e test paths across the monorepo. ## Tests ~2,100 tests green across the migrated vitest suites. `pnpm build` at the root passes. `pnpm format:check` + `pnpm lint` pass. Full `pnpm test:ci` deferred to CI.
1 parent 5ef7a07 commit 7cded72

203 files changed

Lines changed: 3794 additions & 4034 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

oxlint.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@
122122
],
123123
"rules": {
124124
"no-console": "off",
125-
"no-unused-expressions": "off"
125+
"no-unused-expressions": "off",
126+
"jest/valid-expect": "off",
127+
"jest/no-conditional-expect": "off",
128+
"jest/require-to-throw-message": "off",
129+
"jest/no-standalone-expect": "off"
126130
}
127131
},
128132
{

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
"@changesets/cli": "^2.26.2"
2727
},
2828
"devDependencies": {
29-
"chai": "catalog:",
30-
"chai-as-promised": "catalog:",
3129
"husky": "^8.0.0",
3230
"lint-staged": "^15.5.2",
3331
"oxfmt": "catalog:",
@@ -36,8 +34,7 @@
3634
"prettier": "catalog:",
3735
"prettier-plugin-solidity": "catalog:",
3836
"tsx": "catalog:",
39-
"turbo": "^2.8.11",
40-
"vitest": "catalog:"
37+
"turbo": "^2.8.11"
4138
},
4239
"packageManager": "pnpm@10.30.2",
4340
"pnpm": {

pnpm-lock.yaml

Lines changed: 0 additions & 102 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/ccip-server/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@
4949
},
5050
"devDependencies": {
5151
"@hyperlane-xyz/tsconfig": "workspace:^",
52-
"@types/chai": "catalog:",
5352
"@types/cors": "^2",
5453
"@types/express": "^4.17.1",
5554
"@types/node": "catalog:",
5655
"@types/pg": "^8.16.0",
5756
"@types/pino-http": "^5.8.4",
5857
"@types/sinon": "catalog:",
5958
"@vercel/ncc": "catalog:",
60-
"chai": "catalog:",
6159
"nodemon": "^3.0.3",
6260
"pino-pretty": "catalog:",
6361
"sinon": "catalog:",

0 commit comments

Comments
 (0)