Skip to content

No Coverage reported for WebWorkers #102

Closed

Description

@agilgur5

So I have a bit of a unique set-up in that my library is an integration for both webpack and browserify. I use istanbul-instrument-loader and babel-plugin-istanbul to instrument each, respectively. It seems like my worker is being instrumented and my test code instantiates the worker, but I get coverage for everything except the worker. The webworkify function I export also has no reported coverage.

You can view the code at agilgur5/physijs-webpack#cypress-coverage. It's pretty tiny, basically just webpack.js, browserify.js, and browserify-worker-stub.js, which are all ~5-10 LoC, and their two 5 LoC tests (everything in the physijs/ directory is for the most part just vendored and can mostly be ignored).
Can install, test, and see coverage with:

npm install && npm test && npx nyc report

Notably, physi_worker.js isn't present in the coverage report, and browserify-worker-stub.js shows no coverage for the function it exports (which is called by webworkify), despite tests running the worker.
As this is an integration library, it'd be ideal to know that physijs (the library it integrates) itself isn't broken due to the integration, so high code coverage of it would give some confidence that nothing has broken.

I'm not totally sure if this is happening because of an istanbul issue or a cypress issue. When I ran the worker as a fake worker (i.e. on the same thread) in jsdom with jsdom-worker, I did get coverage for it. So I wonder if the reason it's not showing up in cypress's coverage reports is because it's running in a real worker. (Can read agilgur5/physijs-webpack#6 for more details on how I tried to get coverage to work with all sorts of different toolks, but it shouldn't be necessary to understand this issue)

Activity

  1. jennifer-shehane commented on Nov 2, 2026

    @jennifer-shehane
    Member

    The plugin reads __coverage__ only from the app and spec windows. A Web Worker keeps its counters on its own global (self.__coverage__), so worker code doesn't appear in the report.

    #1012 documents a workaround in Coverage from web workers: the worker returns self.__coverage__ over a MessageChannel on request, and an afterEach hook in the support file sends each worker's coverage to the combineCoverage task.

    Limitations:

    • Collect coverage before the worker terminates or the page unloads.
    • Each worker reports once, at the end of the test that started it.
    • Shared workers and service workers are not covered.

    A built-in API for this is not planned as part of this change.

  2. github-actions commented on Nov 2, 2026

    @github-actions

    🎉 This issue has been resolved in version 4.1.3 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions