Skip to content

[Bug]: CoverageReporter throws TypeError on empty branch locations in lcov generation #44113

Closed

Description

Version

1.51.0 (main)

Steps to reproduce

  1. Enable trace with _coverage: true and configure the coverage reporter in playwright.config.ts.
  2. Instrument code that contains an if statement without an else branch (or any branch structure where Istanbul leaves implicit branch locations empty {}).
  3. Run test with @playwright/test.

Expected behavior

CoverageReporter should safely read the line number and generate lcov.info without crashing.

Actual behavior

CoverageReporter crashes with:

TypeError: Cannot read properties of undefined (reading 'line')

When an implicit branch has an empty location object {} in Istanbul's branch.locations, accessing location.start.line throws because location.start is undefined.

Additional context

I have reproduced the issue and have a local fix ready with regression tests. Please assign this to me so I can open the pull request.

Environment

System:
OS: macOS 26.5.2
CPU: (8) arm64 Apple M3
Binaries:
Node: 26.10.0 - /Users/aritrosaha/.nvm/versions/node/v26.10.0/bin/node
npm: 11.19.1 - /Users/aritrosaha/.nvm/versions/node/v26.10.0/bin/npm

Activity

  1. halcyon-past commented on Nov 14, 2026

    @halcyon-past
    ContributorAuthor

    I have submitted a pull request with the fix and regression coverage in #44114.

  2. microsoft-playwright-automation commented on Nov 16, 2026

    @microsoft-playwright-automation
  3. microsoft-playwright-automation commented on Nov 16, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot and I reproduced this on macOS.

    Reproduced on current main (826ce42b8664ea940424e77ce51f1cdf96dcd37f, 1.66.0-next) in Chromium, Firefox, and WebKit. The reporter reads location.start.line before it can use the enclosing branch's line number, so an empty location throws.

    #44114 fixes the crash at beb4d939a4d57cb2416863383d3876fc4f130011. My independent reproduction passes with that fix on all three browsers. Its regression test also fails without the source change and passes with it. No separate fix is needed.

    Reproduction and checks

    I extended should aggregate coverage with the coverage reporter in tests/playwright-test/coverage.spec.ts, removing start and end from an existing branch location before serializing the coverage data. The test checks that lcov.info contains BRDA:2,0,1,0.

    Minimal equivalent configuration:

    export default {
      reporter: 'coverage',
      use: { trace: { mode: 'on', _coverage: true } },
    };

    Test:

    import { test } from '@playwright/test';
    
    test('empty branch location', async ({ page }) => {
      const loc = {
        start: { line: 2, column: 0 },
        end: { line: 2, column: 20 },
      };
      const coverage = {
        'app.js': {
          path: 'app.js',
          statementMap: { '0': loc },
          fnMap: {},
          branchMap: {
            '0': { type: 'if', line: 2, loc, locations: [loc, {}] },
          },
          s: { '0': 1 },
          f: {},
          b: { '0': [1, 0] },
        },
      };
      await page.setContent(
        '<script>window.__coverage__ = ' + JSON.stringify(coverage) + '</script>'
      );
    });
    Check Result
    Independent reproduction on main, Chromium 159.0.8154.6, Firefox 159.0, WebKit 27.2 (r2394), headless Same TypeError in all three
    Independent reproduction on #44114, same Chromium and Firefox, WebKit 27.2 (r2393), headless Passes in all three
    PR's regression test applied to main without its source fix Fails with the reported TypeError
    PR's complete coverage-reporter test file 3 pass per browser
    Related coverage-collection tests, tests/library/coverage.spec.ts 39 pass across all three browsers
    Neighboring reporter lifecycle and attachment tests 19 pass; browser-independent
    npm run build, then npm run flint on the PR Pass
    Merge with current main No conflicts

    I used Node.js 24.22.2. I did not test the reported 1.51.0 or headed mode because the exact crash reproduces on current main. Initial setup attempts failed because dependencies and browser binaries were absent; those passed after installing the pinned dependencies and browsers.

    The PR's only reported GitHub check is the successful CLA check; no test CI jobs have run. GitHub reports its merge state as blocked, so this local verification does not bypass the repository's merge requirements.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions