import { Vitest } from '@nikovirtala/projen-vitest'
new Vitest(project: NodeProject, options?: VitestOptions)
Name | Type | Description |
---|---|---|
project |
projen.javascript.NodeProject |
No description. |
options |
VitestOptions |
No description. |
- Type: projen.javascript.NodeProject
- Type: VitestOptions
Name | Description |
---|---|
toString |
Returns a string representation of this construct. |
postSynthesize |
Called after synthesis. |
preSynthesize |
Called before synthesis. |
synthesize |
Synthesizes files to the project output directory. |
addExclude |
No description. |
addInclude |
No description. |
configureCoverageProvider |
No description. |
configureCoverageReporters |
No description. |
configureEnvironment |
No description. |
configureGlobals |
No description. |
public toString(): string
Returns a string representation of this construct.
public postSynthesize(): void
Called after synthesis.
Order is not guaranteed.
public preSynthesize(): void
Called before synthesis.
public synthesize(): void
Synthesizes files to the project output directory.
public addExclude(pattern: string): void
- Type: string
public addInclude(pattern: string): void
- Type: string
public configureCoverageProvider(provider: CoverageProvider): void
- Type: CoverageProvider
public configureCoverageReporters(reporters: CoverageReporter[]): void
- Type: CoverageReporter[]
public configureEnvironment(environment: Environment): void
- Type: Environment
public configureGlobals(): void
Name | Description |
---|---|
isConstruct |
Checks if x is a construct. |
isComponent |
Test whether the given construct is a component. |
of |
No description. |
import { Vitest } from '@nikovirtala/projen-vitest'
Vitest.isConstruct(x: any)
Checks if x
is a construct.
Use this method instead of instanceof
to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs
library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct
in each copy of the constructs
library
is seen as a different class, and an instance of one class will not test as
instanceof
the other class. npm install
will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof
will behave
unpredictably. It is safest to avoid using instanceof
, and using
this type-testing method instead.
- Type: any
Any object.
import { Vitest } from '@nikovirtala/projen-vitest'
Vitest.isComponent(x: any)
Test whether the given construct is a component.
- Type: any
import { Vitest } from '@nikovirtala/projen-vitest'
Vitest.of(project: NodeProject)
- Type: projen.javascript.NodeProject
Name | Type | Description |
---|---|---|
node |
constructs.Node |
The tree node. |
project |
projen.Project |
No description. |
public readonly node: Node;
- Type: constructs.Node
The tree node.
public readonly project: Project;
- Type: projen.Project
Vitest Config.
import { VitestConfigOptions } from '@nikovirtala/projen-vitest'
const vitestConfigOptions: VitestConfigOptions = { ... }
Name | Type | Description |
---|---|---|
bail |
number |
Stop running tests after certain number of failures. |
coverageDirectory |
string |
Coverage output directory. |
coverageEnabled |
boolean |
Coverage enabled. |
coverageProvider |
CoverageProvider |
Coverage provider type. |
coverageReporters |
CoverageReporter[] |
Coverage reporters. |
environment |
Environment |
The environment that will be used for testing. |
exclude |
string[] |
A list of glob patterns that should be excluded from your test files. |
globals |
boolean |
Register apis globally. |
include |
string[] |
A list of glob patterns that match your test files. |
isolate |
boolean |
Run tests in an isolated environment. This option has no effect on vmThreads pool. |
passWithNoTests |
boolean |
Vitest will not fail, if no tests will be found. |
pool |
Pool |
Pool used to run tests in. |
printConsoleTrace |
boolean |
Always print console traces when calling any console method. |
slowTestThreshold |
number |
The number of milliseconds after which a test or suite is considered slow. |
typecheckChecker |
string |
Tool to use for type checking. Checker should implement the same output format as tsc . |
typecheckEnabled |
boolean |
Enable typechecking alongside your regular tests. |
typecheckTsconfig |
string |
Path to custom tsconfig, relative to the project root. |
updateSnapshots |
boolean |
Update snapshot files. |
public readonly bail: number;
- Type: number
- Default: 0
Stop running tests after certain number of failures.
https://vitest.dev/config/#bail
public readonly coverageDirectory: string;
- Type: string
- Default: "coverage"
Coverage output directory.
public readonly coverageEnabled: boolean;
- Type: boolean
- Default: true
Coverage enabled.
https://vitest.dev/config/#coverage-enabled
public readonly coverageProvider: CoverageProvider;
- Type: CoverageProvider
- Default: "v8"
Coverage provider type.
https://vitest.dev/config/#coverage-provider
public readonly coverageReporters: CoverageReporter[];
- Type: CoverageReporter[]
- Default: '["text", "lcov"]'
Coverage reporters.
https://vitest.dev/config/#coverage-reporter
public readonly environment: Environment;
- Type: Environment
- Default: "node"
The environment that will be used for testing.
https://vitest.dev/config/#environment
public readonly exclude: string[];
- Type: string[]
- Default: Vitest's
configDefaults.exclude
A list of glob patterns that should be excluded from your test files.
https://vitest.dev/config/#exclude
public readonly globals: boolean;
- Type: boolean
- Default: false
Register apis globally.
If you prefer to use the APIs globally like Jest, set to true
.
https://vitest.dev/config/#globals
public readonly include: string[];
- Type: string[]
- Default: Vitest's
configDefaults.include
A list of glob patterns that match your test files.
https://vitest.dev/config/#include
public readonly isolate: boolean;
- Type: boolean
- Default: true
Run tests in an isolated environment. This option has no effect on vmThreads pool.
Disabling this option might improve performance if your code doesn't rely on side effects.
https://vitest.dev/config/#isolate
public readonly passWithNoTests: boolean;
- Type: boolean
- Default: true
Vitest will not fail, if no tests will be found.
https://vitest.dev/config/#passwithnotests
public readonly pool: Pool;
- Type: Pool
- Default: "forks"
Pool used to run tests in.
https://vitest.dev/config/#pool
public readonly printConsoleTrace: boolean;
- Type: boolean
- Default: true
Always print console traces when calling any console method.
https://vitest.dev/config/#consoletrace
public readonly slowTestThreshold: number;
- Type: number
- Default: 300
The number of milliseconds after which a test or suite is considered slow.
https://vitest.dev/config/#slowtestthreshold
public readonly typecheckChecker: string;
- Type: string
- Default: "tsc --noEmit"
Tool to use for type checking. Checker should implement the same output format as tsc
.
https://vitest.dev/config/#typecheck-checker
public readonly typecheckEnabled: boolean;
- Type: boolean
- Default: true (for TypeScript projects)
Enable typechecking alongside your regular tests.
https://vitest.dev/config/#typecheck-enabled
public readonly typecheckTsconfig: string;
- Type: string
- Default: "tsconfig.dev.json"
Path to custom tsconfig, relative to the project root.
https://vitest.dev/config/#typecheck-tsconfig
public readonly updateSnapshots: boolean;
- Type: boolean
- Default: true
Update snapshot files.
This will update all changed snapshots and delete obsolete ones. https://vitest.dev/guide/snapshot.html#updating-snapshots
import { VitestOptions } from '@nikovirtala/projen-vitest'
const vitestOptions: VitestOptions = { ... }
Name | Type | Description |
---|---|---|
config |
VitestConfigOptions |
Initial config options. |
configFilePath |
string |
Config file path. |
vitestVersion |
string |
Vitest version. |
public readonly config: VitestConfigOptions;
- Type: VitestConfigOptions
Initial config options.
public readonly configFilePath: string;
- Type: string
- Default: "vitest.config.ts"
Config file path.
public readonly vitestVersion: string;
- Type: string
- Default: "^2"
Vitest version.
Name | Description |
---|---|
ISTANBUL |
Provide coverage report using istanbul. |
V8 |
Provide coverage reports using v8. |
Provide coverage report using istanbul.
Provide coverage reports using v8.
https://v8.dev/blog/javascript-code-coverage
Name | Description |
---|---|
CLOVER |
Provides clover report. |
HTML |
Provides HTML report. |
JSON |
Provides JSON report. |
LCOV |
Provides LCOV report. |
TEXT |
Provides text report. |
Provides clover
report.
Provides HTML
report.
Provides JSON
report.
Provides LCOV
report.
Provides text
report.
Name | Description |
---|---|
EDGE_RUNTIME |
Run tests in Vercel's Edge Runtime VM. |
HAPPY_DOM |
Run tests in happy-dom environment. |
JSDOM |
Run tests in jsdom environment. |
NODE |
Run tests in a Node.js environment. |
Run tests in Vercel's Edge Runtime VM.
https://edge-runtime.vercel.app/packages/vm
Run tests in happy-dom
environment.
https://github.com/capricorn86/happy-dom
Run tests in jsdom
environment.
https://github.com/jsdom/jsdom
Run tests in a Node.js environment.
Name | Description |
---|---|
FORKS |
Run tests in node:child_process using fork() . |
THREADS |
Run tests in node:worker_threads . |
VMFORKS |
Run tests in isolated node:vm . |
VMTHREADS |
Run tests in isolated node:vm . Test files are run parallel using node:worker_threads . |
Run tests in node:child_process
using fork()
.
Test isolation (when enabled) is done by spawning a new child process for each test file.
Run tests in node:worker_threads
.
Test isolation (when enabled) is done by spawning a new thread for each test file.
Run tests in isolated node:vm
.
Test files are run parallel using node:child_process
fork()
This makes tests run faster, but VM module is unstable. Your tests might leak memory.
Run tests in isolated node:vm
. Test files are run parallel using node:worker_threads
.
This makes tests run faster, but VM module is unstable. Your tests might leak memory.