Skip to content

feat(tests): replace nock with MSW mock server infrastructure#145

Open
base44-os-gremlins[bot] wants to merge 1 commit intomainfrom
feat/msw-test-infrastructure
Open

feat(tests): replace nock with MSW mock server infrastructure#145
base44-os-gremlins[bot] wants to merge 1 commit intomainfrom
feat/msw-test-infrastructure

Conversation

@base44-os-gremlins
Copy link

Summary

  • Replace nock HTTP interception with a proper MSW (Mock Service Worker) mock server using msw@2 + msw/node
  • Create tests/mocks/server.ts — documented server instance with handler authoring guide
  • Update tests/setup.js — MSW lifecycle (beforeAll/afterEach/afterAll)
  • Port all 7 nock-based unit test files to per-test server.use() handler pattern
  • Remove vi.stubGlobal("fetch", ...) from functions.test.ts; use MSW handlers instead
  • Add request-capture pattern for header assertions (Authorization, Base44-State)

Test results

Test Files  10 passed (10)
      Tests 116 passed (116)

Architecture

Vitest test → SDK (axios / fetch) → MSW Node server → handler → fake response

MSW intercepts at the Node.js http.ClientRequest level (via @mswjs/interceptors), so no monkey-patching of axios or fetch is needed.

Goal

https://github.com/base44-dev/gremlins/issues/873

🤖 Generated with Claude Code

Migrate all unit tests from nock-based HTTP interception to a proper
MSW (Mock Service Worker) mock server using msw/node + @mswjs/interceptors.

Changes:
- Add msw@2 as devDependency, remove nock
- Create tests/mocks/server.ts: MSW server with documentation on adding handlers
- Update tests/setup.js: start/stop/reset MSW server in beforeAll/afterEach/afterAll
- Port all 7 nock-based test files to per-test server.use() handlers:
  entities, auth, functions, connectors, integrations, custom-integrations, client
- Replace vi.stubGlobal("fetch", ...) in functions.test.ts with MSW handlers
- Add request capture pattern for asserting headers (Authorization, Base44-State)
- Use RegExp patterns for MSW handlers where operationId contains URL-unsafe chars

All 116 unit tests pass (npm run test:unit exits 0).

Goal: https://github.com/base44-dev/gremlins/issues/873

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/sdk@0.8.21-pr.145.5ba3ebb

Prefer not to change any import paths? Install using npm alias so your code still imports @base44/sdk:

npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.21-pr.145.5ba3ebb"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "@base44/sdk": "npm:@base44-preview/sdk@0.8.21-pr.145.5ba3ebb"
  }
}

Preview published to npm registry — try new features instantly!

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.

0 participants