Skip to content

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

License

Notifications You must be signed in to change notification settings

circleci/v8-coverage-collector

Repository files navigation

v8-coverage-collector

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •