Environment
Environment is a feature that allows you to capture and display specific details related to the test execution environment, such as the operating system, browser version, device information, or any other global information that is relevant to the entire test run.
Such information can be especially insightful when you're troubleshooting test failures in a heterogeneous environment, e.g. when tests fail on CI but pass locally, or when you're trying to pinpoint the cause of a test failure on a specific platform or a version of some software.
It is always a good idea to include environment information in your test reports, as soon as you start running tests anywhere further than your local machine. When you will be setting it up, try to configure saving Executor information as well.
Configuration​
By default, the environment information is not included in the report. To enable it, you need to add the following configuration to your jest.config.js
file.
In the example below, we're using the lodash library to filter out any sensitive information from the environment variables, and we also include the name and version of the package under test, as well as the type of the operating system:
- Config
- Preview
const _ = require('lodash');
const os = require('os');
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
// ...
reporters: [
// ...
['jest-allure2-reporter', {
environment: async ({ manifest }) => ({
'package.name': await manifest((p) => p.name),
'package.version': await manifest((p) => p.version),
'os.type': os.type(),
..._
.chain(process.env)
.omitBy((value, key) => /secret|password|token/i.test(key))
.mapKeys((value, key) => 'env.' + key)
.value(),
}),
}],
],
};