-
-
Notifications
You must be signed in to change notification settings - Fork 11
Support for non-global code coverage thresholds #18
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
Open
thall90
wants to merge
1
commit into
rbardini:main
Choose a base branch
from
thall90:non-global-coverage-thresholds
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ require('ansi-colors').enabled = false | |
|
|
||
| const getChanges = require('../getChanges') | ||
|
|
||
| console.warn = jest.fn() | ||
| const configPath = './jest.config.js' | ||
| const getContents = ( | ||
| level1 = 'coverageThreshold', | ||
|
|
@@ -18,38 +19,33 @@ const getContents = ( | |
| }, | ||
| }` | ||
| const getNewThresholds = ( | ||
| level2 = 'global', | ||
| newThresholds = { | ||
| branches: { diff: 70, next: 80, prev: 10 }, | ||
| functions: { diff: 50, next: 70, prev: 20 }, | ||
| lines: { diff: 30, next: 60, prev: 30 }, | ||
| statements: { diff: 10, next: 50, prev: 40 }, | ||
| }, | ||
| ) => newThresholds | ||
| ) => ({ [level2]: newThresholds }) | ||
|
|
||
| jest.mock('fs') | ||
|
|
||
| // Mock console.warn | ||
| jest.spyOn(console, 'warn').mockImplementation(() => {}) | ||
| beforeEach(() => { | ||
| console.warn.mockReset() | ||
| }) | ||
|
|
||
| it('returns the original contents and no changes if no new thresholds', () => { | ||
| const contents = getContents() | ||
| const newThresholds = getNewThresholds({}) | ||
| const newThresholds = getNewThresholds('global', {}) | ||
|
|
||
| fs.readFileSync.mockReturnValue(contents) | ||
| const { changes, data } = getChanges(configPath, newThresholds) | ||
|
|
||
| expect(fs.readFileSync).toHaveBeenCalledTimes(1) | ||
| expect(fs.readFileSync).toHaveBeenCalledWith(configPath, 'utf8') | ||
| expect(changes).toStrictEqual([]) | ||
| expect(data).toMatchInlineSnapshot(` | ||
| "module.exports = { | ||
| coverageThreshold: { | ||
| global: { | ||
| branches: 10, | ||
| functions: 20, | ||
| lines: 30, | ||
| statements: 40, | ||
| }, | ||
| }, | ||
| }" | ||
| `) | ||
| expect(data).toBe(contents) | ||
| }) | ||
|
|
||
|
|
@@ -61,10 +57,10 @@ it('returns the new contents and changes if new thresholds', () => { | |
| const { changes, data } = getChanges(configPath, newThresholds) | ||
|
|
||
| expect(changes).toStrictEqual([ | ||
| 'branches 10 → 80 +70', | ||
| 'functions 20 → 70 +50', | ||
| 'lines 30 → 60 +30', | ||
| 'statements 40 → 50 +10', | ||
| 'global branches 10 → 80 +70', | ||
| 'global functions 20 → 70 +50', | ||
| 'global lines 30 → 60 +30', | ||
| 'global statements 40 → 50 +10', | ||
| ]) | ||
| expect(data).toMatchInlineSnapshot(` | ||
| "module.exports = { | ||
|
|
@@ -89,7 +85,12 @@ it.each([ | |
| 'returns the original contents and no changes if no matches #%#', | ||
| (level1, level2) => { | ||
| const contents = getContents(level1, level2) | ||
| const newThresholds = getNewThresholds() | ||
| const newThresholds = getNewThresholds(level2, { | ||
| branches: { diff: 0, next: 10, prev: 10 }, | ||
| functions: { diff: 0, next: 20, prev: 20 }, | ||
| lines: { diff: 0, next: 30, prev: 30 }, | ||
| statements: { diff: 0, next: 40, prev: 40 }, | ||
| }) | ||
|
|
||
| fs.readFileSync.mockReturnValueOnce(contents) | ||
| const { changes, data } = getChanges(configPath, newThresholds) | ||
|
|
@@ -98,3 +99,43 @@ it.each([ | |
| expect(data).toBe(contents) | ||
| }, | ||
| ) | ||
|
|
||
| it('returns changes for an updated custom threshold', () => { | ||
| fs.readFileSync.mockReturnValue(` | ||
| module.exports = { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the |
||
| coverageThreshold: { | ||
| global: { | ||
| branches: 0, | ||
| functions: 0, | ||
| lines: 0, | ||
| statements: 0, | ||
| }, | ||
| './src/modules/**/*.module.ts': { | ||
| branches: 50, | ||
| functions: 60, | ||
| lines: 70, | ||
| statements: 80, | ||
| }, | ||
| }, | ||
| } | ||
| `) | ||
|
|
||
| const changes = getChanges('./jest.config.js', { | ||
| './src/modules/**/*.module.ts': { | ||
| branches: { prev: 50, next: 55, diff: 5 }, | ||
| functions: { prev: 60, next: 65, diff: 5 }, | ||
| lines: { prev: 70, next: 75, diff: 5 }, | ||
| statements: { prev: 80, next: 85, diff: 5 }, | ||
| }, | ||
| }) | ||
|
|
||
| expect(changes).toEqual({ | ||
| data: expect.any(String), | ||
| changes: [ | ||
| './src/modules/**/*.module.ts branches 50 → 55 +5', | ||
| './src/modules/**/*.module.ts functions 60 → 65 +5', | ||
| './src/modules/**/*.module.ts lines 70 → 75 +5', | ||
| './src/modules/**/*.module.ts statements 80 → 85 +5', | ||
| ], | ||
| }) | ||
| }) | ||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jest calls these "paths", I think we should do the same for consistency. Also, we should probably use a variadic option: