Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@temporalio/nyc-test-coverage

Package Overview
Dependencies
Maintainers
0
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@temporalio/nyc-test-coverage

Temporal.io SDK code coverage integration

  • 1.11.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
decreased by-7.52%
Maintainers
0
Weekly downloads
 
Created
Source

@temporalio/nyc-test-coverage

NPM

Temporal's TypeScript SDK integration for Workflow code coverage with nyc and similar tools.

Getting Started

  1. npm install -D mocha nyc @temporalio/nyc-test-coverage
  2. Instantiate WorkflowCoverage from this package, and call augmentWorkerOptions() to configure Workflows to gather and export code coverage data:
import { WorkflowCoverage } from '@temporalio/nyc-test-coverage';

const workflowCoverage = new WorkflowCoverage();

worker = await Worker.create(workflowCoverage.augmentWorkerOptions({
  connection: nativeConnection,
  taskQueue,
  workflowsPath: require.resolve("./workflows"),
}));
  1. After your tests are done, call mergeIntoGlobalCoverage() to merge your Workflows' code coverage into nyc's global coverage.
after(() => {
  workflowCoverage.mergeIntoGlobalCoverage();
});

Usage with bundleWorkflowCode()

If you are pre-bundling your Workflows using bundleWorkflowCode(), we recommend using the augmentBundleOptions() method to configure your bundle options, followed by augmentWorkerOptionsWithBundle() to configure your Worker options as follows.

const bundle = await bundleWorkflowCode(
  workflowCoverage.augmentBundleOptions({
    workflowsPath: require.resolve('./workflows'),
  })
);

const worker = await Worker.create(
  workflowCoverage.augmentWorkerOptionsWithBundle({
    connection,
    taskQueue,
    workflowBundle: bundle,
    activities,
  })
);

With bundleWorkflowCode(), you still need to call mergeIntoGlobalCoverage() when your tests are done to merge Workflow test coverage into nyc's global test coverage.

after(() => {
  workflowCoverage.mergeIntoGlobalCoverage();
});

Usage with Jest

This package also works with Jest code coverage. However, this package only works with the default coverageProvider option 'babel'. This package does not work with coverageProvider: 'v8'. Complete the following steps to use this package with Jest.

  1. npm install jest @temporalio/nyc-test-coverage
  2. Check your Jest config and make sure the coverageProvider option is not set to 'v8'. Set coverageProvider to 'babel'.
  3. Instantiate WorkflowCoverage from this package, and call augmentWorkerOptions() to configure Workflows to gather and export code coverage data:
import { WorkflowCoverage } from '@temporalio/nyc-test-coverage';

const workflowCoverage = new WorkflowCoverage();

worker = await Worker.create(workflowCoverage.augmentWorkerOptions({
  connection: nativeConnection,
  taskQueue,
  workflowsPath: require.resolve("./workflows"),
}));
  1. After your tests are done, call mergeIntoGlobalCoverage() to merge your Workflows' code coverage into Jest's global coverage.
afterAll(() => {
  workflowCoverage.mergeIntoGlobalCoverage();
});

Keywords

FAQs

Package last updated on 20 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc