Skip to content

Commit

Permalink
Fix event timing
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Nov 29, 2017
1 parent 7f1e920 commit 4944b9b
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions bin/c8.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,48 @@ const waitTillPortOpen = require('wait-till-port-open')

getPort().then(async port => {
foreground(
['node', `--inspect-brk=${port}`].concat(process.argv.slice(2)),
[process.execPath, `--inspect-brk=${port}`].concat(process.argv.slice(2)),
(done) => {
console.info('actually got here')
done()
}
)
try {
await waitTillPortOpen(port)
const client = await CRI({port: 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 Down

0 comments on commit 4944b9b

Please sign in to comment.