Package detail

puppeteer-to-istanbul

istanbuljs41.6kISC1.4.0

convert from puppeteer's coverage output to a format that can be used by istanbul reports

istanbul, puppeteer, convert, coverage

readme

Puppeteer to Istanbul

Build Status Coverage Status Standard Version

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

Usage

To Output Coverage in Istanbul Format with Puppeteer

  1. install puppeteer, npm i -D puppeteer.
  2. install puppeteer-to-istanbul, npm i -D puppeteer-to-istanbul.
  3. run your code in puppeteer with coverage enabled:

     (async () => {
       const pti = require('puppeteer-to-istanbul')
       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(),
       ]);
       pti.write([...jsCoverage, ...cssCoverage], { includeHostname: true , storagePath: './.nyc_output' })
       await browser.close()
     })()

To Check Istanbul Reports

  1. install nyc, npm i nyc -g.
  2. use nyc's report functionality:

     nyc report --reporter=html

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

see istanbul for a list of possible reporters.

Contributing

The best way to get started with Puppeteer to Istanbul is by installing it for yourself and running tests. PTI requires the most recent build of v8toistanbul to function properly, so start by running npm install.

Next, ensure that all tests are passing before continuing by running npm test (or equivalently, npm t). This should generate a report that gives the same coverage as seen on this README.

Note that a majority of the tests run against pre-generated fixtures, or JSON snippets, that come from Puppeteer's raw output. These are located in the \test\fixtures area. To generate one of your own, write or use one of the scripts in the test area test\sample_js, and run bin/puppeteer-js-runner.js through node, like so:

node bin/puppeteer-js-runner.js --file=/test/sample_js/sample2.js.

If you see an issue with Puppeteer to Istanbul, please open an issue! If you want to help improve Puppeteer to Istanbul, please fork the repository and open a pull request with your changes.

Make sure to review our contributing guide for specific guidelines on contributing.

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.4.0 (2020-06-11)

Features

  • allow a custom storagePath (#56) (eb1aabc)
  • allow the output file to not include the hostname (#57) (3a5b312)

1.3.1 (2020-05-11)

Bug Fixes

1.3.0 (2020-04-14)

Features

  • add support for complete path reporting on files with http(s) protocol (#17) (149716b)
  • include original url in final output. (#34) (dec48a2)

Bug Fixes

  • do not overwrite coverage after each test suite (#42) (848aa76)
  • JSON being output was not valid (de9109c)
  • write to disk incrementally (#40) (c57bd74)

1.2.2 (2018-03-03)

Bug Fixes

  • we need to create the .nyc_output folder if it doesn't exist (17c9e69)

1.2.1 (2018-03-01)

Bug Fixes

  • clone should be a regular dependency not a dev dependency (9dad7fc)

1.2.0 (2018-02-25)

Bug Fixes

  • file:// was missing (0ec1a0a)
  • output format didn't quite match v8 (#5) (8b669f8)

Features

  • add entry-point document (#10) (1f49ae5)
  • Implemented JS local copying and renaming for conversion to v8 (#6) (be72192)
  • implemented puppeteer to V8 class (#4) (327c1ef)

1.1.0 (2018-02-24)

Features

  • add command-line-tool for outputting coverage in puppeteer format (#1) (111354d)
  • initial library structure (6b2deb5)