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

Fix event timing #6

Merged
merged 2 commits into from
Dec 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions bin/c8.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
#!/usr/bin/env node
'use strict'

const {isAbsolute} = require('path')
const argv = require('yargs').parse()
const CRI = require('chrome-remote-interface')
const spawn = require('../lib/spawn')

;(async () => {
try {
info = await spawn(process.execPath,
[`--inspect-brk=0`].concat(process.argv.slice(2)))
const info = await spawn(process.execPath,
[`--inspect-brk=0`].concat(process.argv.slice(2)))
const client = await CRI({port: info.port})

const initialPause = new Promise((resolve) => {
client.once('Debugger.paused', resolve)
})

const mainContextInfo = new Promise((resolve) => {
client.once('Runtime.executionContextCreated', (message) => {
resolve(message.context)
})
})

const executionComplete = new Promise((resolve) => {
client.on('Runtime.executionContextDestroyed', async (message) => {
if (message.executionContextId === (await mainContextInfo).id) {
resolve(message)
}
})
})

const {Debugger, Runtime, Profiler} = client
await Runtime.runIfWaitingForDebugger()
await Runtime.enable()
await Profiler.enable()
await Profiler.startPreciseCoverage({callCount: true, detailed: true})
await Debugger.enable()
await Debugger.paused()
await Promise.all([
Profiler.enable(),
Runtime.enable(),
Debugger.enable(),
Profiler.startPreciseCoverage({callCount: true, detailed: true}),
Runtime.runIfWaitingForDebugger(),
initialPause
])
await Debugger.resume()

client.on('event', async (message) => {
// console.info(message)
if (message.method === 'Runtime.executionContextDestroyed') {
await outputCoverage(Profiler)
client.close()
}
})
await executionComplete
await outputCoverage(Profiler)
client.close()

} catch (err) {
console.error(err)
Expand All @@ -40,12 +58,8 @@ async function outputCoverage (Profiler) {
/node-spawn-wrap/
]
let {result} = await Profiler.takePreciseCoverage()
result = result.filter(coverage => {
for (var ignored, i = 0; (ignored = IGNORED_PATHS[i]) !== undefined; i++) {
if (ignored.test(coverage.url)) return false
}
if (!/^\//.test(coverage.url)) return false
else return true
result = result.filter(({url}) => {
return isAbsolute(url) && IGNORED_PATHS.every(ignored => !ignored.test(url))
})
console.log(JSON.stringify(result, null, 2))
}