Skip to content

Commit

Permalink
test: make test-v8-coverage.js more strict
Browse files Browse the repository at this point in the history
Update the coverage test to verify that nothing is printed to
stderr (which happens when coverage errors happen). Also add a
test case to verify that non-absolute coverage paths work.

PR-URL: nodejs#25289
Fixes: nodejs#25287
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig committed Jan 2, 2019
1 parent a779ee4 commit 8881a5a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/parallel/test-v8-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function nextdir() {
require.resolve('../fixtures/v8-coverage/basic')
], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
assert.strictEqual(output.status, 0);
assert.strictEqual(output.stderr.toString(), '');
const fixtureCoverage = getFixtureCoverage('basic.js', coverageDirectory);
assert.ok(fixtureCoverage);
// first branch executed.
Expand All @@ -38,6 +39,7 @@ function nextdir() {
require.resolve('../fixtures/v8-coverage/exit-1')
], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
assert.strictEqual(output.status, 1);
assert.strictEqual(output.stderr.toString(), '');
const fixtureCoverage = getFixtureCoverage('exit-1.js', coverageDirectory);
assert.ok(fixtureCoverage, 'coverage not found for file');
// first branch executed.
Expand All @@ -55,6 +57,7 @@ function nextdir() {
if (!common.isWindows) {
assert.strictEqual(output.signal, 'SIGINT');
}
assert.strictEqual(output.stderr.toString(), '');
const fixtureCoverage = getFixtureCoverage('sigint.js', coverageDirectory);
assert.ok(fixtureCoverage);
// first branch executed.
Expand All @@ -70,6 +73,7 @@ function nextdir() {
require.resolve('../fixtures/v8-coverage/spawn-subprocess')
], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
assert.strictEqual(output.status, 0);
assert.strictEqual(output.stderr.toString(), '');
const fixtureCoverage = getFixtureCoverage('subprocess.js',
coverageDirectory);
assert.ok(fixtureCoverage);
Expand All @@ -87,6 +91,7 @@ function nextdir() {
require.resolve('../fixtures/v8-coverage/worker')
], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
assert.strictEqual(output.status, 0);
assert.strictEqual(output.stderr.toString(), '');
const fixtureCoverage = getFixtureCoverage('subprocess.js',
coverageDirectory);
assert.ok(fixtureCoverage);
Expand All @@ -103,6 +108,7 @@ function nextdir() {
require.resolve('../fixtures/v8-coverage/spawn-subprocess-no-cov')
], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
assert.strictEqual(output.status, 0);
assert.strictEqual(output.stderr.toString(), '');
const fixtureCoverage = getFixtureCoverage('subprocess.js',
coverageDirectory);
assert.strictEqual(fixtureCoverage, undefined);
Expand All @@ -115,13 +121,35 @@ function nextdir() {
require.resolve('../fixtures/v8-coverage/async-hooks')
], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
assert.strictEqual(output.status, 0);
assert.strictEqual(output.stderr.toString(), '');
const fixtureCoverage = getFixtureCoverage('async-hooks.js',
coverageDirectory);
assert.ok(fixtureCoverage);
// first branch executed.
assert.strictEqual(fixtureCoverage.functions[1].ranges[0].count, 1);
}

// Outputs coverage when the coverage directory is not absolute.
{
const coverageDirectory = nextdir();
const absoluteCoverageDirectory = path.join(tmpdir.path, coverageDirectory);
const output = spawnSync(process.execPath, [
require.resolve('../fixtures/v8-coverage/basic')
], {
cwd: tmpdir.path,
env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory }
});
assert.strictEqual(output.status, 0);
assert.strictEqual(output.stderr.toString(), '');
const fixtureCoverage = getFixtureCoverage('basic.js',
absoluteCoverageDirectory);
assert.ok(fixtureCoverage);
// first branch executed.
assert.strictEqual(fixtureCoverage.functions[1].ranges[0].count, 1);
// second branch did not execute.
assert.strictEqual(fixtureCoverage.functions[1].ranges[1].count, 0);
}

// Extracts the coverage object for a given fixture name.
function getFixtureCoverage(fixtureFile, coverageDirectory) {
const coverageFiles = fs.readdirSync(coverageDirectory);
Expand Down

0 comments on commit 8881a5a

Please sign in to comment.