mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -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>
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
// This tests NODE_COMPILE_CACHE works.
|
|
|
|
require('../common');
|
|
const { spawnSyncAndExit } = require('../common/compile-cache');
|
|
const fixtures = require('../common/fixtures');
|
|
const tmpdir = require('../common/tmpdir');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
{
|
|
// Test that it throws if the script fails to parse, and no cache is created.
|
|
tmpdir.refresh();
|
|
const dir = tmpdir.resolve('.compile_cache_dir');
|
|
|
|
spawnSyncAndExit(
|
|
process.execPath,
|
|
[fixtures.path('syntax', 'bad_syntax.js')],
|
|
{
|
|
env: {
|
|
...process.env,
|
|
NODE_DEBUG_NATIVE: 'COMPILE_CACHE',
|
|
NODE_COMPILE_CACHE: dir
|
|
},
|
|
cwd: tmpdir.path
|
|
},
|
|
{
|
|
status: 1,
|
|
stderr: /skip .*bad_syntax\.js because the cache was not initialized/,
|
|
});
|
|
|
|
const cacheDir = fs.readdirSync(dir);
|
|
assert.strictEqual(cacheDir.length, 1);
|
|
const entries = fs.readdirSync(path.join(dir, cacheDir[0]));
|
|
assert.strictEqual(entries.length, 0);
|
|
|
|
spawnSyncAndExit(
|
|
process.execPath,
|
|
[fixtures.path('syntax', 'bad_syntax.mjs')],
|
|
{
|
|
env: {
|
|
...process.env,
|
|
NODE_DEBUG_NATIVE: 'COMPILE_CACHE',
|
|
NODE_COMPILE_CACHE: dir
|
|
},
|
|
cwd: tmpdir.path
|
|
},
|
|
{
|
|
status: 1,
|
|
stderr: /skip .*bad_syntax\.mjs because the cache was not initialized/,
|
|
});
|
|
}
|