Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while trying to read the map file #211

Open
ibrocodes7 opened this issue Mar 13, 2023 · 5 comments
Open

Error while trying to read the map file #211

ibrocodes7 opened this issue Mar 13, 2023 · 5 comments

Comments

@ibrocodes7
Copy link

ibrocodes7 commented Mar 13, 2023

Hi, I am trying to use the package with playwright version 1.24. I am seeing some console errors while trying to collect the coverage.

I followed the instructions as per https://playwright.dev/docs/api/class-coverage.

import { Page, test as base } from '@playwright/test';
const v8toIstanbul = require('v8-to-istanbul');

import {
  LoginPage,
} from '../src/pages';

let blinkPage: Page = null;

export const test = base.extend<{
  loginPage: LoginPage;
}>({
  page: async ({ browser }, use) => {
    if (blinkPage === null) {
      blinkPage = await browser.newPage();
    }
    await use(blinkPage);
  },

  loginPage: async ({ page }, use) => {
    await use(new LoginPage(page));
  },
});

test.beforeEach(async ({ page }) => {
  await page.coverage.startJSCoverage();
});

test.afterEach(async ({ page }) => {
  const coverage = await page.coverage.stopJSCoverage();
  console.log(coverage);

  for (const entry of coverage) {
    const converter = v8toIstanbul('', 0, { source: entry.source });
    await converter.load();
    converter.applyCoverage(entry.functions);
    console.log(JSON.stringify(converter.toIstanbul()));
  }
});

Error:

{"":{"path":"","all":false,"statementMap":{"0":{"start":{"line":1,"column":0},"end":{"line":1,"column":0}},"1":{"start":{"line":2,"column":0},"end":{"line":2,"column":46}},"2":{"start":{"line":3,"column":0},"end":{"line":3,"column":23}},"3":{"start":{"line":4,"column":0},"end":{"line":4,"column":61}},"4":{"start":{"line":5,"column":0},"end":{"line":5,"column":21}},"5":{"start":{"line":6,"column":0},"end":{"line":6,"column":22}},"6":{"start":{"line":7,"column":0},"end":{"line":7,"column":10}},"7":{"start":{"line":8,"column":0},"end":{"line":8,"column":68}},"8":{"start":{"line":9,"column":0},"end":{"line":9,"column":60}},"9":{"start":{"line":10,"column":0},"end":{"line":10,"column":58}},"10":{"start":{"line":11,"column":0},"end":{"line":11,"column":40}},"11":{"start":{"line":12,"column":0},"end":{"line":12,"column":50}},"12":{"start":{"line":13,"column":0},"end":{"line":13,"column":25}},"13":{"start":{"line":14,"column":0},"end":{"line":14,"column":58}},"14":{"start":{"line":15,"column":0},"end":{"line":15,"column":10}},"15":{"start":{"line":16,"column":0},"end":{"line":16,"column":0}},"16":{"start":{"line":17,"column":0},"end":{"line":17,"column":46}},"17":{"start":{"line":18,"column":0},"end":{"line":18,"column":51}},"18":{"start":{"line":19,"column":0},"end":{"line":19,"column":60}},"19":{"start":{"line":20,"column":0},"end":{"line":20,"column":51}},"20":{"start":{"line":21,"column":0},"end":{"line":21,"column":15}},"21":{"start":{"line":22,"column":0},"end":{"line":22,"column":24}},"22":{"start":{"line":23,"column":0},"end":{"line":23,"column":9}},"23":{"start":{"line":24,"column":0},"end":{"line":24,"column":42}},"24":{"start":{"line":25,"column":0},"end":{"line":25,"column":61}},"25":{"start":{"line":26,"column":0},"end":{"line":26,"column":43}},"26":{"start":{"line":27,"column":0},"end":{"line":27,"column":50}},"27":{"start":{"line":28,"column":0},"end":{"line":28,"column":15}},"28":{"start":{"line":29,"column":0},"end":{"line":29,"column":75}},"29":{"start":{"line":30,"column":0},"end":{"line":30,"column":9}},"30":{"start":{"line":31,"column":0},"end":{"line":31,"column":0}},"31":{"start":{"line":32,"column":0},"end":{"line":32,"column":8}},"32":{"start":{"line":33,"column":0},"end":{"line":33,"column":0}},"33":{"start":{"line":34,"column":0},"end":{"line":34,"column":61}},"34":{"start":{"line":35,"column":0},"end":{"line":35,"column":72}},"35":{"start":{"line":36,"column":0},"end":{"line":36,"column":59}},"36":{"start":{"line":37,"column":0},"end":{"line":37,"column":64}},"37":{"start":{"line":38,"column":0},"end":{"line":38,"column":51}},"38":{"start":{"line":39,"column":0},"end":{"line":39,"column":44}},"39":{"start":{"line":40,"column":0},"end":{"line":40,"column":48}},"40":{"start":{"line":41,"column":0},"end":{"line":41,"column":48}},"41":{"start":{"line":42,"column":0},"end":{"line":42,"column":17}},"42":{"start":{"line":43,"column":0},"end":{"line":43,"column":50}},"43":{"start":{"line":44,"column":0},"end":{"line":44,"column":81}},"44":{"start":{"line":45,"column":0},"end":{"line":45,"column":112}},"45":{"start":{"line":46,"column":0},"end":{"line":46,"column":87}},"46":{"start":{"line":47,"column":0},"end":{"line":47,"column":84}},"47":{"start":{"line":48,"column":0},"end":{"line":48,"column":52}},"48":{"start":{"line":49,"column":0},"end":{"line":49,"column":40}},"49":{"start":{"line":50,"column":0},"end":{"line":50,"column":40}},"50":{"start":{"line":51,"column":0},"end":{"line":51,"column":17}},"51":{"start":{"line":52,"column":0},"end":{"line":52,"column":9}},"52":{"start":{"line":53,"column":0},"end":{"line":53,"column":31}},"53":{"start":{"line":54,"column":0},"end":{"line":54,"column":52}},"54":{"start":{"line":55,"column":0},"end":{"line":55,"column":40}},"55":{"start":{"line":56,"column":0},"end":{"line":56,"column":60}},"56":{"start":{"line":57,"column":0},"end":{"line":57,"column":17}},"57":{"start":{"line":58,"column":0},"end":{"line":58,"column":9}}},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":1,"11":1,"12":1,"13":1,"14":1,"15":1,"16":1,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":1,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":1,"31":1,"32":1,"33":1,"34":1,"35":1,"36":1,"37":1,"38":1,"39":1,"40":1,"41":1,"42":1,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":1,"53":0,"54":0,"55":0,"56":0,"57":0},"branchMap":{"0":{"type":"branch","line":2,"loc":{"start":{"line":2,"column":-1},"end":{"line":58,"column":9}},"locations":[{"start":{"line":2,"column":-1},"end":{"line":58,"column":9}}]},"1":{"type":"branch","line":43,"loc":{"start":{"line":43,"column":31},"end":{"line":43,"column":47}},"locations":[{"start":{"line":43,"column":31},"end":{"line":43,"column":47}}]},"2":{"type":"branch","line":43,"loc":{"start":{"line":43,"column":49},"end":{"line":52,"column":9}},"locations":[{"start":{"line":43,"column":49},"end":{"line":52,"column":9}}]},"3":{"type":"branch","line":53,"loc":{"start":{"line":53,"column":30},"end":{"line":58,"column":9}},"locations":[{"start":{"line":53,"column":30},"end":{"line":58,"column":9}}]}},"b":{"0":[1],"1":[0],"2":[0],"3":[0]},"fnMap":{"0":{"name":"createNode","decl":{"start":{"line":17,"column":8},"end":{"line":23,"column":9}},"loc":{"start":{"line":17,"column":8},"end":{"line":23,"column":9}},"line":17},"1":{"name":"appendNodesToDom","decl":{"start":{"line":24,"column":8},"end":{"line":30,"column":9}},"loc":{"start":{"line":24,"column":8},"end":{"line":30,"column":9}},"line":24}},"f":{"0":0,"1":0}}}
Passed: 0	Failed: 1	Pending: 0


  1) login/login.test.ts:18:3 › Login scenarios ›  should load login page ==================

    Error: An error occurred while trying to read the map file at /Users/<path>/ag-grid-chunk-bfc390cf.js.map
    Error: ENOENT: no such file or directory, open '/Users/<path>/ag-grid-chunk-bfc390cf.js.map'

        at readFromFileMap (/Users/<path>/node_modules/convert-source-map/index.js:60:11)
        at new Converter (/Users/<path>/node_modules/convert-source-map/index.js:67:32)
        at Object.exports.fromMapFileComment (/Users/<path>/node_modules/convert-source-map/index.js:153:10)
        at Object.exports.fromMapFileSource (/Users/<path>/node_modules/convert-source-map/index.js:165:22)
        at V8ToIstanbul.load (/Users/<path>/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:52:66)
        at /Users/<path>/fixtures/blink.ts:334:21

