JSPM

  • Created
  • Published
  • Downloads 46566
  • Score
    100M100P100Q170872F
  • License MIT

Temporal.io SDK code coverage integration

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@temporalio/nyc-test-coverage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @temporalio/nyc-test-coverage

    NPM

    Temporal's TypeScript SDK interceptors and sinks for code coverage with nyc.

    Getting Started

    1. npm install mocha nyc
    2. Use nyc to manually instrument your Workflow code, for example nyc instrument lib lib --in-place. Make sure you instrument your Workflow code after compiling it with tsc.
    3. Add this package's sinks and interceptors to your test worker, for example:
    import { WorkflowCoverage } from '@temporalio/nyc-test-coverage';
    
    const workflowCoverage = new WorkflowCoverage();
    
    worker = await Worker.create({
      connection: nativeConnection,
      taskQueue,
      workflowsPath: require.resolve("./workflows"),
      interceptors: {
        workflowModules: [workflowCoverage.interceptorModule]
      },
      sinks: workflowCoverage.sinks,
    });
    1. After your tests are done, call mergeIntoGlobalCoverage() to merge your Workflows' code coverage into nyc's global coverage.
    after(() => {
      workflowCoverage.mergeIntoGlobalCoverage();
    });

    For example, the following is a sample npm script that handles instrumenting and running tests. The following assumes that npm run build produces compiled JavaScript in the lib directory.

    {
      "test.coverage": "npm run build && nyc instrument lib lib --in-place && nyc --reporter=lcov --reporter=text-summary mocha lib/*.test.js"
    }