Main Vitest OOP decorator class Provides class-based test definition with Allure integration OOP test decorators for Vitest with Allure support

Remarks

Features:

  • Class-based test definition with decorators
  • Full Allure reporting integration
  • Scenario pattern for reusable test steps
  • Test lifecycle hooks (beforeAll, afterAll, before, after)
  • Test modifiers (skip, only, todo, timeout, repeats)
  • Suite options (mode, timeout, retries)
  • TypeScript support with full type safety

Example

import { suite, test, epic, severity, owner, tags } from '@biorate/vitest';
import { Severity } from 'allure-js-commons';
import 'reflect-metadata';

@suite('Authentication')
class AuthTest {
@epic('Security')
@feature('Login')
@story('User Authentication')
@severity(Severity.CRITICAL)
@owner('user-id-123')
@tags('auth', 'login', 'critical')
@test('should authenticate user')
async shouldAuthenticate() {
// test implementation
}
}

Example

import { suite, test, skip, only, todo, timeout, repeats } from '@biorate/vitest';

@suite('Edge Cases')
class EdgeCasesTest {
@skip()
@test('skip this test')
async skippedTest() {
// will be skipped
}

@only()
@test('run only this test')
async exclusiveTest() {
// only this test will run
}

@todo()
@test('todo test')
async todoTest() {
// marked as todo
}

@timeout(5000)
@test('test with timeout')
async timeoutTest() {
// will timeout after 5 seconds
}

@repeats(3, { mode: 'series' })
@test('flaky test')
async flakyTest() {
// will run 3 times in series
}
}

Example

import { Scenario, Step, Context } from '@biorate/vitest';

export class LoginScenario extends Scenario {
@Step('Open login page')
protected async openPage() {
await this.context.page.goto('/login');
}

@Step('Enter credentials')
protected async enterCredentials() {
await this.context.page.fill('#username', 'user');
await this.context.page.fill('#password', 'pass');
}
}

@suite('Login Flow')
class LoginTest {
@test('should login successfully')
async testLogin() {
await Context.run([LoginScenario], { page: this.page });
}
}

Example

import { suite, test } from '@biorate/vitest';

@suite('Database Tests')
class DatabaseTest {
protected static async beforeAll() {
// Setup before all tests
}

protected static async afterAll() {
// Cleanup after all tests
}

protected async before() {
// Setup before each test
}

protected async after() {
// Cleanup after each test
}

@test('should connect')
async shouldConnect() {
// test implementation
}
}

Constructors

Properties

allureStep: any

Deprecated

Use Allure step API directly. This is for Mocha compatibility. Step decorator for Mocha migration

allureSuite: any
attachment: any

Deprecated

Use Allure attachment API directly. This is for Mocha compatibility. Attachment decorator for Mocha migration

context: any

Deprecated

Context symbol for Mocha compatibility. Use Vitest's test context directly. Context symbol for Mocha migration

data: any

Deprecated

Data decorator for Mocha compatibility (parameterized tests) Use Vitest's native parameterized tests instead.

description: any
epic: any
feature: any
id: any
issue: any
label: any
link: any
only: any

Only decorator factory

Example

@only()
onlyIfEnv: any

OnlyIfEnv decorator factory - run test only if env variable matches

Example

@onlyIfEnv('CI', 'true')
owner: any
parallel: any

Deprecated

Use suite with { mode: 'parallel' } instead. This decorator is for Mocha compatibility. Parallel decorator factory for Mocha migration

Example

@parallel(true)
params: any

Deprecated

Use params from test context instead. This decorator is for Mocha compatibility. Params decorator factory for Mocha migration

Example

@params([1, 2], [3, 4])
parentSuite: any
pending: any

Deprecated

Use skip instead. This decorator is for Mocha compatibility. Pending decorator factory for Mocha migration

Example

@pending()
repeats: any

Repeats decorator factory

Example

@repeats(3)
retries: any

Deprecated

Use repeats instead. This decorator is for Mocha compatibility. Retries decorator factory for Mocha migration

Example

@retries(3)
severity: any
skip: any

Skip decorator factory

Example

@skip()
slow: any

Deprecated

Use timeout instead. This decorator is for Mocha compatibility. Slow decorator factory for Mocha migration

Example

@slow(1000)
story: any
subSuite: any
suite: any

Suite decorator factory

Param: name

Suite name (optional, defaults to class name)

Param: options

Suite options (timeout, retries, mode)

Returns

Class decorator

Example

@suite('My Test Suite')
class MyTest {}

Example

@suite('Parallel Suite', { mode: 'parallel', timeout: 10000, retries: 2 })
class ParallelTest {}
tag: any
tags: any
test: any

Test decorator factory

Example

@test('should work')
testCaseId: any

Deprecated

Use id instead. This is for Mocha compatibility. TestCaseId decorator for Mocha migration

timeout: any

Timeout decorator factory

Example

@timeout(5000)
todo: any

Todo decorator factory

Example

@todo()

