Skip to content

Latest commit

 

History

History
804 lines (480 loc) · 26.2 KB

API.md

File metadata and controls

804 lines (480 loc) · 26.2 KB

API Reference

Constructs

Vitest

Initializers

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.

projectRequired
  • Type: projen.javascript.NodeProject

optionsOptional

Methods

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.

toString
public toString(): string

Returns a string representation of this construct.

postSynthesize
public postSynthesize(): void

Called after synthesis.

Order is not guaranteed.

preSynthesize
public preSynthesize(): void

Called before synthesis.

synthesize
public synthesize(): void

Synthesizes files to the project output directory.

addExclude
public addExclude(pattern: string): void
patternRequired
  • Type: string

addInclude
public addInclude(pattern: string): void
patternRequired
  • Type: string

configureCoverageProvider
public configureCoverageProvider(provider: CoverageProvider): void
providerRequired

configureCoverageReporters
public configureCoverageReporters(reporters: CoverageReporter[]): void
reportersRequired

configureEnvironment
public configureEnvironment(environment: Environment): void
environmentRequired

configureGlobals
public configureGlobals(): void

Static Functions

Name Description
isConstruct Checks if x is a construct.
isComponent Test whether the given construct is a component.
of No description.

isConstruct
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.

xRequired
  • Type: any

Any object.


isComponent
import { Vitest } from '@nikovirtala/projen-vitest'

Vitest.isComponent(x: any)

Test whether the given construct is a component.

xRequired
  • Type: any

of
import { Vitest } from '@nikovirtala/projen-vitest'

Vitest.of(project: NodeProject)
projectRequired
  • Type: projen.javascript.NodeProject

Properties

Name Type Description
node constructs.Node The tree node.
project projen.Project No description.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


projectRequired
public readonly project: Project;
  • Type: projen.Project

Structs

VitestConfigOptions

Vitest Config.

https://vitest.dev/config/

Initializer

import { VitestConfigOptions } from '@nikovirtala/projen-vitest'

const vitestConfigOptions: VitestConfigOptions = { ... }

Properties

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.

bailOptional
public readonly bail: number;
  • Type: number
  • Default: 0

Stop running tests after certain number of failures.

https://vitest.dev/config/#bail


coverageDirectoryOptional
public readonly coverageDirectory: string;
  • Type: string
  • Default: "coverage"

Coverage output directory.


coverageEnabledOptional
public readonly coverageEnabled: boolean;
  • Type: boolean
  • Default: true

Coverage enabled.

https://vitest.dev/config/#coverage-enabled


coverageProviderOptional
public readonly coverageProvider: CoverageProvider;

Coverage provider type.

https://vitest.dev/config/#coverage-provider


coverageReportersOptional
public readonly coverageReporters: CoverageReporter[];

Coverage reporters.

https://vitest.dev/config/#coverage-reporter


environmentOptional
public readonly environment: Environment;

The environment that will be used for testing.

https://vitest.dev/config/#environment


excludeOptional
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


globalsOptional
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


includeOptional
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


isolateOptional
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


passWithNoTestsOptional
public readonly passWithNoTests: boolean;
  • Type: boolean
  • Default: true

Vitest will not fail, if no tests will be found.

https://vitest.dev/config/#passwithnotests


poolOptional
public readonly pool: Pool;
  • Type: Pool
  • Default: "forks"

Pool used to run tests in.

https://vitest.dev/config/#pool


printConsoleTraceOptional
public readonly printConsoleTrace: boolean;
  • Type: boolean
  • Default: true

Always print console traces when calling any console method.

https://vitest.dev/config/#consoletrace


slowTestThresholdOptional
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


typecheckCheckerOptional
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


typecheckEnabledOptional
public readonly typecheckEnabled: boolean;
  • Type: boolean
  • Default: true (for TypeScript projects)

Enable typechecking alongside your regular tests.

https://vitest.dev/config/#typecheck-enabled


typecheckTsconfigOptional
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


updateSnapshotsOptional
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


VitestOptions

Initializer

import { VitestOptions } from '@nikovirtala/projen-vitest'

const vitestOptions: VitestOptions = { ... }

Properties

Name Type Description
config VitestConfigOptions Initial config options.
configFilePath string Config file path.
vitestVersion string Vitest version.

configOptional
public readonly config: VitestConfigOptions;

Initial config options.


configFilePathOptional
public readonly configFilePath: string;
  • Type: string
  • Default: "vitest.config.ts"

Config file path.


vitestVersionOptional
public readonly vitestVersion: string;
  • Type: string
  • Default: "^2"

Vitest version.


Enums

CoverageProvider

Members

Name Description
ISTANBUL Provide coverage report using istanbul.
V8 Provide coverage reports using v8.

ISTANBUL

Provide coverage report using istanbul.

https://istanbul.js.org


V8

Provide coverage reports using v8.

https://v8.dev/blog/javascript-code-coverage


CoverageReporter

Members

Name Description
CLOVER Provides clover report.
HTML Provides HTML report.
JSON Provides JSON report.
LCOV Provides LCOV report.
TEXT Provides text report.

CLOVER

Provides clover report.


HTML

Provides HTML report.


JSON

Provides JSON report.


LCOV

Provides LCOV report.


TEXT

Provides text report.


Environment

Members

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.

EDGE_RUNTIME

Run tests in Vercel's Edge Runtime VM.

https://edge-runtime.vercel.app/packages/vm


HAPPY_DOM

Run tests in happy-dom environment.

https://github.com/capricorn86/happy-dom


JSDOM

Run tests in jsdom environment.

https://github.com/jsdom/jsdom


NODE

Run tests in a Node.js environment.


Pool

Members

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.

FORKS

Run tests in node:child_process using fork().

Test isolation (when enabled) is done by spawning a new child process for each test file.


THREADS

Run tests in node:worker_threads.

Test isolation (when enabled) is done by spawning a new thread for each test file.


VMFORKS

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.


VMTHREADS

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.