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.

Bastien Labelle Bastien Labelle Full stack dev w/ 20+ years of experience Jacek Rozanski Jacek Rozanski Senior PHP/Symfony developer and DevOps engineer with 20+ years of professional experience, running opcode.pl (web development agency, est. 2004). Day job: I'm the sole backend developer at merketing company where I own and maintain 11 PHP/Symfony microservices on AWS (ECS Fargate, RDS, S3, CloudFront), handle the full CI/CD pipeline (Bitbucket Pipelines, Docker), and manage monitoring with Sentry and CloudWatch. These services handle high request volumes in production every month. What I bring to AI-built apps: - I audit and fix security issues (OWASP methodology), performance bottlenecks, and architectural problems in codebases generated by Cursor, Claude Code, Lovable, Bolt, and v0 - I refactor AI-generated prototypes into production-grade applications with proper error handling, testing, and clean architecture (SOLID, DDD, hexagonal architecture) - I set up the infrastructure AI tools don't touch: AWS hosting, CI/CD pipelines, automated deployments, database optimization, monitoring, and alerting - I integrate external services: payment providers, email systems, partner APIs, SSO/auth Tech stack: PHP 8.x, Symfony, React, Next.js, PostgreSQL, MySQL, Docker, AWS (ECS, RDS, S3, SQS/SNS, CloudFront), Terraform, Supabase. I also use AI tools daily (Claude Code, Cursor) in my own workflow, so I understand both the strengths and the gaps in AI-generated code. Based in Poland (CET timezone). Available for async work and calls during EU/US business hours. Daniel Vázquez Daniel Vázquez Software Engineer with over 10 years of experience on Startups, Government, big tech industry & consulting. 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 PawelPloszaj PawelPloszaj I'm fronted developer with 10+ years of experience with big projects. I have small backend background too Stanislav Prigodich Stanislav Prigodich 15+ years building iOS and web apps at startups and enterprise companies. I want to use that experience to help builders ship real products - when something breaks, I'm here to fix it. Meïr Ankri Meïr Ankri Full-stack developer specializing in React / Next.js / Node.js with 6+ years of experience. I've worked across various sectors including automotive (Reezocar/Société Générale), healthcare (Medical Link SaaS), and e-commerce (Glasman). I build web apps end-to-end, from architecture to production, with a focus on scalability, performance, and code quality. I also mentor junior developers and contribute to technical decisions and code reviews. 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. Matthew Butler Matthew Butler Systems Development Engineer @ Amazon Web Services Pratik Pratik SWE with 15+ years of experience building and maintaining web apps and extensive BE infrastructure

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