Skip to content

Latest commit

 

History

History
78 lines (55 loc) · 1.53 KB

File metadata and controls

78 lines (55 loc) · 1.53 KB

v8-coverage-collector

JSR

Wrapper around v8's Profiler APIs used to gather coverage data for CircleCI's Smarter Testing Javascript plugins.

The coverage collector can be used to collect precise coverage during the test run lifecycles.

Usage

Add the package as a dependency

pnpm i jsr:@circleci/v8-coverage-collector

Use the provided APIs to collect and reset coverage during the test lifecycle events.

import {V8CoverageCollector} from '@circleci/v8-coverage-collector';

export default class TestHookExample {
  private inspector: V8CoverageCollector;

  constructor() {
    this.inspector = new V8CoverageCollector();
  }

  async onBeforeAll(): Promise<void> {
    await this.inspector.connect()
  }

  async onBeforeTest(): Promise<void> {
    await this.inspector.resetCoverage();
  }

  async onAfterTest(test: ExampleTest): Promise<void> {
    await this.inspector
      .collectCoverage(process.cwd(), test.file, test.name)
      .then((result) => {
        test.meta.testKey = result.testKey;
        test.meta.coveredFiles = result.coveredFiles;
      });
  }

  async onAfterAll(): Promise<void> {
    await this.inspector.disconnect()
  }
}

Development

Install and use current node version.

NODE_VER=$(cat ./.nvmrc)
nvm install $NODE_VER
nvm use $NODE_VER

Install dependencies with pnpm.

pnpm install

Build the plugin.

pnpm build

Run tests.

pnpm test