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.

Pratik Pratik SWE with 15+ years of experience building and maintaining web apps and extensive BE infrastructure Kingsley Omage Kingsley Omage Fullstack software engineer passionate about AI Agents, blockchain, LLMs. 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. Franck Plazanet Franck Plazanet I am a Strategic Engineering Leader with over 8 years of experience building high-availability enterprise systems and scaling high-performing technical teams. My focus is on bridging the gap between complex technology and business growth. Core Expertise: 🚀 Leadership: Managing and coaching teams of 15+ engineers, fostering a culture of accountability and continuous improvement. 🏗️ Architecture: Enterprise Core Systems, Multi-system Integration (ERP/API/ETL), and Core Database Structure. ☁️ Cloud & Scale: AWS Expert; architected systems handling 10B+ monthly requests and managing 100k+ SKUs. 📈 Business Impact: Aligning tech strategy with P&L goals to drive $70k+ in monthly recurring revenue. I thrive on "out-of-the-box" thinking to solve complex technical bottlenecks and am always looking for ways to use automation to improve business productivity. Dor Yaloz Dor Yaloz SW engineer with 6+ years of experience, I worked with React/Node/Python did projects with React+Capacitor.js for ios Supabase expert Victor Denisov Victor Denisov Developer Yovel Cohen Yovel Cohen I got a lot of experience in building Long-horizon AI Agents in production, Backend apps that scale to millions of users and frontend knowledge as well. Krishna Sai Kuncha Krishna Sai Kuncha Experienced Professional Full stack Developer with 8+ years of experience across react, python, js, ts, golang and react-native. Developed inhouse websearch tooling for AI before websearch was solved : ) Prakash Prajapati Prakash Prajapati I’m a Senior Python Developer specializing in building secure, scalable, and highly available systems. I work primarily with Python, Django, FastAPI, Docker, PostgreSQL, and modern AI tooling such as PydanticAI, focusing on clean architecture, strong design principles, and reliable DevOps practices. I enjoy solving complex engineering problems and designing systems that are maintainable, resilient, and built to scale. Jared Hasson Jared Hasson Full time lead founding dev at a cyber security saas startup, with 10 yoe and a bachelor's in CS. Building & debugging software products is what I've spent my time on for forever

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