Skip to content
Vitest 3
Main Navigation Guide & APIConfigBrowser ModeAdvanced API
3.2.0
2.1.9
1.6.1
0.34.6

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

Appearance

Sidebar Navigation

API

Node API

Getting Started

Vitest

TestProject

TestSpecification

Test Task API

TestCase

TestSuite

TestModule

TestCollection

Plugin API

Runner API

Reporters API

Task Metadata

Guides

Running Tests

Extending Reporters

Custom Pool

Config Reference

Test API Reference

On this page

TestSpecification ​

The TestSpecification class describes what module to run as a test and its parameters.

You can only create a specification by calling createSpecification method on a test project:

ts
const specification = project.createSpecification(
  resolve('./example.test.ts'),
  [20, 40] // optional test lines
);

createSpecification expects resolved module ID. It doesn't auto-resolve the file or check that it exists on the file system.

taskId ​

Test module's identifier.

project ​

This references the TestProject that the test module belongs to.

moduleId ​

The ID of the module in Vite's module graph. Usually, it's an absolute file path using posix separator:

ts
'C:/Users/Documents/project/example.test.ts'; // ✅
'/Users/mac/project/example.test.ts'; // ✅
'C:\\Users\\Documents\\project\\example.test.ts'; // ❌

testModule ​

Instance of TestModule associated with the specification. If test wasn't queued yet, this will be undefined.

pool experimental ​

The pool in which the test module will run.

DANGER

It's possible to have multiple pools in a single test project with poolMatchGlob and typecheck.enabled. This means it's possible to have several specifications with the same moduleId but different pool. In Vitest 4, the project will only support a single pool, and this property will be removed.

testLines ​

This is an array of lines in the source code where the test files are defined. This field is defined only if the createSpecification method received an array.

Note that if there is no test on at least one of the lines, the whole suite will fail. An example of a correct testLines configuration:

ts
const specification = project.createSpecification(
  resolve('./example.test.ts'),
  [3, 8, 9]
);
ts
import { test, describe } from 'vitest'

test('verification works')

describe('a group of tests', () => { 
  // ...

  test('nested test')
  test.skip('skipped test')
})
1
2
3
4
5
6
7
8
9
10

toJSON ​

ts
function toJSON(): SerializedTestSpecification;

toJSON generates a JSON-friendly object that can be consumed by the Browser Mode or Vitest UI.

Pager
Previous pageTestProject
Next pageTestCase

Released under the MIT License.

Copyright (c) 2021-Present Vitest Team

https://vitest.dev/advanced/api/test-specification

Released under the MIT License.

Copyright (c) 2021-Present Vitest Team