Look, I've wasted so many weekends on tests that mysteriously fail in VS Code but work fine from the command line. Or tests that pass in my IDE but explode the moment they hit CI. If you've been there, this guide is for you.
The built-in Test Explorer works great when it works. Which is maybe 70% of the time on a good day? Your mileage may vary depending on what extensions you have installed and whether VS Code feels like cooperating.
The Test Explorer: When It Doesn't Hate You
Test Explorer is supposed to automatically find your tests. Sometimes it does, sometimes it just stares at you blankly while you mash the reload button like an idiot.
Test Discovery Bullshit I've Dealt With:
- Tests not showing up because of missing
jest.config.js
- even thoughnpm test
works fine - Test Explorer finds tests but throws "No tests found" when you try to run them
- Tests randomly vanish and reappear when you edit files
- Jest extension conflicting with ESLint extension, breaking everything until you disable one
- VS Code 1.85 broke test discovery for a week until they patched it
When Test Explorer Actually Works:
When it works, the real-time feedback is pretty sweet. Change something, instantly see what breaks. Beats constantly alt-tabbing to check if you fucked up.
Breakpoint Debugging Reality Check:
Setting breakpoints in tests is hit or miss. Sometimes they work perfectly, sometimes they don't trigger at all. I'm probably biased because I've had more luck with `debugger;` statements, but that might just be my setup.
Jest: The Devil You Know
Jest is everywhere, which means everyone's debugging the same stupid Jest issues. The good news is there are Stack Overflow answers for most of them.
Jest Extension Reality:
The Jest extension works great until it doesn't. Common issues I've hit:
- Extension stops discovering new test files until you reload
- Watch mode gets confused and runs the wrong tests
- Memory leaks when running large test suites (VS Code becomes unusable)
- Conflicts with ESLint extension causing random crashes
My Jest VS Code Setup:
{
"jest.jestCommandLine": "npm run test",
"jest.autoRun": {
"watch": false, // I manually trigger tests, auto-run is annoying
"onStartup": [] // Don't run tests on startup, it slows down VS Code
},
"jest.showCoverageOnLoad": false, // Coverage UI kills performance
"jest.debugMode": true
}
The Nuclear Option for Jest Issues:
- Reload the window (Cmd+Shift+P → "Developer: Reload Window")
- Still broken? Close VS Code, nuke
node_modules
, reinstall everything - Still broken? Restart your computer and contemplate switching careers
- Still broken? Check Jest issues to see if you're not alone in your suffering
Vitest: Jest But Faster (When It Works)
Vitest is basically Jest with better performance and less bullshit. The VS Code integration is pretty good, but it's newer so there are fewer Stack Overflow answers when things break.
What Might Work Better Than Jest (YMMV):
- Test execution seems faster on larger codebases, but I haven't benchmarked it properly
- TypeScript support is cleaner out of the box, though your config might be different
- Hot module replacement for tests works when it works - sometimes it gets confused
- Uses less memory in my experience, but could depend on your test setup
What Still Sucks:
- Fewer extensions and tooling compared to Jest ecosystem
- Some Jest plugins don't work with Vitest (obviously)
- Documentation assumes you know Vite, which is annoying if you don't
Vitest VS Code Issues I've Hit:
- Test discovery breaks if your `vite.config.js` is misconfigured
- Watch mode occasionally gets stuck and stops running tests
- Debugging breakpoints work better than Jest, but still not 100% reliable
- Check Vitest GitHub discussions when things go wrong
Playwright: Browser Testing That Actually Works
Playwright is probably the least frustrating way to do browser testing in VS Code. The Microsoft extension is solid, and debugging actually works most of the time.
What's Actually Good:
- Test recording is legitimately useful - click around your app and get working test code
- Debugging shows you both the browser state and VS Code debugger
- Cross-browser testing doesn't require separate configurations
- Error messages are usually helpful (unlike Selenium)
The Inevitable Pain Points:
- Tests are slow as hell (it's launching actual browsers)
- Flaky tests due to timing issues, especially with CSS animations
- Memory usage gets insane when running multiple browser instances
- VS Code crashes if you run too many Playwright tests at once
- Check Playwright troubleshooting docs when tests randomly fail
Real Debugging War Story:
Spent forever on this weird Playwright issue. Test passed locally but kept timing out in CI. Think it was some timing thing with animations? Anyway, adding a wait fixed it but I'm still not 100% sure why. Probably should've dug deeper but deadlines, you know?
Playwright Debugging That Actually Helps:
test('login with actual debugging', async ({ page }) => {
await page.goto('/login');
// This actually pauses and lets you inspect manually
await page.pause();
// When debugging, keep the browser open
await page.fill('[data-testid="email"]', 'test@example.com');
// Breakpoint here lets you see both VS Code vars and browser state
await page.click('[data-testid="submit"]');
});
The Weekend Debugging Survival Guide
Flaky Tests Are the Worst:
Your test passes 9 times out of 10, then fails randomly in CI. Here's what actually works:
- Run the test 50+ times locally -
for i in {1..50}; do npm test -- --testNamePattern="flaky test"; done
- Check for timing issues - Add
await page.waitForTimeout(1000)
everywhere and see if it helps - Look for shared state - Tests fucking with each other's data is the most common cause
- Environment differences - Different Node versions, timezone issues, different CPU speeds
The Debugger Console Is Your Friend:
When breakpoints don't work, use the Debug Console in VS Code:
// In the debug console:
> JSON.stringify(user, null, 2) // Pretty print objects
> process.env.NODE_ENV // Check environment
> global.something // Inspect global state
VS Code Test Failures That'll Ruin Your Day:
"Cannot find any tests" Error:
- Check your `jest.config.js` or `vitest.config.js` exists
- Verify test files match naming pattern (
*.test.js
,*.spec.js
) - Restart VS Code (the nuclear option that works 80% of the time)
- Check VS Code testing docs for setup help
Classic "Works on My Machine" Syndrome:
- Node version differences (
nvm use
and check.nvmrc
) - Timezone issues (tests with dates/times)
- Missing environment variables
- File path case sensitivity (macOS vs Linux)
Breakpoints Refuse to Cooperate:
- Try
debugger;
statements instead - Check source maps are enabled
- Disable code coverage during debugging
- Make sure you're debugging the right test file (VS Code sometimes gets confused)
VS Code Memory Issues During Testing:
// Add to settings.json
{
"jest.autoRun": {
"watch": false,
"onSave": "test-src-file"
},
"testing.automaticallyOpenTesting": false
}
The Bottom Line on VS Code Testing
What Actually Works:
- Test Explorer for visual feedback (when it's not broken)
debugger;
statements over VS Code breakpoints- Manual test execution over auto-run (saves your sanity)
- Playwright for E2E testing if you can handle the slowness
What Doesn't Work (But Everyone Tries):
- Auto-running all tests on file save (kills VS Code performance)
- Complex test coverage setups (just write more tests)
- Trying to debug flaky tests instead of rewriting them
- Running 50+ browser tests simultaneously in VS Code
The 80/20 Rule:
80% of your debugging time will be spent on:
- Tests that work locally but fail in CI
- Extensions conflicting with each other
- Memory issues from running too many tests
- Breakpoints that refuse to trigger
My Current VS Code Test Setup:
{
"jest.autoRun": { "watch": false },
"jest.showCoverageOnLoad": false,
"testing.automaticallyOpenTesting": false,
"typescript.preferences.includePackageJsonAutoImports": "off"
}
Simple setup that works for me. Might not be perfect for your project, but it's saved me from fighting with VS Code configs when I should be writing actual tests.