node/test/parallel/test-v8-take-coverage-noop.js
Joyee Cheung fc5636e1eb v8: implement v8.takeCoverage()
Add an v8.takeCoverage() API that allows the user to write the
coverage started by NODE_V8_COVERAGE to disk on demand.
The coverage can be written multiple times during the lifetime
of the process, each time the execution counter will be reset.
When the process is about to exit, one last coverage will
still be written to disk.

Also refactors the internal profiler connection code
so that we use the inspector response id to identify
the profile response instead of using an ad-hoc flag in C++.

PR-URL: https://github.com/nodejs/node/pull/33807
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Ben Coe <bencoe@gmail.com>
2020-10-22 10:53:32 +00:00

33 lines
862 B
JavaScript

'use strict';
if (!process.features.inspector) return;
require('../common');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const { spawnSync } = require('child_process');
tmpdir.refresh();
// v8.takeCoverage() should be a noop if NODE_V8_COVERAGE is not set.
const intervals = 40;
{
const output = spawnSync(process.execPath, [
'-r',
fixtures.path('v8-coverage', 'take-coverage'),
fixtures.path('v8-coverage', 'interval'),
], {
env: {
...process.env,
NODE_DEBUG_NATIVE: 'INSPECTOR_PROFILER',
TEST_INTERVALS: intervals
},
});
console.log(output.stderr.toString());
assert.strictEqual(output.status, 0);
const coverageFiles = fs.readdirSync(tmpdir.path);
assert.strictEqual(coverageFiles.length, 0);
}