Files
hash-map/docs/TEAMCITY.md

3.0 KiB

TeamCity Test Integration

This project includes TeamCity test reporting integration using the TeamcityReporter class.

Usage

In TeamCity CI

When running tests in TeamCity, use the test:teamcity script:

bun run test:teamcity

This will automatically detect the TeamCity environment (via TEAMCITY_VERSION env variable) and output test results in TeamCity's service message format.

Local Development

For local testing, simply use:

bun test

The TeamCity reporter will be disabled automatically when not running in TeamCity.

How It Works

The integration uses a TAP (Test Anything Protocol) to TeamCity converter:

  1. TAP Reporter: Bun's built-in TAP reporter outputs test results in TAP format
  2. Converter: scripts/test-tap-teamcity.ts parses TAP output and converts it to TeamCity service messages
  3. TeamcityReporter: tests/TeamcityReporter.ts formats and outputs TeamCity service messages

TeamCity Service Messages

The reporter outputs the following TeamCity service messages:

  • ##teamcity[testSuiteStarted name='...'] - When a test suite starts
  • ##teamcity[testSuiteFinished name='...'] - When a test suite ends
  • ##teamcity[testStarted name='...'] - When a test starts
  • ##teamcity[testFinished name='...'] - When a test completes successfully
  • ##teamcity[testFailed name='...' message='...' details='...'] - When a test fails
  • ##teamcity[testIgnored name='...'] - When a test is skipped

Special Character Escaping

The reporter properly escapes special characters according to TeamCity's specification:

  • |||
  • '|'
  • \n|n
  • \r|r
  • [|[
  • ]|]

Available Test Scripts

Script Description
bun test Run tests normally (local development)
bun test --watch Run tests in watch mode
bun run test:teamcity Run tests with TeamCity reporting
bun run ci-test Alias for test:teamcity (used in CI)

TeamCity Build Configuration

Add this build step to your TeamCity build configuration:

#!/bin/bash
set -e

# Install dependencies
bun install

# Run tests with TeamCity reporting
bun run ci-test

Files

  • tests/TeamcityReporter.ts - TeamCity service message formatter
  • scripts/test-tap-teamcity.ts - TAP to TeamCity converter
  • scripts/test-teamcity.ts - Alternative direct output parser (not currently used)
  • tests/setup.ts - Test setup utilities

Testing the Integration

To test TeamCity reporting locally:

# Simulate TeamCity environment
export TEAMCITY_VERSION="2024.1"
bun run test:teamcity

# Unset when done
unset TEAMCITY_VERSION

You should see output like:

##teamcity[testSuiteStarted name='HashMap']
##teamcity[testStarted name='HashMap > constructor > should create an empty map with default capacity']
##teamcity[testFinished name='HashMap > constructor > should create an empty map with default capacity']
...
##teamcity[testSuiteFinished name='HashMap']