-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
test_runner: exclude test files from coverage by default #56060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4f5885e
test_runner: exclude test files from coverage by default
pmarchini 4e2bdf6
test: add default coverage default exclusions test
pmarchini 1e5a29c
lib: move glob from path to internal/fs/glob
pmarchini 2692e5f
test: skip test if no inspector
pmarchini 70be970
lib: rename glob to matchGlobPattern
pmarchini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test/fixtures/test-runner/coverage-default-exclusion/file-test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const test = require('node:test'); | ||
const assert = require('node:assert'); | ||
const { foo } = require('./logic-file'); | ||
|
||
test('foo returns 1', () => { | ||
assert.strictEqual(foo(), 1); | ||
}); |
7 changes: 7 additions & 0 deletions
7
test/fixtures/test-runner/coverage-default-exclusion/file.test.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import test from 'node:test'; | ||
import assert from 'node:assert'; | ||
import { foo } from './logic-file.js'; | ||
|
||
test('foo returns 1', () => { | ||
assert.strictEqual(foo(), 1); | ||
}); |
7 changes: 7 additions & 0 deletions
7
test/fixtures/test-runner/coverage-default-exclusion/file.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import test from 'node:test'; | ||
import assert from 'node:assert'; | ||
import { foo } from './logic-file.js'; | ||
|
||
test('foo returns 1', () => { | ||
assert.strictEqual(foo(), 1); | ||
}); |
9 changes: 9 additions & 0 deletions
9
test/fixtures/test-runner/coverage-default-exclusion/logic-file.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function foo() { | ||
return 1; | ||
} | ||
|
||
function bar() { | ||
return 'bar'; | ||
} | ||
|
||
module.exports = { foo, bar }; |
7 changes: 7 additions & 0 deletions
7
test/fixtures/test-runner/coverage-default-exclusion/test.cjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const test = require('node:test'); | ||
const assert = require('node:assert'); | ||
const { foo } = require('./logic-file.js'); | ||
|
||
test('foo returns 1', () => { | ||
assert.strictEqual(foo(), 1); | ||
}); |
7 changes: 7 additions & 0 deletions
7
test/fixtures/test-runner/coverage-default-exclusion/test/not-matching-test-name.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const test = require('node:test'); | ||
const assert = require('node:assert'); | ||
const { foo } = require('../logic-file.js'); | ||
|
||
test('foo returns 1', () => { | ||
assert.strictEqual(foo(), 1); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
test/parallel/test-runner-coverage-default-exclusion.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import '../common/index.mjs'; | ||
import { before, describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
import { spawnSync } from 'node:child_process'; | ||
import { cp } from 'node:fs/promises'; | ||
import tmpdir from '../common/tmpdir.js'; | ||
import fixtures from '../common/fixtures.js'; | ||
const skipIfNoInspector = { | ||
skip: !process.features.inspector ? 'inspector disabled' : false | ||
}; | ||
|
||
tmpdir.refresh(); | ||
|
||
async function setupFixtures() { | ||
const fixtureDir = fixtures.path('test-runner', 'coverage-default-exclusion'); | ||
await cp(fixtureDir, tmpdir.path, { recursive: true }); | ||
} | ||
|
||
describe('test runner coverage default exclusion', skipIfNoInspector, () => { | ||
before(async () => { | ||
await setupFixtures(); | ||
}); | ||
|
||
it('should override default exclusion setting --test-coverage-exclude', async () => { | ||
const report = [ | ||
'# start of coverage report', | ||
'# ---------------------------------------------------------------------------', | ||
'# file | line % | branch % | funcs % | uncovered lines', | ||
'# ---------------------------------------------------------------------------', | ||
'# file-test.js | 100.00 | 100.00 | 100.00 | ', | ||
'# file.test.mjs | 100.00 | 100.00 | 100.00 | ', | ||
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7', | ||
'# test.cjs | 100.00 | 100.00 | 100.00 | ', | ||
'# test | | | | ', | ||
'# not-matching-test-name.js | 100.00 | 100.00 | 100.00 | ', | ||
'# ---------------------------------------------------------------------------', | ||
'# all files | 91.89 | 100.00 | 83.33 | ', | ||
'# ---------------------------------------------------------------------------', | ||
'# end of coverage report', | ||
].join('\n'); | ||
|
||
|
||
const args = [ | ||
'--test', | ||
'--experimental-test-coverage', | ||
'--test-coverage-exclude=!test/**', | ||
'--test-reporter=tap', | ||
]; | ||
const result = spawnSync(process.execPath, args, { | ||
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path }, | ||
cwd: tmpdir.path | ||
}); | ||
|
||
assert.strictEqual(result.stderr.toString(), ''); | ||
assert(result.stdout.toString().includes(report)); | ||
assert.strictEqual(result.status, 0); | ||
}); | ||
|
||
it('should exclude test files from coverage by default', async () => { | ||
const report = [ | ||
'# start of coverage report', | ||
'# --------------------------------------------------------------', | ||
'# file | line % | branch % | funcs % | uncovered lines', | ||
'# --------------------------------------------------------------', | ||
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7', | ||
'# --------------------------------------------------------------', | ||
'# all files | 66.67 | 100.00 | 50.00 | ', | ||
'# --------------------------------------------------------------', | ||
'# end of coverage report', | ||
].join('\n'); | ||
|
||
const args = [ | ||
'--test', | ||
'--experimental-test-coverage', | ||
'--test-reporter=tap', | ||
]; | ||
const result = spawnSync(process.execPath, args, { | ||
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path }, | ||
cwd: tmpdir.path | ||
}); | ||
|
||
assert.strictEqual(result.stderr.toString(), ''); | ||
assert(result.stdout.toString().includes(report)); | ||
assert.strictEqual(result.status, 0); | ||
}); | ||
|
||
it('should exclude ts test files when using --experimental-strip-types', async () => { | ||
const report = [ | ||
'# start of coverage report', | ||
'# --------------------------------------------------------------', | ||
'# file | line % | branch % | funcs % | uncovered lines', | ||
'# --------------------------------------------------------------', | ||
'# logic-file.js | 66.67 | 100.00 | 50.00 | 5-7', | ||
'# --------------------------------------------------------------', | ||
'# all files | 66.67 | 100.00 | 50.00 | ', | ||
'# --------------------------------------------------------------', | ||
'# end of coverage report', | ||
].join('\n'); | ||
|
||
const args = [ | ||
'--test', | ||
'--experimental-test-coverage', | ||
'--experimental-strip-types', | ||
'--disable-warning=ExperimentalWarning', | ||
'--test-reporter=tap', | ||
]; | ||
const result = spawnSync(process.execPath, args, { | ||
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path }, | ||
cwd: tmpdir.path | ||
}); | ||
|
||
assert.strictEqual(result.stderr.toString(), ''); | ||
assert(result.stdout.toString().includes(report)); | ||
assert.strictEqual(result.status, 0); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.