mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
V8 cannot collect block coverage for functions that are deserialized from the code cache, so it only reports how many times each of them ran. With a warm compile cache, branches that never ran inside those functions are reported as covered, and tools that merge reports from several processes can report functions that ran as never run. The documentation recommended turning the cache off by hand. Do it automatically when coverage collection starts with the process, through NODE_V8_COVERAGE or --experimental-test-coverage. The compile cache tests stop propagating NODE_V8_COVERAGE to the processes they spawn, so that they keep working when the test suite itself runs with coverage. Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com> PR-URL: https://github.com/nodejs/node/pull/67120 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
common.skipIfInspectorDisabled();
|
|
|
|
const { spawnSyncAndAssert } = require('../common/child_process');
|
|
const assert = require('assert');
|
|
const fixtures = require('../common/fixtures');
|
|
const fs = require('fs');
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
const cacheDir = tmpdir.resolve('compile_cache');
|
|
const env = {
|
|
...process.env,
|
|
NODE_DEBUG_NATIVE: 'COMPILE_CACHE',
|
|
NODE_V8_COVERAGE: tmpdir.resolve('coverage'),
|
|
};
|
|
|
|
spawnSyncAndAssert(
|
|
process.execPath,
|
|
[fixtures.path('empty.js')],
|
|
{ env: { ...env, NODE_COMPILE_CACHE: cacheDir }, cwd: tmpdir.path },
|
|
{ stderr: /Disabled because V8 coverage is being collected/ });
|
|
assert(!fs.existsSync(cacheDir));
|
|
|
|
spawnSyncAndAssert(
|
|
process.execPath,
|
|
['-r', fixtures.path('compile-cache-wrapper.js'), fixtures.path('empty.js')],
|
|
{
|
|
env: {
|
|
...env,
|
|
NODE_COMPILE_CACHE: undefined,
|
|
NODE_TEST_COMPILE_CACHE_DIR: cacheDir,
|
|
},
|
|
cwd: tmpdir.path,
|
|
},
|
|
{
|
|
stdout(output) {
|
|
assert.match(output, /Compile cache already disabled/);
|
|
assert.match(output, /dir after enableCompileCache: undefined/);
|
|
},
|
|
stderr: /Disabled because V8 coverage is being collected/,
|
|
});
|
|
assert(!fs.existsSync(cacheDir));
|