-
-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add processinfo index, add externalId (#1055)
If a NYC_PROCESSINFO_EXTERNAL_ID environment variable is set, then it is saved in the processinfo as `externalId`. 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. - Adds a NYC_PROCESS_ID to environment - Adds `parent` to processInfo object, a uuid referring to parent. - Rebase onto processinfo-numeric-pids branch - Avoid re-writing the processinfo/{uuid}.json files - Update process tree output to rely on process index instead of duplicating effort. 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.
- Loading branch information
1 parent
32f75b0
commit 8dcf180
Showing
5 changed files
with
214 additions
and
34 deletions.
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,95 @@ | ||
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: Number, | ||
ppid: Number, | ||
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), | ||
files: [ resolvedJS ] | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
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() | ||
}) |