Implement a Tester

Standard test runners are integrated into Bit using a Bit Aspect. For example, Jest is integrated into Bit using the Jest Aspect. These Aspects implement the Tester interface. A tester implementation should be able to provide testing in the workspace as well as testing during build.

The easiest way to start implementing a tester is to create a new Bit Aspect using the Aspect template.

bit create aspect extensions/my-tester
CopiedCopy

As a convention, the tester interface is implemented in a file named with the tester prefix. Since it is a specific implementation file, it is not part of the generic Aspect component template and therefore needs to be created manually:

cd extensions/my-tester
touch my-tester.tester.ts
CopiedCopy

Tester implementation file

note

When implementing testing in the workspace, make sure the tester implementation transpiles source files during testing. The tester receives the compiled code (compiled by the Env's Compiler) only during build. For example, the Jest Aspect uses the transform option to do so.

test

test(context: TesterContext): Promise<Tests>;
CopiedCopy

The test method is used by Tester for testing in the workspace as well as during build. Use the received context object to handle both cases.

watch (optional)

watch?(context: TesterContext): Promise<Tests>
CopiedCopy

Watch tests on all components

onTestRunComplete (optional)

onTestRunComplete?(callback: CallbackFn): Promise<void>
CopiedCopy

on test run complete. (applies only during watch)

version

version(): string;
CopiedCopy

Returns the tester version.

displayConfig (optional)

displayConfig?(): string
CopiedCopy

The displayConfig function helps the user see the tester config when using the bit env <comp-id> command. It should return a string representation of the tester config. (for example JSON.stringify of the tsconfig file)

configPath (optional)

configPath?: string;
CopiedCopy

A path to the config of the specific tester in the filesystem. for example path to the jest config file.

Main runtime file

createTester(jestConfig: any, jestModulePath?: string): JestTester
CopiedCopy

Creates returns an instance of the implemented Tester.

For example:

createTester(jestConfig: any, jestModulePath = require.resolve('jest')) {
  return new JestTester(JestAspect.id, jestConfig, jestModulePath, this.jestWorker, this.logger);
}
CopiedCopy