Comparing version 2.0.0 to 3.0.0-alpha.0
#!/usr/bin/env node | ||
'use strict' | ||
const CRI = require('chrome-remote-interface') | ||
const Exclude = require('test-exclude') | ||
const {isAbsolute} = require('path') | ||
const mkdirp = require('mkdirp') | ||
const foreground = require('foreground-child') | ||
const report = require('../lib/report') | ||
const {resolve} = require('path') | ||
const rimraf = require('rimraf') | ||
const spawn = require('../lib/spawn') | ||
const uuid = require('uuid') | ||
const v8ToIstanbul = require('v8-to-istanbul') | ||
const {writeFileSync} = require('fs') | ||
const sw = require('spawn-wrap') | ||
const { | ||
@@ -24,80 +16,12 @@ hideInstrumenteeArgs, | ||
const exclude = Exclude({ | ||
include: argv.include, | ||
exclude: argv.exclude | ||
sw([require.resolve('../lib/wrap')], { | ||
C8_ARGV: JSON.stringify(argv) | ||
}) | ||
;(async function executeWithCoverage (instrumenteeArgv) { | ||
try { | ||
const bin = instrumenteeArgv.shift() | ||
const info = await spawn(bin, | ||
[`--inspect-brk=0`].concat(instrumenteeArgv)) | ||
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 Promise.all([ | ||
Profiler.enable(), | ||
Runtime.enable(), | ||
Debugger.enable(), | ||
Profiler.startPreciseCoverage({callCount: true, detailed: true}), | ||
Runtime.runIfWaitingForDebugger(), | ||
initialPause | ||
]) | ||
await Debugger.resume() | ||
await executionComplete | ||
const allV8Coverage = await collectV8Coverage(Profiler) | ||
writeIstanbulFormatCoverage(allV8Coverage) | ||
await client.close() | ||
report({ | ||
reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter], | ||
coverageDirectory: argv.coverageDirectory, | ||
watermarks: argv.watermarks | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
process.exit(1) | ||
} | ||
})(hideInstrumenterArgs(argv)) | ||
async function collectV8Coverage (Profiler) { | ||
let {result} = await Profiler.takePreciseCoverage() | ||
result = result.filter(({url}) => { | ||
url = url.replace('file://', '') | ||
return isAbsolute(url) && exclude.shouldInstrument(url) | ||
foreground(hideInstrumenterArgs(argv), (out) => { | ||
report({ | ||
reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter], | ||
coverageDirectory: argv.coverageDirectory, | ||
watermarks: argv.watermarks | ||
}) | ||
return result | ||
} | ||
function writeIstanbulFormatCoverage (allV8Coverage) { | ||
const tmpDirctory = resolve(argv.coverageDirectory, './tmp') | ||
rimraf.sync(tmpDirctory) | ||
mkdirp.sync(tmpDirctory) | ||
allV8Coverage.forEach((v8) => { | ||
const script = v8ToIstanbul(v8.url) | ||
script.applyCoverage(v8.functions) | ||
writeFileSync( | ||
resolve(tmpDirctory, `./${uuid.v4()}.json`), | ||
JSON.stringify(script.toIstanbul(), null, 2), | ||
'utf8' | ||
) | ||
}) | ||
} | ||
}) |
{ | ||
"name": "c8", | ||
"version": "2.0.0", | ||
"version": "3.0.0-alpha.0", | ||
"description": "collect test coverage using v8's inspector", | ||
@@ -36,4 +36,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"chrome-remote-interface": "^0.25.2", | ||
"find-up": "^2.1.0", | ||
"foreground-child": "^1.5.6", | ||
"istanbul-lib-coverage": "^1.1.1", | ||
@@ -44,2 +44,4 @@ "istanbul-lib-report": "^1.1.2", | ||
"rimraf": "^2.6.2", | ||
"signal-exit": "^3.0.2", | ||
"spawn-wrap": "^1.4.2", | ||
"test-exclude": "^4.1.1", | ||
@@ -46,0 +48,0 @@ "uuid": "^3.1.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
0
10578
14
197
2
7
+ Addedforeground-child@^1.5.6
+ Addedsignal-exit@^3.0.2
+ Addedspawn-wrap@^1.4.2
+ Addedcross-spawn@4.0.2(transitive)
+ Addedforeground-child@1.5.6(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedspawn-wrap@1.4.3(transitive)
- Removedchrome-remote-interface@^0.25.2
- Removedasync-limiter@1.0.1(transitive)
- Removedchrome-remote-interface@0.25.7(transitive)
- Removedcommander@2.11.0(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedultron@1.1.1(transitive)
- Removedws@3.3.3(transitive)