-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add option to choose mode for display file coverage (#192)
BREAKING CHANGE: The File-Coverage will now only report files that were actually changed in the pull-request on default. This is to avoid large projects having problems with the comments on the PR being too big. To get the old behavior (always report all tested files), use the new setting 'file-coverage-mode: all'. --------- Co-authored-by: David Losert <davelosert@github.com>
- Loading branch information
1 parent
de9002f
commit 148463f
Showing
11 changed files
with
418 additions
and
132 deletions.
There are no files selected for viewing
This file contains 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 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 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,29 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import * as core from '@actions/core'; | ||
import { FileCoverageMode, getCoverageModeFrom } from './FileCoverageMode'; | ||
|
||
vi.mock('@actions/core', async (importOriginal) => ({ | ||
...importOriginal, | ||
warning: vi.fn(), | ||
})); | ||
|
||
describe('FileCoverageMode', () => { | ||
it('parses "all" to the right value', () => { | ||
expect(getCoverageModeFrom('all')).toBe(FileCoverageMode.All); | ||
}); | ||
|
||
it('parses "changes" to the right value', () => { | ||
expect(getCoverageModeFrom('changes')).toBe(FileCoverageMode.Changes); | ||
}); | ||
|
||
it('defaults to "changes" if the input is not valid', () => { | ||
expect(getCoverageModeFrom('invalid')).toBe(FileCoverageMode.Changes); | ||
}); | ||
|
||
it('logs a warning if the input is not valid', () => { | ||
const spy = vi.spyOn(core, 'warning'); | ||
getCoverageModeFrom('invalid'); | ||
expect(spy).toHaveBeenCalledWith('Not valid value "invalid" for summary mode, used "changes"'); | ||
spy.mockRestore(); | ||
}); | ||
}); |
This file contains 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,22 @@ | ||
import * as core from '@actions/core'; | ||
|
||
enum FileCoverageMode { | ||
All = 'all', | ||
Changes = 'changes', | ||
None = 'none', | ||
} | ||
|
||
function getCoverageModeFrom(input: string): FileCoverageMode { | ||
const allEnums = Object.values(FileCoverageMode) as string[]; | ||
const index = allEnums.indexOf(input); | ||
if (index === -1) { | ||
core.warning(`Not valid value "${input}" for summary mode, used "changes"`) | ||
return FileCoverageMode.Changes; | ||
} | ||
return input as FileCoverageMode; | ||
} | ||
|
||
export { | ||
FileCoverageMode, | ||
getCoverageModeFrom | ||
} |
This file contains 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.