Files
node/test/parallel/test-compile-cache-api-flush.js
Shelley Vohr dcaf43a167 module: disable the compile cache while V8 coverage is collected
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>
2026-11-20 14:59:50 +00:00

48 lines
1.8 KiB
JavaScript

'use strict';
// This tests module.flushCompileCache() works as expected.
require('../common');
const { spawnSyncAndAssert } = require('../common/compile-cache');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
{
// Test that it works with non-existent directory.
tmpdir.refresh();
const cacheDir = tmpdir.resolve('compile_cache');
spawnSyncAndAssert(
process.execPath,
[fixtures.path('compile-cache-flush.js')],
{
env: {
...process.env,
NODE_DEBUG_NATIVE: 'COMPILE_CACHE',
NODE_COMPILE_CACHE: cacheDir,
},
cwd: tmpdir.path
},
{
stdout(output) {
// This contains output from the nested spawnings of compile-cache-flush.js.
assert.match(output, /child1.* cache for .*compile-cache-flush\.js was accepted, keeping the in-memory entry/);
assert.match(output, /child2.* cache for .*compile-cache-flush\.js was accepted, keeping the in-memory entry/);
return true;
},
stderr(output) {
// This contains output from the top-level spawning of compile-cache-flush.js.
assert.match(output, /reading cache from .*compile_cache.* for CommonJS .*compile-cache-flush\.js/);
assert.match(output, /compile-cache-flush\.js was not initialized, initializing the in-memory entry/);
const writeRE = /writing cache for .*compile-cache-flush\.js.*success/;
const flushRE = /module\.flushCompileCache\(\) finished/;
assert.match(output, writeRE);
assert.match(output, flushRE);
// The cache writing should happen before flushing finishes i.e. it's not delayed until process shutdown.
assert(output.match(writeRE).index < output.match(flushRE).index);
return true;
}
});
}