Run the following on a component that uses your env, to get the Jest version currently being used:
$bit envs get pages/welcome --services teambit.defender/formatter 
The out is similar to the following:
teambit.defender/formatter
configured tester: prettier-formatter (Prettier @ 2.7.1)
configured tester: prettier-formatter (Prettier @ 2.7.1)
To provide your Jest tester with a different version of Jest, implement the tester env handler and replace your Jest build task:
/* @filename: my-env.bit-env.ts */ /* your base env */ import { ReactEnv } from '@teambit/react.react-env'; import type { ReactEnvInterface } from '@teambit/react.react-env'; import type { EnvHandler } from '@teambit/envs'; import { JestTask, JestTester } from '@teambit/defender.jest-tester'; import { Tester } from '@teambit/tester'; export class MyEnv extends ReactEnv implements ReactEnvInterface { constructor() { super(); } name = 'my-env'; /** * replace the env's default tester with this instance of jest-tester */ tester(): EnvHandler<Tester> { return JestTester.from({ /* the path to the jest instance used by this env */ jest: require.resolve('jest'), }); } build() { return super.build().from([ /** * replace the env's default jest task with this task * (add a jest task if one is not already registered to this pipeline) * **/ JestTask.from({ /* the path to the jest instance used by this env */ jest: require.resolve('jest'), }), ]); } } export default new MyEnv();
Jest-tester requires a path to the jest instance, not an instance of jest. Because of that, Jest is not imported by the env, which leads to Bit failing to detect Jest as a dependency of that env.
To address that, manually add Jest as a dependency of that env:
$bit deps set my-env jest@29.0.0 
See command synopsis
Install the new version in your workspace:
$bit install 
See command synopsis
Run the following to compile your env:
$bit compile 
See command synopsis