Skip to content

test(app-check): migrate app-check to Vitest - #10376

Open
Manvi1203 wants to merge 8 commits into
mainfrom
feature/vitest-app-check
Open

Manvi1203 wants to merge 8 commits into
mainfrom
feature/vitest-app-check

Conversation

@Manvi1203

@Manvi1203 Manvi1203 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrates @firebase/app-check unit tests from legacy Karma (Mocha / Chai / Sinon) to Vitest (Browser Chromium via Playwright).

Description

  • Runner & Config: Replaced karma.conf.js with vitest.config.mjs extending config/vitest.base.mjs. Configured browser runner targeting Chromium via Playwright with defensive project filtering (if (config.test?.projects)). Updated test/setup.ts with global afterEach teardown (vi.useRealTimers(), vi.resetAllMocks(), vi.restoreAllMocks()).
  • Target Environment: @firebase/app-check relies on browser APIs (self.grecaptcha, IndexedDB, localStorage, DOM <script> injection, document.hasFocus, page visibility/proactive refresh timers). All 8 unit test suites run in the browser project via @vitest/browser-playwright.
  • Assertions & Lifecycle: Converted legacy Chai assertions (expect(...).to.equal, .to.deep.equal, .to.be.true, .to.be.rejectedWith, .to.throw) to native Vitest matchers (.toBe(), .toEqual(), .toBe(true), .rejects.toThrow(), .toThrow()). Converted Mocha's done callback in src/internal-api.test.ts to Promise-based async execution. Standardized afterEach cleanup for globals (self.grecaptcha, self.FIREBASE_APPCHECK_DEBUG_TOKEN).
  • Mocks, Spies & Timers: Converted Sinon stubs, spies, and fake timers (sinon.stub, sinon.spy, sinon.useFakeTimers) to native Vitest utilities (vi.fn(), vi.spyOn(), vi.useFakeTimers()). Used vi.mock('...', { spy: true }) in api.test.ts, debug.test.ts, internal-api.test.ts, providers.test.ts, and storage.test.ts so sealed ESM module exports (./client, ./indexeddb, ./storage, ./recaptcha, ./debug, ./util, ./internal-api, @firebase/util) can be spied and overridden per test via vi.spyOn(...) while keeping their original implementations active by default.
  • Module Augmentation: Updated declare module '@firebase/component' to declare module '@firebase/component/dist/src/types' in src/index.ts and src/public-types.ts so Vite's ESM resolver properly merges NameServiceMapping for 'app-check' and 'app-check-internal'.
  • Package Scripts: Updated package.json scripts (test, test:ci, test:browser, test:browser:debug) to run Vitest and removed legacy Karma scripts (test:karma, test:karma:debug).

Performance

  • Baseline (Karma + Webpack): ~12–15s total duration
  • Vitest (Unit Tests): ~2.5s (8 test files, 111 tests passed)

@Manvi1203
Manvi1203 requested review from a team and hsubox76 as code owners September 11, 2026 02:13
@changeset-bot

changeset-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 88362b6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the @firebase/app-check package's test suite from Karma, Mocha, Chai, and Sinon to Vitest. This involves updating configuration files, package scripts, and test files to use Vitest's APIs and assertions. The review feedback points out several remaining instances of legacy Chai .to.equal assertions in internal-api.test.ts that should be updated to Vitest's .toBe() matcher.

Comment thread packages/app-check/src/internal-api.test.ts Outdated
Comment thread packages/app-check/src/internal-api.test.ts Outdated
Comment thread packages/app-check/src/internal-api.test.ts Outdated
Comment thread packages/app-check/src/internal-api.test.ts Outdated
Comment thread packages/app-check/src/internal-api.test.ts Outdated
@Manvi1203
Manvi1203 requested a review from a team as a code owner September 15, 2026 22:41
@Manvi1203
Manvi1203 requested a review from a team as a code owner September 17, 2026 18:07
@Manvi1203

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the app-check package's test suite from Karma, Mocha, Chai, and Sinon to Vitest, updating configuration files, test scripts, and test assertions accordingly. It also refactors some type-only exports to use export type. The review feedback identifies several opportunities to improve test isolation and robustness: specifically, ensuring mock wrappers for readDebugTokenFromIndexedDB correctly forward arguments to the underlying implementation, and properly cleaning up global variables like self.FIREBASE_APPCHECK_DEBUG_TOKEN and self.grecaptcha in afterEach blocks to prevent test pollution.

Comment thread packages/app-check/src/api.test.ts Outdated
Comment thread packages/app-check/src/api.test.ts
Comment thread packages/app-check/src/debug.test.ts Outdated
Comment thread packages/app-check/src/providers.test.ts
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.

1 participant