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

feat: first pass at functional prototype without subprocess support #5

Merged
merged 2 commits into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
node_modules
.nyc_output
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Loading