Windsurf testing

API Tests Hitting Real Endpoints in Windsurf Project

Tests in your Windsurf-generated project are making real HTTP requests to external APIs instead of using mocks. This causes tests to be slow, flaky, expensive (burning API credits), and destructive (creating real data in third-party services). Password reset emails get sent to real users during tests, real charges appear on payment processors, and tests fail when external APIs are down.

Cascade generates test files that set up the test scenario but doesn't intercept outbound HTTP requests. The test code calls your app's functions, which in turn call real Stripe, SendGrid, OpenAI, or other APIs. In development this may go unnoticed because the API keys are for test/sandbox environments, but it still makes tests slow and unreliable.

The problem becomes critical when tests run in CI/CD pipelines where they execute on every push, rapidly consuming API quotas and creating garbage data in external services.

Error Messages You Might See

Test timeout: API request took too long Stripe: API key not valid for test mode Error: getaddrinfo ENOTFOUND api.external-service.com Rate limited during test run 402 Payment Required in test environment
Test timeout: API request took too longStripe: API key not valid for test modeError: getaddrinfo ENOTFOUND api.external-service.comRate limited during test run402 Payment Required in test environment

Common Causes

  • No HTTP interception library — The test suite doesn't use nock, msw, or similar tools to intercept outbound HTTP requests
  • Service layer not abstracted — External API calls are made directly in business logic instead of through injectable service classes
  • Environment variables pointing to real APIs — Test environment uses real API keys instead of test/mock keys
  • Missing test environment configuration — No .env.test file or NODE_ENV=test check to switch to mock implementations
  • Mocks set up but not activated — HTTP mocking library is installed but the mocks aren't started before tests or cleaned up after

How to Fix It

  1. Install MSW (Mock Service Worker) — Set up msw to intercept all outbound HTTP requests in tests. Define handlers that return predetermined responses for each external API
  2. Create a .env.test file — Use fake or empty API keys in test configuration so even if mocks fail, real APIs aren't called
  3. Add a global test setup — In jest.setup.ts or a beforeAll, start the MSW server. In afterAll, close it. In afterEach, reset handlers to default
  4. Use nock for specific API mocking — For precise control, use nock to mock individual HTTP endpoints and assert they were called with expected parameters
  5. Fail tests on unmocked requests — Configure MSW or nock to throw an error on any unhandled HTTP request, making it impossible for tests to hit real APIs
  6. Abstract external services — Create wrapper classes for each external API and inject mock implementations in tests

Real developers can help you.

Simon A. Simon A. I'm a backend developer building APIs, emulators, and interactive game systems. Professionally, I've developed Java/Spring reporting solutions, managed relational and NoSQL databases, and implemented CI/CD workflows. rayush33 rayush33 JavaScript (React.js, React Native, Node.js) Developer with demonstrated industry experience of 4+ years, actively looking for opportunities to hone my skills as well as help small-scale business owners with solutions to technical problems Matthew Butler Matthew Butler Systems Development Engineer @ Amazon Web Services Sage Fulcher Sage Fulcher Hey I'm Sage! Im a Boston area software engineer who grew up in South Florida. Ive worked at a ton of cool places like a telehealth kidney care startup that took part in a billion dollar merger (Cricket health/Interwell health), a boutique design agency where I got to work on a ton of exciting startups including a photography education app, a collegiate Esports league and more (Philosophie), a data analytics as a service startup in Cambridge (MA) as well as at Phillips and MIT Lincoln Lab where I designed and developed novel network security visualizations and analytics. I've been writing code and furiously devoted to using computers to make people’s lives easier for about 17 years. My degree is in making computers make pretty lights and sounds. Outside of work I love hip hop, the Celtics, professional wrestling, magic the gathering, photography, drumming, and guitars (both making and playing them) Rudra Bhikadiya Rudra Bhikadiya I build and fix web apps across Next.js, Node.js, and DBs. Comfortable jumping into messy code, broken APIs, and mysterious bugs. If your project works in theory but not in reality, I help close that gap. Daniel Vázquez Daniel Vázquez Software Engineer with over 10 years of experience on Startups, Government, big tech industry & consulting. Antriksh Narang Antriksh Narang 5 years+ Experienced Dev (Specially in Web Development), can help in python, javascript, react, next.js and full stack web dev technologies. Luca Liberati Luca Liberati I work on monoliths and microservices, backends and frontends, manage K8s clusters and love to design apps architecture Taufan Taufan I’m a product-focused engineer and tech leader who builds scalable systems and turns ideas into production-ready platforms. Over the past years, I’ve worked across startups and fast-moving teams, leading backend architecture, improving system reliability, and shipping products used by thousands of users. My strength is not just writing code — but connecting product vision, technical execution, and business impact. legrab legrab I'll fill this later

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

What is the best way to mock HTTP requests in tests?

Use MSW (Mock Service Worker) for broad HTTP interception — it works at the network level and catches all requests. Use nock for precise assertions about specific API calls. Both can be configured to fail on unmocked requests.

Should I use Stripe test mode or mock Stripe entirely?

For unit tests, mock Stripe entirely with MSW or nock for speed and reliability. For integration tests, use Stripe's test mode with test API keys. Never use live mode in any test environment.

Related Windsurf Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help