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

[QUESTION] How can we use Istanbul code coverage in Playwright? #20459

Closed
gauravgandhi1315 opened this issue Jan 27, 2023 · 4 comments
Closed

Comments

@gauravgandhi1315
Copy link

I was using Istanbul with WebdriverIO to generate the automation tests code coverage, check below. How can we implement same in playwright? I am not if we can declare global in playwright.

  global: (afterEachReportAutomation = async browser => {
    const coverage = await browser.execute(() => {
      if (typeof window.__coverage__ === undefined) {
        console.log("instrumentation not done...");
        window.__coverage__ = {};
      } else {
        return window.__coverage__;
      }
    });
    coverageObjects.push(coverage);
  }),

  //Combines coverage information and merge all the information from the coverageObjects and instruct istanbul to generate readable html reports.
  after: () => {
    coverageObjects.forEach(coverage => {
      coverageMap.merge(coverage);
    });

    const context = libReport.createContext({
      dir: "report",
      defaultSummarizer: "nested",
      coverageMap
    });
    const tree = libReport.summarizers.pkg(coverageMap);
    tree.visit(reports.create("html"), context);
  },

  afterHook: function() {
    global.afterEachReportAutomation(browser);
  }
@pavelfeldman
Copy link
Member

pavelfeldman commented Jan 27, 2023

Not sure I'm answering your question, but:

those are API calls that you will call from beforeEach/afterEach. Not sure what global is!

@gauravgandhi1315
Copy link
Author

@pavelfeldman Can I use global-setup and teardown?

@pavelfeldman
Copy link
Member

You can definitely use global-setup and teardown, but I am not sure how this is related to the code coverage.

@pavelfeldman
Copy link
Member

pavelfeldman commented Jan 28, 2023

Let me fold this into #7030

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

2 participants