Skip to content

given coverage information output by puppeteer's API output a format consumable by Istanbul reports

License

Notifications You must be signed in to change notification settings

obihill/puppeteer-to-istanbul

 
 

Repository files navigation

Puppeteer to Istanbul Extra

Convert coverage from the format outputted by puppeteer to a format consumable by [Istanbul][istanbul].

Introduction

Puppeteer-to-istanbul-extra is a fork of puppeteer-to-istanbul. It is basically the same as, but provides additional functionality.

Usage

To Output Coverage in Istanbul Format with Puppeteer

  1. install puppeteer, npm i -D puppeteer.

  2. install puppeteer-to-istanbul-extra, npm i -D puppeteer-to-istanbul-extra.

  3. run your code in puppeteer with coverage enabled:

    (async () => {
      const pti = require('puppeteer-to-istanbul-extra')
      const puppeteer = require('puppeteer')
      const browser = await puppeteer.launch()
      const page = await browser.newPage()
    
      // Enable both JavaScript and CSS coverage
      await Promise.all([
        page.coverage.startJSCoverage(),
        page.coverage.startCSSCoverage()
      ]);
      // Navigate to page
      await page.goto('https://www.google.com');
      // Disable both JavaScript and CSS coverage
      const [jsCoverage, cssCoverage] = await Promise.all([
        page.coverage.stopJSCoverage(),
        page.coverage.stopCSSCoverage(),
      ]);
      const options_obj = {output_dir: './.nyc_output'}
      pti.write([...jsCoverage, ...cssCoverage], options_obj)
      await browser.close()
    })()

Options

Puppeteer-to-istanbul-extra provides options for use with the write method.

Here are the available options:

Option name Description Type Default
output_dir Directory to output coverage information. Note that it should be relative to the current working directory String ./.nyc_output
backup Define backup characteristics for coverage files. If true, will backup existing files. Boolean false

To Check Istanbul Reports

  1. install nyc, npm i nyc -g.

  2. use nyc's report functionality:

    nyc report --reporter=html

puppeteer-to-istanbul-extra outputs temporary files in a format that can be consumed by nyc.

see istanbul for a list of possible reporters.

Extras

Please see Puppeteer-to-Istanbul for additional information.

About

given coverage information output by puppeteer's API output a format consumable by Istanbul reports

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%