Vue Auto Test
A VS Code extension that instantly generates Vitest test files for Vue components and provides quick access to run tests directly from the editor.
Overview
Vue Auto Test streamlines your Vue.js testing workflow by automatically generating test files and providing convenient tools to run tests without leaving VS Code. It supports Vue 3 projects using Vitest and @vue/test-utils, with automatic detection of your project structure, package manager, and TypeScript configuration.
Perfect for projects using:
- Vue.js 3
- Script setup
- Composition API
- Vite
- Vitest
- @vue/test-utils
Key Features
Test File Generation
- One-click test file generation for any Vue component
- Automatic component name detection and conversion
- Maintains your project folder structure
- Prevents accidental overwrites
- Supports both TypeScript and JavaScript projects
Test Execution
- Run individual tests directly from the context menu
- Run tests with coverage reports
- Automatic package manager detection (npm, yarn, pnpm, bun)
- Copy test commands to clipboard
- Keyboard shortcuts for quick access
Smart Configuration
- Configurable test directory location
- Support for path aliases (@ imports)
- Customizable component name format
- Automatic TypeScript/JavaScript detection
Installation
- Open VS Code
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Search for "Vue Auto Test"
- Click Install
Quick Start
Generate a Test File
- Open any
.vue component file
- Right-click in the editor or in the Explorer
- Select "Generate Vue Test File"
- The test file is created in your configured test directory
Run a Test
- Open any
.spec.ts or .spec.js file
- Right-click in the editor
- Select "Vue Auto Test" → "Run Test"
Usage
Generating Test Files
Method 1: Context Menu (Recommended)
- Open a
.vue component file
- Right-click inside the editor or in the Explorer
- Click "Generate Vue Test File"
- The extension creates the test file in your configured test directory
Method 2: Command Palette
- Press
Ctrl+Shift+P (Cmd+Shift+P on Mac)
- Type: "Vue Auto Test: Generate Vue Test File"
- Press Enter
The generated test file will:
- Be placed in your configured test directory (default:
test folder at project root)
- Maintain the same folder structure as your source files
- Use the correct import path based on your configuration
- Include a basic rendering test as a starting point
Example:
- Component:
src/components/ExampleComponent.vue
- Test generated:
test/components/ExampleComponent.spec.ts
Running Tests
When you right-click on a .spec.ts or .spec.js file, you'll see a "Vue Auto Test" submenu with the following options:
- Run Test - Executes the test in a terminal
- Run Test with Coverage - Executes the test with coverage report
- Copy Run Test Command - Copies the test command to clipboard
- Copy Run Test with Coverage Command - Copies the test command with coverage to clipboard
Method 1: Context Menu
- Right-click on any
.spec.ts or .spec.js file in the editor or Explorer
- Hover over "Vue Auto Test" submenu
- Select your desired option
Method 2: Keyboard Shortcuts
- Run Test:
Ctrl+Alt+T (Windows/Linux) or Cmd+Alt+T (Mac)
- Run Test with Coverage:
Ctrl+Alt+Shift+T (Windows/Linux) or Cmd+Alt+Shift+T (Mac)
- Copy Run Test Command:
Ctrl+Alt+C (Windows/Linux) or Cmd+Alt+C (Mac)
- Copy Run Test with Coverage Command:
Ctrl+Alt+Shift+C (Windows/Linux) or Cmd+Alt+Shift+C (Mac)
The extension automatically detects your package manager by checking for lock files:
pnpm-lock.yaml → uses pnpm
yarn.lock → uses yarn
bun.lockb → uses bun
- Otherwise → uses
npm
Example commands generated:
pnpm vitest run test/components/example-component.spec.ts
pnpm vitest run test/components/example-component.spec.ts --coverage
Configuration
All settings can be configured in VS Code Settings (Ctrl+, / Cmd+,). Search for "Vue Auto Test Wrapper" to find all available options.
Test Directory
Set where test files are generated. Default is test folder at the project root.
Settings Path: vueAutoTestWrapper.testDirectory
Default: test
Example:
- Component:
src/components/ExampleComponent.vue
- Test Directory:
test
- Include Source Directory:
false (default)
- Test generated:
test/components/ExampleComponent.spec.ts
The extension maintains the same folder structure as your source files within the test directory, but by default removes the source directory name from the path.
With Include Source Directory enabled:
- Component:
src/components/ExampleComponent.vue
- Test Directory:
test
- Include Source Directory:
true
- Test generated:
test/src/components/ExampleComponent.spec.ts
Source Directory
Configure the source directory path used for calculating import paths.
Settings Path: vueAutoTestWrapper.sourceDirectory
Default: src
Example:
- Source Directory:
src
- Component:
src/components/Button.vue
- Import path calculated from
src directory
Use Alias (@)
Enable this option to use @ alias for imports instead of relative paths. This is useful when your project uses path aliases configured in vite.config.ts or tsconfig.json.
Settings Path: vueAutoTestWrapper.useAlias
Default: false
When enabled:
- Imports use
@/path/to/component format
- Example:
import ExampleComponent from '@/components/ExampleComponent.vue'
When disabled (default):
- Imports use relative paths
- Example:
import ExampleComponent from './ExampleComponent.vue'
Configure the format for component names in imports and test file names.
Settings Path: vueAutoTestWrapper.componentNameFormat
Default: kebab-case
Available formats:
kebab-case (default)
- File:
my-component.vue
- Import:
import MyComponent from './my-component.vue'
- Test file:
my-component.spec.ts
- Note: Uses PascalCase for import variable name (JavaScript/TypeScript doesn't allow hyphens in variable names)
camelCase
- File:
my-component.vue
- Import:
import myComponent from './my-component.vue'
- Test file:
myComponent.spec.ts
PascalCase
- File:
my-component.vue
- Import:
import MyComponent from './my-component.vue'
- Test file:
MyComponent.spec.ts
snake_case
- File:
my-component.vue
- Import:
import my_component from './my-component.vue'
- Test file:
my_component.spec.ts
Include Source Directory
Control whether the source directory name is included in the test file path.
Settings Path: vueAutoTestWrapper.includeSourceDirectory
Default: false
When false (default):
- Component:
src/views/salas-raid.vue
- Test generated:
test/views/salas-raid.spec.js
When true:
- Component:
src/views/salas-raid.vue
- Test generated:
test/src/views/salas-raid.spec.js
This setting allows you to choose whether to mirror the exact source directory structure including the source directory name, or to create a cleaner test structure without it.
Generated Test Structure
The extension generates tests with the following structure:
import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import ComponentName from './ComponentName.vue'
describe('ComponentName.vue', () => {
it('renders correctly', () => {
const wrapper = mount(ComponentName)
expect(wrapper.exists()).toBe(true)
})
})
For JavaScript projects, the same structure is generated with .spec.js extension:
import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import ComponentName from './ComponentName.vue'
describe('ComponentName.vue', () => {
it('renders correctly', () => {
const wrapper = mount(ComponentName)
expect(wrapper.exists()).toBe(true)
})
})
This provides:
- Explicit imports from Vitest (
describe, it, expect) for compatibility with all Vitest configurations
- Proper imports from @vue/test-utils
- Correct import path to your component (relative or alias-based)
- Proper component name in imports (based on your format configuration)
- Basic rendering test as starting point
- TypeScript or JavaScript support (automatically detected)
Note: If your component uses plugins like vue-i18n, vue-router, or pinia, you'll need to configure them in the test. For example, for vue-i18n:
import { createI18n } from 'vue-i18n'
const i18n = createI18n({
legacy: false,
locale: 'en',
fallbackLocale: 'en',
messages: {}
})
const wrapper = mount(ComponentName, {
global: {
plugins: [i18n]
}
})
Use Cases
Use Case 1: Quick Test Setup for New Components
Scenario: You've just created a new Vue component and need to set up tests immediately.
Steps:
- Create your component:
src/components/MyComponent.vue
- Right-click in the editor
- Select "Generate Vue Test File"
- Result:
test/components/MyComponent.spec.ts is created with a basic test
Benefit: No manual file creation, no import path calculation, no boilerplate typing.
Use Case 2: Running Individual Tests During Development
Scenario: You're working on a specific component and want to run only its tests.
Steps:
- Open the test file:
test/components/MyComponent.spec.ts
- Right-click in the editor
- Select "Vue Auto Test" → "Run Test"
- The test runs in a terminal using your package manager
Benefit: Quick feedback without running the entire test suite.
Use Case 3: Checking Test Coverage
Scenario: You want to see coverage for a specific component.
Steps:
- Open the test file
- Right-click in the editor
- Select "Vue Auto Test" → "Run Test with Coverage"
- Coverage report is generated
Benefit: Immediate visibility into what parts of your component are tested.
Use Case 4: Consistent Test Structure Across Team
Scenario: Your team needs consistent test file structure and naming conventions.
Steps:
- Configure the extension settings in your workspace
- Team members use the extension for all new components
- All tests follow the same structure automatically
Benefit: Uniform codebase, easier code reviews, predictable test locations.
Use Case 5: Testing Components in Nested Folders
Scenario: Your project uses feature-based folder structure with nested components.
Example structure:
src/
features/
dashboard/
components/
Header.vue
Sidebar.vue
views/
HomePage.vue
With default test directory (test), tests are generated as:
test/
features/
dashboard/
components/
Header.spec.ts
Sidebar.spec.ts
views/
HomePage.spec.ts
Steps:
- Open any component in nested folders
- Generate test file
- Import paths are automatically calculated correctly
- Test file is created in the corresponding location in the test directory
Benefit: Works regardless of folder depth or structure, maintaining organized test structure.
Use Case 6: Using Path Aliases
Scenario: Your project uses @ alias for imports configured in vite.config.ts or tsconfig.json.
Steps:
- Enable "Use Alias" in extension settings
- Generate test files
- Imports will use
@/path/to/component format
Example:
- Component:
src/components/Button.vue
- Generated import:
import Button from '@/components/Button.vue'
Benefit: Consistent with your project's import style.
Requirements
- VS Code version 1.80.0 or higher
- Vue 3 project
- Vitest installed in your project
- @vue/test-utils installed in your project
Keyboard Shortcuts
| Action |
Windows/Linux |
Mac |
| Run Test |
Ctrl+Alt+T |
Cmd+Alt+T |
| Run Test with Coverage |
Ctrl+Alt+Shift+T |
Cmd+Alt+Shift+T |
| Copy Run Test Command |
Ctrl+Alt+C |
Cmd+Alt+C |
| Copy Run Test with Coverage Command |
Ctrl+Alt+Shift+C |
Cmd+Alt+Shift+C |
Shortcuts only work when editing .spec.ts or .spec.js files.
Extension Settings
This extension contributes the following settings:
vueAutoTestWrapper.testDirectory - Directory where test files are generated (default: test)
vueAutoTestWrapper.sourceDirectory - Source directory path (default: src)
vueAutoTestWrapper.useAlias - Use @ alias for imports (default: false)
vueAutoTestWrapper.componentNameFormat - Component name format: kebab-case, camelCase, PascalCase, or snake_case (default: kebab-case)
vueAutoTestWrapper.includeSourceDirectory - Include the source directory name in the test file path (default: false)
Commands
The extension provides the following commands (accessible via Command Palette):
Vue Auto Test: Generate Vue Test File - Generate a test file for the current Vue component
Vue Auto Test: Run Test - Run the current test file
Vue Auto Test: Run Test with Coverage - Run the current test file with coverage
Vue Auto Test: Copy Run Test Command - Copy the test command to clipboard
Vue Auto Test: Copy Run Test with Coverage Command - Copy the test command with coverage to clipboard
Vue Component Files (.vue)
- Generate Vue Test File - Appears when right-clicking on
.vue files
Test Files (.spec.ts, .spec.js)
- Vue Auto Test submenu with:
- Run Test
- Run Test with Coverage
- Copy Run Test Command
- Copy Run Test with Coverage Command
Troubleshooting
If the menu doesn't appear for .spec.js files, try:
- Reload the VS Code window:
Ctrl+Shift+P → "Reload Window"
- Close and reopen VS Code
- Ensure the file extension is exactly
.spec.js (not .test.js or other variations)
Test commands don't work
Ensure:
- Vitest is installed in your project
- Your project has a valid
package.json
- The test file path is correct
Import paths are incorrect
Check your configuration:
- Verify the
sourceDirectory setting matches your project structure
- If using aliases, ensure
useAlias is enabled and your project has alias configuration in vite.config.ts or tsconfig.json
Release Notes
1.0.0
Initial release:
- Generate test files for Vue components
- Automatic component name detection and conversion
- Context menu integration for Vue files and test files
- Command palette support
- Run individual tests from context menu
- Run tests with coverage
- Copy test commands to clipboard
- Keyboard shortcuts for test operations
- Automatic package manager detection
- Automatic TypeScript/JavaScript detection
- Configurable test directory
- Support for path aliases
- Configurable component name format
- Duplicate file protection
- Proper import path calculation
Contributing
Contributions are welcome! Please feel free to submit a Pull Request on the extension's GitHub repository.
License
This extension is licensed under the MIT License.
Support
For issues, feature requests, or questions, please visit the extension's repository on GitHub.