Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
THIS IS A WIP COMMIT FOR REVIEW ONLY, DO NOT MERGE
Docs and tests still TK. Future commit message follows. --- feat: add processinfo index, add externalId If a NYC_PROCESSINFO_EXTERNAL_ID environment variable is set, then it is saved in the processinfo as `externalId`. BREAKING CHANGE: This adds a file named 'index.json' to the .nyc_output/processinfo directory, which has a different format from the other files in this dir. Furthermore, when this file is generated, some additional helpful metadata is memoized to the processinfo json files, to minimize the cost of repeated generation. (This isn't necessarily a breaking change, but it is an update to the de facto schema for those files.) As soon as possible, index generation and process tree display should be migrated out to a new 'istanbul-lib-processinfo' library. This opens the door to add features in the v14 release family to improve support for partial/resumed test runs and file watching. - When a process is run with --clean=false and a previously seen externalId, clear away all the coverage files in the set for that externalId. - When a file is changed, a test runner can use the index to determine which tests (by externalId) ought to be re-run.
- Loading branch information
Showing
5 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const {resolve} = require('path') | ||
const bin = resolve(__dirname, '../self-coverage/bin/nyc') | ||
const {spawn} = require('child_process') | ||
const t = require('tap') | ||
const rimraf = require('rimraf') | ||
const node = process.execPath | ||
const fixturesCLI = resolve(__dirname, './fixtures/cli') | ||
const tmp = 'processinfo-test' | ||
const fs = require('fs') | ||
const resolvedJS = resolve(fixturesCLI, 'selfspawn-fibonacci.js') | ||
|
||
rimraf.sync(resolve(fixturesCLI, tmp)) | ||
t.teardown(() => rimraf.sync(resolve(fixturesCLI, tmp))) | ||
|
||
t.test('build some processinfo', t => { | ||
var args = [ | ||
bin, '-t', tmp, '--build-process-tree', | ||
node, 'selfspawn-fibonacci.js', '5', | ||
] | ||
var proc = spawn(process.execPath, args, { | ||
cwd: fixturesCLI, | ||
env: { | ||
PATH: process.env.PATH, | ||
NYC_PROCESSINFO_EXTERNAL_ID: 'blorp', | ||
} | ||
}) | ||
// don't actually care about the output for this test, just the data | ||
proc.stderr.resume() | ||
proc.stdout.resume() | ||
proc.on('close', (code, signal) => { | ||
t.equal(code, 0) | ||
t.equal(signal, null) | ||
t.end() | ||
}) | ||
}) | ||
|
||
t.test('validate the created processinfo data', t => { | ||
const covs = fs.readdirSync(resolve(fixturesCLI, tmp)) | ||
.filter(f => f !== 'processinfo') | ||
t.plan(covs.length * 2) | ||
|
||
covs.forEach(f => { | ||
fs.readFile(resolve(fixturesCLI, tmp, f), 'utf8', (er, covjson) => { | ||
if (er) | ||
throw er | ||
const covdata = JSON.parse(covjson) | ||
t.same(Object.keys(covdata), [resolvedJS]) | ||
// should have matching processinfo for each cov json | ||
const procInfoFile = resolve(fixturesCLI, tmp, 'processinfo', f) | ||
fs.readFile(procInfoFile, 'utf8', (er, procInfoJson) => { | ||
if (er) | ||
throw er | ||
const procInfoData = JSON.parse(procInfoJson) | ||
t.match(procInfoData, { | ||
pid: /^[0-9]+$/, | ||
ppid: /^[0-9]+$/, | ||
uuid: f.replace(/\.json$/, ''), | ||
argv: [ | ||
node, | ||
resolvedJS, | ||
/[1-5]/, | ||
], | ||
execArgv: [], | ||
cwd: fixturesCLI, | ||
time: Number, | ||
root: /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/, | ||
coverageFilename: resolve(fixturesCLI, tmp, f), | ||
nodes: [], | ||
_coverageMap: null, | ||
files: [ resolvedJS ], | ||
children: Array, | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
t.test('check out the index', t => { | ||
const indexFile = resolve(fixturesCLI, tmp, 'processinfo', 'index.json') | ||
const indexJson = fs.readFileSync(indexFile, 'utf-8') | ||
const index = JSON.parse(indexJson) | ||
const u = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/ | ||
t.match(index, { | ||
processes: {}, | ||
files: { | ||
[resolvedJS]: [u, u, u, u, u, u, u, u, u ], | ||
}, | ||
externalIds: { | ||
blorp: { | ||
root: u, | ||
children: [u, u, u, u, u, u, u, u ], | ||
}, | ||
}, | ||
}) | ||
t.end() | ||
}) |