Setup a Tester

You can use the tester of your choice, alongside its configuration in your dev environment:

Looking for another tester? Learn how to create your own component tester.

Using a tester

For example, the following configuration defines the Jest tester as the tester to use during development and during build. Note that a single env can use different testers or tester configuration for development and build.

Install the tester in your workspace:

$bit
Copiedcopy

Set the tester in the relevant env:

/* @filename: my-env.bit-env.ts */

import { NodeEnv } from '@teambit/node.node';
import { EnvHandler } from '@teambit/envs';
import { Tester } from '@teambit/tester';
import { Pipeline } from '@teambit/builder';
/* import the tester and tester task */
import { JestTester, JestTask } from '@teambit/defender.jest-tester';

export class MyEnv extends NodeEnv {
  name = 'my-env';

  /**
   * the path to the jest config file.
   */
  protected jestConfigPath = require.resolve('./config/jest.config');

 tester(): EnvHandler<Tester> {
  /**
   * use jest for testing during development
   * executed on 'bit test'
   */
    return JestTester.from({
      jest: require.resolve('jest'),
      config: this.jestConfigPath,
    });
  }

 build() {
    return Pipeline.from([
      /**
       * use jest for testing during development
       * executed on 'bit build', 'bit snap', 'bit tag'
       */
      JestTask.from({
        config: this.jestConfigPath,
      }),
    ]);
  }

export default new MyEnv();
CopiedCopy
on this page
Using a tester