Jest TeamCity Reporter
jest-teamcity is a specialized Jest reporter designed to integrate test results with TeamCity CI/CD servers. Currently at version 1.12.0, this package provides detailed reporting, including test durations, pending test statuses, and full stack traces for failed tests, all formatted using TeamCity's service messages. It automatically groups tests into logical suites, enhancing readability and analysis within TeamCity's interface. Releases are generally infrequent, focusing on maintenance, dependency updates, and addressing specific edge cases or improvements in how Jest's internal APIs or TeamCity's expectations are handled. A key differentiator is its automatic activation based on the `TEAMCITY_VERSION` environment variable, ensuring it only outputs TeamCity-specific messages when running within that environment, while defaulting to standard Jest output otherwise. This prevents noisy output during local development.
Common errors
-
Cannot find module 'jest-teamcity' from 'jest-config/build/isValidReporter.js'
cause The `jest-teamcity` package is not installed or is incorrectly referenced in the Jest configuration.fixRun `npm install --save-dev jest-teamcity` or `yarn add --dev jest-teamcity`. Verify that 'jest-teamcity' is spelled correctly in your Jest `reporters` array. -
Jest tests ran successfully, but no TeamCity service messages appeared in the CI log.
cause The `TEAMCITY_VERSION` environment variable was not set, which disables the `jest-teamcity` reporter's output.fixEnsure `TEAMCITY_VERSION` is set in your CI environment or locally (e.g., `export TEAMCITY_VERSION="some_version"` on Linux/macOS or `set TEAMCITY_VERSION=some_version` on Windows) before running tests. -
TeamCity reports incomplete or malformed test suite data after test failures.
cause Older versions of `jest-teamcity` (prior to v1.10.0) might not have properly handled test suite hook failures or suites that failed to run.fixUpgrade to `jest-teamcity` version 1.10.0 or newer to ensure proper handling of all test suite states.
Warnings
- gotcha The `jest-teamcity` reporter will only produce TeamCity-specific output if the `TEAMCITY_VERSION` environment variable is set. If this variable is missing, it silently defaults to standard Jest output.
- breaking Version 1.7.0 refactored the package to use Jest's official reporters API. While the configuration string 'jest-teamcity' remained the same, this change might have required Jest version updates or addressed issues for users on significantly older Jest configurations.
- gotcha Prior to versions 1.9.0 and 1.10.0, the reporter had known issues handling Jest test suites that failed to run entirely or failures within test suite hooks. This could lead to incomplete or malformed reports in TeamCity.
- gotcha It is common practice to include `"default"` alongside `"jest-teamcity"` in the `reporters` array (e.g., `["default", "jest-teamcity"]`). Omitting `"default"` might suppress standard console output from Jest when `TEAMCITY_VERSION` is not set, potentially making local debugging more difficult.
Install
-
npm install jest-teamcity -
yarn add jest-teamcity -
pnpm add jest-teamcity
Imports
- jest-teamcity
const reporter = require('jest-teamcity'); // This package is not for direct JS import// jest.config.js module.exports = { reporters: ["default", "jest-teamcity"] };
Quickstart
npm install --save-dev jest-teamcity
// jest.config.js
module.exports = {
"reporters": ["default", "jest-teamcity"]
};
// package.json
// ...
// "scripts": {
// "test": "jest"
// }
// ...
// To run locally with TeamCity output enabled:
// In your terminal before running tests:
export TEAMCITY_VERSION="some_version"
# Then run your tests
npm test