Instrumenting Jest tests with Helios
Use the installation instructions below if you're using Jest as your testing framework and would like to add your existing tests to Helios for complete E2E troubleshooting.
Navigate to your project's root directory, and install the latest Helios OpenTelemetry SDK:
npm install --save helios-opentelemetry-sdk
In your test file, paste the following code snippet before all other imports:
const { instrumentTests } = require('helios-opentelemetry-sdk');
instrumentTests({
apiToken: <API_TOKEN>,
environment: <ENVIRONMENT>, // Defaults to process.env.NODE_ENV if omitted.
});
import { instrumentTests } from 'helios-opentelemetry-sdk';
instrumentTests({
apiToken: <API_TOKEN>,
environment: <ENVIRONMENT>, // Defaults to process.env.NODE_ENV if omitted.
});
jest-circus
Make sure to complete the step below to complete the installation if you're using the
jest-circus
runner (which is the default runner in Jest 27 and above). Specifically,testEnvironment
needs to be referenced.
Add a reference to Helios testEnvironment
by adding the following annotation to the top of your test file:
/**
* @jest-environment @heliosphere/opentelemetry-instrumentation-jest
*/
Another option is to point to the module using:
--env
CLI option
All set
Now when you run your tests - the results will show up in the Helios application and the URL of the exact test trace will be handily printed after each test run.
Jest
Updated 7 months ago