Angular Jasmine Test Runner

A VS Code extension that lets you run individual Angular/Jasmine/Karma test files with a single click - no need to run the entire test suite!
✨ Features
- 🚀 One-Click Test Execution: Run test files or entire folders instantly
- 📂 Right-Click Menu: Run tests from File Explorer context menu
- 🎯 Editor Title Bar: Run tests directly from the editor using the beaker icon button
- ⚙️ Flexible Setup: Works with npm scripts or direct Angular CLI commands
- 🔍 Smart Detection: Automatically detects library name from file path
- 📊 Clear Output: View results in Output Panel and Terminal
🚀 Quick Start
Step 1: Install the Extension
- Open VS Code
- Press
Ctrl+Shift+X (or Cmd+Shift+X on Mac) to open Extensions
- Search for "Angular Jasmine Test Runner"
- Click Install
Method A: Using npm Scripts (Easiest)
If you already have a test script in your package.json:
- Open VS Code Settings (
Ctrl+, or Cmd+,)
- Search for
runSingleTest
- Set these values:
- ✅
runSingleTest.usePackageJsonScript: true
runSingleTest.packageJsonScript: test (or your script name)
That's it! You're ready to use the extension.
Method B: Using Direct Angular CLI Command
- Open VS Code Settings (
Ctrl+, or Cmd+,)
- Search for
runSingleTest
- Configure one of these options:
Option 1: Auto-detect Library Name (Recommended)
- ✅
runSingleTest.autoDetectLibraryName: true
runSingleTest.usePackageJsonScript: false
Option 2: Manual Library Name
runSingleTest.libraryName: your-library-name (e.g., my-app, shared-lib)
runSingleTest.autoDetectLibraryName: false
runSingleTest.usePackageJsonScript: false
Step 3: Run Your Tests!
Method 1: From File Explorer (Right-Click)
- Open File Explorer in VS Code (
Ctrl+Shift+E or Cmd+Shift+E)
- Right-click on a test file (
.spec.ts or .test.ts)
- Select "Run Tests" from the context menu
- Or right-click on a folder to run all tests in that folder
Method 2: From Editor Title Bar
- Open any test file (
.spec.ts or .test.ts) in the editor
- Look for the "Run Tests" button (beaker icon) in the editor title bar
- Click it!
📖 Detailed Usage Guide
Running a Single Test File
From File Explorer:
- Right-click on the test file
- Click "Run Tests"
From Editor:
- Open the test file
- Click the "Run Tests" button in the editor title bar
Running All Tests in a Folder
- Right-click on a folder in File Explorer
- Select "Run Tests"
- All
.spec.ts files in that folder will run
⚙️ Configuration Reference
All Available Settings
Open VS Code Settings (Ctrl+,) and search for runSingleTest:
| Setting |
Type |
Default |
Description |
runSingleTest.usePackageJsonScript |
boolean |
false |
Use npm script instead of direct ng test command |
runSingleTest.packageJsonScript |
string |
"test" |
Name of the npm script in package.json |
runSingleTest.ngTestCommand |
string |
"node --max_old_space_size=15360 node_modules/@angular/cli/bin/ng test" |
Full command to run ng test |
runSingleTest.libraryName |
string |
"" |
Library/project name for ng test (e.g., my-app) |
runSingleTest.autoDetectLibraryName |
boolean |
false |
Automatically detect library name from file path |
runSingleTest.ngTestArgs |
string |
"--configuration=withConfig --browsers=ChromeDebug" |
Additional arguments for ng test |
Configuration Examples
Example 1: Simple npm Script Setup
{
"runSingleTest.usePackageJsonScript": true,
"runSingleTest.packageJsonScript": "test"
}
This runs: npm run test -- --include <filePath>
Example 2: Auto-detect Library Name
{
"runSingleTest.usePackageJsonScript": false,
"runSingleTest.autoDetectLibraryName": true,
"runSingleTest.ngTestCommand": "node --max_old_space_size=15360 node_modules/@angular/cli/bin/ng test",
"runSingleTest.ngTestArgs": "--configuration=withConfig --browsers=ChromeDebug"
}
How it works:
- Test file:
termeh-patterns/src/lib/search/trp-search.component.spec.ts
- Detected library:
termeh-patterns (first folder in path)
Example 3: Manual Library Name
{
"runSingleTest.usePackageJsonScript": false,
"runSingleTest.autoDetectLibraryName": false,
"runSingleTest.libraryName": "my-library",
"runSingleTest.ngTestCommand": "node --max_old_space_size=15360 node_modules/@angular/cli/bin/ng test",
"runSingleTest.ngTestArgs": "--configuration=withConfig --browsers=ChromeDebug"
}
Important Notes
⚠️ Required Configuration:
- If
usePackageJsonScript is false, you must configure either:
autoDetectLibraryName: true, OR
libraryName: "your-library-name"
If neither is configured, you'll see an error message asking you to set one of them.
🔧 How It Works
- File Detection: The extension detects test files (
.spec.ts or .test.ts)
- Command Building: It constructs the appropriate test command based on your configuration
- Execution: The command runs in VS Code's integrated terminal
- Output: Results appear in both the Terminal and Output Panel
Example Generated Command
For a test file at src/app/components/my-component.spec.ts with library name my-app:
node --max_old_space_size=15360 node_modules/@angular/cli/bin/ng test my-app --configuration=withConfig --browsers=ChromeDebug --include src/app/components/my-component.spec.ts
🐛 Troubleshooting
Problem: You're using direct ng test command but haven't configured library name detection.
Solution:
- Set
runSingleTest.autoDetectLibraryName to true, OR
- Set
runSingleTest.libraryName to your library name
Problem: Auto-detection is enabled but couldn't find a library name in the file path.
Solution:
- Set
runSingleTest.libraryName manually, OR
- Ensure your test files are in a folder structure like
library-name/src/...
Tests Not Running
Check:
- Is the file a test file? (must end with
.spec.ts or .test.ts)
- Are your configuration settings correct?
- Check the Output Panel for error messages
- Make sure you're right-clicking on the file/folder in File Explorer, or using the button in the editor title bar
Solution:
- Make sure the file is a test file (
.spec.ts or .test.ts)
- The button appears in the editor title bar when a test file is open
- Try closing and reopening the file
📝 Changelog
See CHANGELOG.md for detailed version history.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
👤 Author
Mahdi Hajian
Enjoy faster test development! 🚀