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.

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 : ) Jen Jacobsen Jen Jacobsen I’m a Full-Stack Developer with over 10 years of experience building modern web and mobile applications. I enjoy working across the full product lifecycle — turning ideas into real, well-built products that are intuitive for users and scalable for businesses. I particularly enjoy building mobile apps, modern web platforms, and solving complex technical problems in a way that keeps systems clean, reliable, and easy to maintain. Richard McSorley Richard McSorley Full-Stack Software Engineer with 8+ years building high-performance applications for enterprise clients. Shipped production systems at Walmart (4,000+ stores), Cigna (20M+ users), and Arkansas Blue Cross. 5 patents in retail/supply chain tech. Currently focused on AI integrations, automation tools, and TypeScript-first architectures. 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. 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 prajwalfullstack prajwalfullstack Hi Im a full stack developer, a vibe coded MVP to Market ready product, I'm here to help Jaime Orts-Caroff Jaime Orts-Caroff I'm a Senior Android developer, currently working at Aircall. I'm open to work in various fields! Omar Faruk Omar Faruk As a Product Engineer at Klasio, I contributed to end-to-end product development, focusing on scalability, performance, and user experience. My work spanned building and refining core features, developing dynamic website templates, integrating secure and reliable payment gateways, and optimizing the overall system architecture. I played a key role in creating a scalable and maintainable platform to support educators and learners globally. I'm enthusiastic about embracing new challenges and making meaningful contributions. 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) 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.

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