Run and debug @hapi/lab tests directly from VS Code's native Test Explorer
- Native Test Explorer Integration - Tests appear in VS Code's Test Explorer sidebar with green play arrows in the gutter
- Run Individual Tests - Click the play button next to any
test(),it(),describe(), orexperiment()block - Run All Tests - Run entire test files or all tests at once from the Test Explorer panel
- Live Results - See test pass/fail status with colored ANSI output directly in the Test Results panel
- Real-time Discovery - Tests are automatically discovered and updated as you edit your files
- Source Map Support - Debug your tests with full source map support
- Install the extension from the VS Code Marketplace
- Open a project that uses
@hapi/labfor testing - Open the Test Explorer in the sidebar (beaker icon) or press
Cmd+Shift+Pand type "Testing: Focus on Test Explorer View" - Your tests will be automatically discovered - look for green play buttons in the gutter
- Click the play button next to any test to run it
- Node.js 18 or later
- VS Code 1.85.0 or later
- A project using
@hapi/labfor testing
Search for "hapi/lab Test Runner" in the VS Code Extensions marketplace, or install directly.
The extension is also available on Open VSX for VS Code derivatives like Cursor, VSCodium, and other editors that use the Open VSX Registry.
code --install-extension mtharrison.vscode-lab-test-runner- Download the
.vsixfile from the releases page - In VS Code, go to Extensions (
Cmd+Shift+X) - Click the
...menu and select "Install from VSIX..." - Select the downloaded file
Configure the extension through VS Code settings (Cmd+, or Ctrl+,):
| Setting | Default | Description |
|---|---|---|
labTestExplorer.testMatch |
**/{test,tests,__tests__}/**/*.{js,ts} |
Glob pattern to match test files |
labTestExplorer.labPath |
"" |
Path to lab executable (leave empty to use npx) |
labTestExplorer.timeout |
30000 |
Test timeout in milliseconds |
labTestExplorer.labArgs |
--no-lint --no-coverage --no-L -v -r console |
CLI arguments to pass to lab |
labTestExplorer.commandPrefix |
"" |
Command prefix for running tests (e.g., NODE_ENV=test) |
labTestExplorer.activationCommand |
"" |
Shell command to run when extension activates |
labTestExplorer.suppressPrefixOutput |
true |
Suppress output from commandPrefix wrapper |
{
"labTestExplorer.testMatch": "**/test/**/*.test.ts",
"labTestExplorer.timeout": 60000,
"labTestExplorer.commandPrefix": "NODE_ENV=test",
"labTestExplorer.labArgs": "--no-lint --no-coverage -v -r console"
}The commandPrefix setting is useful for:
- Setting environment variables:
NODE_ENV=test - Using wrapper scripts:
./scripts/test-wrapper.sh -- - Running with specific Node options:
node --inspect --
From the Gutter:
- Click the green play button that appears next to any
test(),it(),describe(), orexperiment()block
From the Test Explorer:
- Open the Test Explorer panel (beaker icon in the sidebar)
- Expand the test tree to see individual tests
- Click the play button next to any test or test file
- Use the "Run All Tests" button to run everything
From the Command Palette:
- Press
Cmd+Shift+Pand type "Test: Run All Tests"
| Icon | Meaning |
|---|---|
| Green checkmark | Test passed |
| Red X | Test failed |
| Yellow clock | Test is running |
Test output appears in the "Test Results" panel with colored output for easy reading.
- Set breakpoints in your test files
- Use VS Code's built-in debugger with the "Debug Test" option
- Step through your code with full source map support
- Click the refresh button in the Test Explorer toolbar
- Run the command "hapi/lab Test Runner: Refresh" from the Command Palette
- Ensure your test files match the
labTestExplorer.testMatchglob pattern - Check that
@hapi/labis installed in your project - Verify your test files use
test(),it(),describe(), orexperiment()functions
- Check the "Output" panel for error messages (select "hapi/lab Test Runner" from the dropdown)
- Ensure
npx labworks from your project root - Try setting an explicit
labTestExplorer.labPathif you have a non-standard setup
- Narrow down the
labTestExplorer.testMatchpattern to be more specific - Ensure
node_modulesis not being scanned (it's excluded by default)
npm install # Install dependencies
npm run compile # Compile TypeScript
npm run watch # Watch for changes during development
npm test # Run tests
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage
npm run lint # Lint code
npm run lint:fix # Lint and auto-fix issues
npm run package # Package extension for production
npm run vsce:package # Create .vsix file for distributionContributions are welcome! Please feel free to submit a Pull Request.