Methods

  • Parameters

    • nameFn: string

      Step name or function

    Returns ((target, propertyKey, descriptor) => PropertyDescriptor)

      • (target, propertyKey, descriptor): PropertyDescriptor
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns PropertyDescriptor

    Deprecated

    Use Allure step API directly. Mocha compatibility decorator. Step decorator for Mocha migration

  • Apply Allure metadata to the current test

    Parameters

    • allureMethods: AllureMetadata

      Allure methods and their arguments

    Returns Promise<void>

  • Parameters

    • name: string

      Attachment name

    • content: string | Buffer

      Attachment content

    • Optional type: string

      Content type

    Returns ((target, propertyKey, descriptor) => PropertyDescriptor)

      • (target, propertyKey, descriptor): PropertyDescriptor
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns PropertyDescriptor

    Deprecated

    Use Allure attachment API directly. Mocha compatibility decorator. Attachment decorator for Mocha migration

  • Create an Allure decorator factory

    Parameters

    • methodName: string

      Allure method name

    • append: boolean = false

      Whether to append multiple values

    Returns ((...args) => ((target, propertyKey?, descriptor?) => void))

      • (...args): ((target, propertyKey?, descriptor?) => void)
      • Parameters

        • Rest ...args: string[]

        Returns ((target, propertyKey?, descriptor?) => void)

          • (target, propertyKey?, descriptor?): void
          • Parameters

            • target: any
            • Optional propertyKey: string
            • Optional descriptor: PropertyDescriptor

            Returns void

  • Create an issue decorator with optional URL

    Returns ((name, url?) => ((target, propertyKey?, descriptor?) => void))

      • (name, url?): ((target, propertyKey?, descriptor?) => void)
      • Parameters

        • name: string
        • Optional url: string

        Returns ((target, propertyKey?, descriptor?) => void)

          • (target, propertyKey?, descriptor?): void
          • Parameters

            • target: any
            • Optional propertyKey: string
            • Optional descriptor: PropertyDescriptor

            Returns void

  • Create a link decorator with optional type parameter

    Returns ((url, name?, type?) => ((target, propertyKey?, descriptor?) => void))

      • (url, name?, type?): ((target, propertyKey?, descriptor?) => void)
      • Parameters

        • url: string
        • Optional name: string
        • Optional type: string

        Returns ((target, propertyKey?, descriptor?) => void)

          • (target, propertyKey?, descriptor?): void
          • Parameters

            • target: any
            • Optional propertyKey: string
            • Optional descriptor: PropertyDescriptor

            Returns void

  • Parameters

    • params: any

      Test parameters

    • Optional name: string

      Optional test name

    Returns ((target, propertyKey, descriptor) => PropertyDescriptor)

      • (target, propertyKey, descriptor): PropertyDescriptor
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns PropertyDescriptor

    Deprecated

    Data decorator for Mocha compatibility (parameterized tests). Use Vitest's native parameterized tests instead.

  • Only decorator factory

    Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

  • OnlyIfEnv decorator factory - run test only if env variable matches

    Parameters

    • variableName: string

      Environment variable name

    • expectedValue: string

      Expected value

    Returns ((target, propertyKey?, descriptor?) => void)

      • (target, propertyKey?, descriptor?): void
      • Parameters

        • target: any
        • Optional propertyKey: string
        • Optional descriptor: PropertyDescriptor

        Returns void

  • Parameters

    • enabled: boolean

      Whether to enable parallel execution

    Returns ((target) => void)

      • (target): void
      • Parameters

        • target: any

        Returns void

    Deprecated

    Use #suite with { mode: 'parallel' } instead. Mocha compatibility decorator. Parallel decorator factory for Mocha migration

  • Parameters

    • Rest ...paramsList: any[][]

      List of parameter sets

    Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

    Deprecated

    Params are handled differently in Vitest. Mocha compatibility decorator. Params decorator factory for Mocha migration

  • Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

    Deprecated

    Use #skip instead. Mocha compatibility decorator. Pending decorator factory for Mocha migration

  • Register a single test method with Vitest

    Parameters

    • instance: any

      Class instance

    • name: string

      Method name

    • method: ((...args) => void | Promise<void>)

      Method function

        • (...args): void | Promise<void>
        • Parameters

          • Rest ...args: any[]

          Returns void | Promise<void>

    • meta: TestMetadata

      Test metadata

    Returns void

  • Repeats decorator factory

    Parameters

    • count: number

      Number of repeats (must be positive)

    • Optional options: {
          mode?: "series" | "queue";
      }

      Repeat options

      • Optional mode?: "series" | "queue"

    Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

  • Parameters

    • count: number

      Number of retries (must be non-negative)

    Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

    Deprecated

    Use #repeats instead. Mocha compatibility decorator. Retries decorator factory for Mocha migration

  • Set Allure metadata method for a test

    Parameters

    • target: any

      Method or class target

    • method: string

      Allure method name (e.g., 'epic', 'severity')

    • args: any[]

      Method arguments

    • append: boolean = false

      Whether to append to existing metadata

    Returns void

  • Skip decorator factory

    Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

  • Parameters

    • ms: number

      Slow threshold in milliseconds

    Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

    Deprecated

    Use #timeout instead. Mocha compatibility decorator. Slow decorator factory for Mocha migration

  • Suite decorator factory

    Parameters

    • Optional name: string

      Suite name (optional, defaults to class name)

    • Optional options: SuiteOptions

      Suite options (timeout, retries, mode)

    Returns ((Class) => void)

      • (Class): void
      • Parameters

        • Class: (new () => any)
            • new (): any
            • Returns any

        Returns void

  • Test decorator factory

    Parameters

    • Optional name: string

      Test name (optional, defaults to method name)

    Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

  • Parameters

    • id: string

      Test case ID

    Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

    Deprecated

    Use #id instead. Mocha compatibility decorator. TestCaseId decorator for Mocha migration

  • Timeout decorator factory

    Parameters

    • ms: number

      Timeout in milliseconds (must be positive)

    Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

  • Todo decorator factory

    Returns ((target, propertyKey, descriptor) => void)

      • (target, propertyKey, descriptor): void
      • Parameters

        • target: any
        • propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void