Skip to content

fix(test): upgrade vitest to 4 and restore the suites it was silently skipping - #1317

Open
arkhindi12 wants to merge 1 commit into
Miracle656:mainfrom
arkhindi12:fix/vitest-upgrade-1311
Open

arkhindi12 wants to merge 1 commit into
Miracle656:mainfrom
arkhindi12:fix/vitest-upgrade-1311

Conversation

@arkhindi12

Copy link
Copy Markdown

What this does

Bumps vitest in sdk and frontend/wallet from ^1.3.0 (resolving 1.6.1) to ^4.1.12, the current major that still supports Node 20 — the version CI pins. Both workspaces end up on the same major.

Closes #1311

The suites were already broken, not just stale

Worth stating up front, because it changes what this PR is: npm run test:vitest did not work on main in either workspace. It collected zero tests and reported every file as failed.

sdk    @ main:  Test Files  37 failed (37)    Tests  no tests
wallet @ main:  Test Files 107 failed (107)   Tests  no tests

Three causes, all fixed here:

  1. No include. Vitest swept up the Jest suites and the Playwright spec, then failed on describe is not defined. Both configs now scope to tests/**/*.test.ts.
  2. Wrong environment in sdk. It ran with environment: 'node' while the suites touch localStorage and document. Now jsdom.
  3. wallet had no @vitest/coverage-v8 while its config already asked for provider: 'v8'. Added.

The @veil/* aliases that only existed in Jest's moduleNameMapper are now mirrored into resolve.alias, so the suites resolve the same way under both runners.

tests/ was being run twice, with different semantics

Both runners claimed tests/. Those suites call jest.mock, which only Jest hoists — so under Vitest the mocks were silently inert and the tests exercised the real modules instead. That is a passing-looking test that tests nothing, which is the same failure mode this issue warns about.

tests/ is now Vitest-only in both workspaces, and Jest's testMatch no longer lists it. The affected files moved from jest.mock/jest.fn to vi.mock/vi.fn. This is the "fix the suites rather than pin around them" part of the issue.

One real bug surfaced

The WebAuthn suite replaced the whole crypto object with just getRandomValues:

Object.defineProperty(global, 'crypto', {
  value: { getRandomValues: jest.fn(...) },
});

That dropped subtle, which the code under test needs to import an ECDSA P-256 key — it failed with Cannot read properties of undefined (reading 'importKey'). The mock now keeps the real subtle.

Test counts

Suites / tests, before → after. Totals are unchanged; the split just moved because tests/ changed owner.

sdk     before  36 / 434   →   after  33 / 420 (jest)  +  3 / 14 (vitest)   = 36 / 434
wallet  before 101 / 1555  →   after  98 / 1511 (jest) +  3 / 44 (vitest)   = 101 / 1555

No suite is skipped or marked todo to reach these numbers. The 2 skipped suites and 3 skipped tests in wallet are the pre-existing live-gated ones (drift.live.test.ts, sponsoredSubmit.live.test.ts), untouched.

Measured on main (baseline) and on this branch, same machine, Node 22:

                        before        after
sdk    jest        36 / 434        33 / 420   exit 0
sdk    vitest      broken (0)       3 / 14    exit 0
wallet jest       101 / 1555       98 / 1511   exit 0
wallet vitest      broken (0)       3 / 44    exit 0

Coverage

Works in both, and both exit 0. The previous thresholds: 70 was carried over from the Jest run, which measures all of src/; applying it to the three-file Vitest subset made the command fail permanently, which is how it stayed unrun. The floor is now set to what those suites actually cover (sdk 14/8/18/15, wallet 30/15/30/30) with a comment explaining the distinction — coverage still reports, it just no longer claims 70% of a subset. Say the word if you'd rather keep 70 and gate on the Jest run only.

CI

Neither job ran npm run test:vitest, which is precisely how this rotted unnoticed. Both now run it right after Jest.

Out of scope

@stellar/stellar-sdk is untouched — no version or declaration change in either lockfile (verified by diffing the @stellar entries). Version spread stays with #660.

Verification

sdk:    npx tsc --noEmit                      exit 0
wallet: npm run typecheck                     exit 0
sdk:    npx jest --silent                     33 suites / 420 tests   exit 0
sdk:    npm run test:vitest                    3 suites /  14 tests   exit 0
wallet: npx jest --silent                     98 suites / 1511 tests  exit 0
wallet: npm run test:vitest                    3 suites /  44 tests   exit 0

ci.yml still parses; all 10 jobs intact.

Both workspaces declared vitest ^1.3.0 (resolving 1.6.1). Bump to ^4.1.12,
which is the current major that still supports Node 20 — the version CI pins.

`npm run test:vitest` was already broken on main in both workspaces before
this change: it collected zero tests and reported 37 failures in sdk and 107
in wallet. Three causes:

- No `include`, so vitest swept up the Jest suites and the Playwright spec
  and failed on `describe is not defined`.
- sdk ran with `environment: node` while its suites touch localStorage and
  document.
- wallet used `provider: 'v8'` without depending on @vitest/coverage-v8.

Also: tests/ was claimed by both runners. The suites call `jest.mock`, which
only Jest hoists, so under vitest they silently exercised the real modules
instead of the mocks. tests/ is now Vitest-only in both workspaces and the
Jest testMatch no longer lists it; the files moved to `vi.mock`/`vi.fn`.

One real bug surfaced: the WebAuthn suite replaced the whole `crypto` object
with just `getRandomValues`, dropping `subtle`, which the code under test
needs to import an ECDSA P-256 key. The mock now keeps the real `subtle`.

CI never ran `npm run test:vitest`, which is how it stayed broken without
anyone noticing. Both jobs now run it after Jest.

Test counts (suites / tests), unchanged in total:

  sdk    before 36 / 434  ->  after 33 / 420 (jest) + 3 / 14 (vitest)
  wallet before 101 / 1555 -> after 98 / 1511 (jest) + 3 / 44 (vitest)

No suite is skipped or marked todo to get there; the 2 skipped suites and 3
skipped tests in wallet are the pre-existing `live`-gated ones. Coverage
reporting works in both. `@stellar/stellar-sdk` is untouched (see Miracle656#660).
@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown

@arkhindi12 is attempting to deploy a commit to the miracle656's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vitest is several majors behind in sdk and wallet

1 participant