Skip to content

Commit

Permalink
feat: first pass at functional prototype without subprocess support (#5)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: dropped subprocess support for the time being, while we march towards an initial implementation.
  • Loading branch information
bcoe committed Nov 27, 2017
1 parent 38dff30 commit 9534f56
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 170 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
.DS_Store
node_modules
.nyc_output
14 changes: 10 additions & 4 deletions README.md
Expand Up @@ -14,13 +14,19 @@ The above example will collect coverage for `foo.js` using v8's profiler.

TODO:

- [ ] write logic for converting v8 coverage output to [Istanbul Coverage.json format](https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md).
- [x] write logic for converting v8 coverage output to [Istanbul Coverage.json format](https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md).
* https://github.com/bcoe/v8-to-istanbul

- [ ] talk to Node.js project about silencing messages:

> `Debugger listening on ws://127.0.0.1:56399/e850110a-c5df-41d8-8ef2-400f6829617f`.
- [ ] figure out why `detailed` mode does not appear to be working.
- [ ] figure out a better way to determine that all processes in event loop
- [x] figure out why `detailed` mode does not appear to be working.
* this is fixed in v8, as long as you start with `--inspect-brk` you
can collect coverage in detailed mode.
- [x] figure out a better way to determine that all processes in event loop
have terminated (except the inspector session).
- [ ] process.exit() can't perform an async operation; how can we track coverage
- [x] process.exit() can't perform an async operation; how can we track coverage
for scripts that exit?
* we can now listen for the `Runtime.executionContextDestroyed` event.
- [ ]
56 changes: 52 additions & 4 deletions bin/c8.js
@@ -1,10 +1,58 @@
#!/usr/bin/env node

const argv = require('yargs').parse()
const CRI = require('chrome-remote-interface')
const getPort = require('get-port');
const foreground = require('foreground-child')
const sw = require('spawn-wrap')
const waitTillPortOpen = require('wait-till-port-open')

if (argv._.length) {
sw([require.resolve('./wrap')])
foreground(process.argv.slice(2))
getPort().then(async port => {
foreground(
['node', `--inspect-brk=${port}`].concat(process.argv.slice(2)),
(done) => {
console.info('actually got here')
}
)
try {
await waitTillPortOpen(port)
const client = await CRI({port: port})

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 Debugger.resume()

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

} catch (err) {
console.error(err)
process.exit(1)
}
})

async function outputCoverage (Profiler) {
const IGNORED_PATHS = [
/\/bin\/wrap.js/,
/\/node_modules\//,
/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
})
console.log(JSON.stringify(result, null, 2))
}
52 changes: 0 additions & 52 deletions bin/wrap.js

This file was deleted.

Empty file removed index.js
Empty file.
135 changes: 26 additions & 109 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -25,7 +25,7 @@
"chrome-remote-interface": "^0.25.2",
"foreground-child": "^1.5.6",
"get-port": "^3.2.0",
"spawn-wrap": "=1.3.8",
"wait-till-port-open": "^1.0.0",
"yargs": "^10.0.3"
},
"devDependencies": {
Expand Down

0 comments on commit 9534f56

Please sign in to comment.