Skip to content

Commit

Permalink
default allow-empty-coverage if disable-coverage set
Browse files Browse the repository at this point in the history
Fix: #1001
  • Loading branch information
isaacs committed Mar 8, 2024
1 parent 2d16686 commit e6dfb7a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,14 @@ export class TapConfig<C extends ConfigSet = BaseConfigSet> {
* Get a configuration value, as we currently know it
*/
get<K extends keyof OptionsResults<C>>(k: K): OptionsResults<C>[K] {
return this.parse().values[k]
const value = this.parse().values[k]
// special case: if --disable-coverage is set, then default
// --allow-empty-coverage to true, so we don't get unuseful failures.
if (k === 'allow-empty-coverage' && value === undefined) {
const disabled = this.get('disable-coverage')
if (disabled) return true as OptionsResults<C>[K]
}
return value
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/config/src/jack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,9 @@ export default jack({
description: `Do not generate code coverage information for the test run.
This will always result in a \`# No coverage generated\`
message being printed, and will cause the test run to exit
in error unless \`allow-empty-coverage\` is also set.
message being printed. If this flag is set, then
\`--allow-empty-coverage\` will default to \`true\`,
because we do not expect to get any coverage.
WARNING: tests that do not produce coverage are
untrustworthy. This should only be used when coverage is
Expand Down
2 changes: 1 addition & 1 deletion src/config/tap-snapshots/test/jack.ts.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Object {
"description": String(
Do not generate code coverage information for the test run.
This will always result in a \`# No coverage generated\` message being printed, and will cause the test run to exit in error unless \`allow-empty-coverage\` is also set.
This will always result in a \`# No coverage generated\` message being printed. If this flag is set, then \`--allow-empty-coverage\` will default to \`true\`, because we do not expect to get any coverage.
WARNING: tests that do not produce coverage are untrustworthy. This should only be used when coverage is being generated and tracked by some other mechanism.
),
Expand Down
17 changes: 17 additions & 0 deletions src/config/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,3 +892,20 @@ t.test('load file from env.TAP_RCFILE', async t => {
}
}
})

t.test('default allow-empty-coverage when disable-coverage set', async t => {
const dir = t.testdir({
'.taprc': `
disable-coverage: true
`,
})
const cwd = process.cwd()
t.teardown(() => process.chdir(cwd))
process.chdir(dir)
const { TapConfig } = await t.mockImport<
typeof import('../dist/esm/index.js')
>('../dist/esm/index.js')
const c = await TapConfig.load()
t.equal(c.get('disable-coverage'), true)
t.equal(c.get('allow-empty-coverage'), true)
})

0 comments on commit e6dfb7a

Please sign in to comment.