```bash
@Smrtnyk
Copy link

Smrtnyk commented May 9, 2023

Same issue here

@Mau-MD
Copy link

Mau-MD commented Aug 2, 2023

Same issue here. Were you able to fix it?

@rwalle
Copy link

rwalle commented Nov 12, 2023

It is simply because the source map file does not exist -- here in the v8-to-istanbul.js

this.rawSourceMap = this.sources.sourceMap ||
// if we find a source-map (either inline, or a .map file) we load
// both the transpiled and original source, both of which are used during
// the backflips we perform to remap absolute to relative positions.
convertSourceMap.fromSource(rawSource) || convertSourceMap.fromMapFileSource(rawSource, this._readFileFromDir.bind(this))

If there is any hint that the file uses source map, it tries to read the source map file. However in many cases it does not exist (e.g. third-party library did not ship source map along with bundled code when packaging), as what happened to you here. To me this is a mistake -- the "missing source map" problem is often out of user's control, and user should not be prevented from collecting coverage because of it. Most of the time the source map is for a third-party library which the user does not care about anyway.

If you want a workaround, you can just simply wrap the code in try-catch in your local node_modules:

try {
    this.rawSourceMap = this.sources.sourceMap || rcmap = convertSourceMap.fromSource(rawSource) || convertSourceMap.fromMapFileSource(rawSource, this._readFileFromDir.bind(this));
} catch {
    this.rawSourceMap = null;
}

But apparently this won't work in CI.

I think should be patched.

@bcoe Could you consider this? I'll be happy to create a pull request for this.

@bcoe
Copy link
Member

bcoe commented Nov 21, 2023

@rwalle I would consider a patch for this. I think we should warn on the console as well as setting this.rawSourceMap = null, if we have metadata indicating a source map, but no source map.

@rwalle
Copy link

rwalle commented May 20, 2024

@rwalle I would consider a patch for this. I think we should warn on the console as well as setting this.rawSourceMap = null, if we have metadata indicating a source map, but no source map.

finally got back to this. The change is simple enough, but should I add a test? (I guess so.) If the code does console.warn, the only thing to test this would be to override console.warn in the test -- not sure you want to do that. Other methods like injecting a logger would mean adding more code elsewhere. How would you like to proceed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants