-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jest-reporters: Use global coverage thresholds as high watermarks (#9416
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 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
44 changes: 44 additions & 0 deletions
44
packages/jest-reporters/src/__tests__/get_watermarks.test.ts
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,44 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import getWatermarks from '../get_watermarks'; | ||
import {makeGlobalConfig} from '../../../../TestUtils'; | ||
|
||
describe('getWatermarks', () => { | ||
test(`that watermarks use thresholds as upper target`, () => { | ||
const watermarks = getWatermarks( | ||
makeGlobalConfig({ | ||
coverageThreshold: { | ||
global: { | ||
branches: 100, | ||
functions: 100, | ||
lines: 100, | ||
statements: 100, | ||
}, | ||
}, | ||
}), | ||
); | ||
|
||
expect(watermarks).toEqual({ | ||
branches: [expect.any(Number), 100], | ||
functions: [expect.any(Number), 100], | ||
lines: [expect.any(Number), 100], | ||
statements: [expect.any(Number), 100], | ||
}); | ||
}); | ||
|
||
test(`that watermarks are created always created`, () => { | ||
const watermarks = getWatermarks(makeGlobalConfig()); | ||
|
||
expect(watermarks).toEqual({ | ||
branches: [expect.any(Number), expect.any(Number)], | ||
functions: [expect.any(Number), expect.any(Number)], | ||
lines: [expect.any(Number), expect.any(Number)], | ||
statements: [expect.any(Number), expect.any(Number)], | ||
}); | ||
}); | ||
}); |
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,36 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {Config} from '@jest/types'; | ||
import istanbulReport = require('istanbul-lib-report'); | ||
|
||
export default function getWatermarks( | ||
config: Config.GlobalConfig, | ||
): istanbulReport.Watermarks { | ||
const defaultWatermarks = istanbulReport.getDefaultWatermarks(); | ||
|
||
const {coverageThreshold} = config; | ||
|
||
if (!coverageThreshold || !coverageThreshold.global) { | ||
return defaultWatermarks; | ||
} | ||
|
||
const keys: Array<keyof Config.CoverageThresholdValue> = [ | ||
'branches', | ||
'functions', | ||
'lines', | ||
'statements', | ||
]; | ||
return keys.reduce((watermarks, key) => { | ||
const value = coverageThreshold.global[key]; | ||
if (value !== undefined) { | ||
watermarks[key][1] = value; | ||
} | ||
|
||
return watermarks; | ||
}, defaultWatermarks); | ||
} |