Skip to content

Commit

Permalink
feat: implemented puppeteer to V8 class (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkoves authored and bcoe committed Feb 24, 2018
1 parent f3c679f commit 327c1ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
25 changes: 21 additions & 4 deletions lib/puppeteer-to-v8.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
class PuppeteerToV8 {
// constructor () {}
}
constructor (coverageInfo) {
this.coverageInfo = coverageInfo
}

setCoverageInfo (coverageInfo) {
this.coverageInfo = coverageInfo
}

module.exports = () => {
return new PuppeteerToV8()
convertCoverage () {
// Iterate through coverage info and create IDs
let id = 0

return this.coverageInfo.map(coverageItem => {
return {
scriptId: id++,
url: coverageItem.url,
functions: { ranges: coverageItem.ranges }
}
})
}
}

module.exports = () => new PuppeteerToV8()
21 changes: 16 additions & 5 deletions test/puppeteer-to-v8.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
/* globals describe, it */
/* globals describe, it, before */

const puppeteerToV8 = require('../lib/puppeteer-to-v8')()
var PuppeteerToV8 = require('../lib/puppeteer-to-v8')()

require('chai').should()

describe('puppeteer-to-v8', () => {
let v8Coverage
const fixture = require('./fixtures/function-coverage-missing')

before(() => {
PuppeteerToV8.setCoverageInfo(fixture)

v8Coverage = PuppeteerToV8.convertCoverage()
})

it('translates ranges into v8 format', () => {
console.info(puppeteerToV8)
// V8 coverage has ranges on a functions object, so check for that
v8Coverage[0].functions.ranges.should.eql(fixture[0].ranges)
})

// use mkdirp:
Expand All @@ -17,8 +27,9 @@ describe('puppeteer-to-v8', () => {

// look at the uuid library:
// uuid.v4()
it('generates scriptID', () => {

it('generates scriptId', () => {
// Ensures that the scriptId is of type 'number'
(typeof v8Coverage[0].scriptId).should.eql('number')
})

// for this test case, make sure we cover what happens
Expand Down

0 comments on commit 327c1ef

Please sign in to comment.