feat(tests): replace nock with MSW mock server infrastructure#145
Open
base44-os-gremlins[bot] wants to merge 1 commit intomainfrom
Open
feat(tests): replace nock with MSW mock server infrastructure#145base44-os-gremlins[bot] wants to merge 1 commit intomainfrom
base44-os-gremlins[bot] wants to merge 1 commit intomainfrom
Conversation
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>
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/sdk@0.8.21-pr.145.5ba3ebbPrefer not to change any import paths? Install using npm alias so your code still imports npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.21-pr.145.5ba3ebb"Or add it to your {
"dependencies": {
"@base44/sdk": "npm:@base44-preview/sdk@0.8.21-pr.145.5ba3ebb"
}
}
Preview published to npm registry — try new features instantly! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nockHTTP interception with a proper MSW (Mock Service Worker) mock server usingmsw@2+msw/nodetests/mocks/server.ts— documented server instance with handler authoring guidetests/setup.js— MSW lifecycle (beforeAll/afterEach/afterAll)server.use()handler patternvi.stubGlobal("fetch", ...)fromfunctions.test.ts; use MSW handlers insteadAuthorization,Base44-State)Test results
Architecture
MSW intercepts at the Node.js
http.ClientRequestlevel (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