Skip to main content

Shared Test Utilities (@utils-test)

The @wrkbelt/shared/utils-test package provides common utilities that can be used across different types of tests (UI, API, unit). These utilities help standardize test configuration, environment handling, and reporting.

Installation

npm install @wrkbelt/shared/utils-test --save-dev

Features

Environment Utilities

The package includes utilities for working with different environments:

import { getValueByEnv, Environments } from '@wrkbelt/shared/utils-test';

// Configure different values for different environments
const apiUrl = getValueByEnv({
[Environments.local]: 'http://localhost:3000',
[Environments.staging]: 'https://staging-api.example.com',
default: 'https://api.example.com',
});

console.log(apiUrl); // Returns the appropriate URL based on current environment

Reporting Utilities

The package provides utilities for enhancing test reports, especially in CI/CD environments:

import { getMetaInformation } from '@wrkbelt/shared/utils-test';

// Add metadata to test reports
const metadata = getMetaInformation();
// Use with your test reporter

The getMetaInformation function returns:

  • Revision information (commit ID, author, timestamp)
  • PR or commit links
  • CI workflow links
  • Environment details

This metadata can be useful for:

  • Identifying which code version was tested
  • Linking test results to specific commits or PRs
  • Tracking test execution across different environments

Constants

The package defines common constants used across tests:

import { Environments, sharedFilePaths } from '@wrkbelt/shared/utils-test';

// Environment enum
console.log(Environments.staging); // 'staging'

// Common file paths
console.log(sharedFilePaths.organizationId); // 'organization-id.json'

Best Practices

  • Use environment utilities to handle environment-specific configuration
  • Add metadata to test reports in CI/CD pipelines
  • Share common constants across test suites
  • Combine with @utils-test-api and @utils-test-ui for comprehensive test coverage