-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coverage drop comparison by overall coverage (#9)
- Loading branch information
Showing
12 changed files
with
2,907 additions
and
2,338 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
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 |
---|---|---|
@@ -1,114 +1,134 @@ | ||
import { | ||
formatArtifactName, | ||
checkFileExists, | ||
createHash, | ||
roundPercentage, | ||
determineCommonBasePath, | ||
escapeRegExp, | ||
colorizePercentageByThreshold, | ||
getInputs | ||
} from '../src/utils' | ||
import { | ||
expect, | ||
test, | ||
beforeEach, | ||
afterEach, | ||
describe, | ||
jest | ||
} from '@jest/globals' | ||
|
||
const env = process.env | ||
|
||
beforeEach(() => { | ||
jest.resetModules() | ||
process.env = {...env} | ||
}) | ||
|
||
afterEach(() => { | ||
process.env = env | ||
}) | ||
|
||
test('formats the artifact name', async () => { | ||
process.env.INPUT_GITHUB_TOKEN = 'token' | ||
process.env.INPUT_FILENAME = 'filename.xml' | ||
process.env.INPUT_ARTIFACT_NAME = 'coverage-%name%' | ||
const name = formatArtifactName('bar') | ||
expect(name).toBe('coverage-bar') | ||
}) | ||
|
||
test('files exists', async () => { | ||
const ret = await checkFileExists(__filename) | ||
expect(ret).toBeTruthy() | ||
|
||
const ret1 = await checkFileExists(__filename + 'bar') | ||
expect(ret1).toBeFalsy() | ||
}) | ||
|
||
test('created hash', () => { | ||
const hash = createHash('foo') | ||
expect(hash).toBeDefined() | ||
}) | ||
|
||
test('round percentage', () => { | ||
const a = roundPercentage(45.51234565) | ||
expect(a).toBe(45.51) | ||
|
||
const b = roundPercentage(45.51634565) | ||
expect(b).toBe(45.52) | ||
}) | ||
|
||
test('determine common base path from list of paths', () => { | ||
const path = determineCommonBasePath([ | ||
'/usr/src/app/foo.js', | ||
'/usr/src/app/foo/bar.js' | ||
]) | ||
|
||
expect(path).toBe('/usr/src/app') | ||
}) | ||
|
||
test('escaping regular expression input', () => { | ||
const output = escapeRegExp('\\^$.|?*+{}[]()') | ||
expect(output).toBe('\\\\\\^\\$\\.\\|\\?\\*\\+\\{\\}\\[\\]\\(\\)') | ||
}) | ||
|
||
test('colorize percentage by threshold', () => { | ||
const shouldBeNA = colorizePercentageByThreshold(null) | ||
expect(shouldBeNA).toBe('N/A') | ||
|
||
const shouldBeGrey = colorizePercentageByThreshold(0) | ||
expect(shouldBeGrey).toBe('⚪ 0%') | ||
|
||
const shouldBeRed = colorizePercentageByThreshold(20, 50) | ||
expect(shouldBeRed).toBe('🔴 20%') | ||
|
||
const shouldBeGreen = colorizePercentageByThreshold(70, 50) | ||
expect(shouldBeGreen).toBe('🟢 70%') | ||
|
||
const shouldBeRedA = colorizePercentageByThreshold(20, 75, 30) | ||
expect(shouldBeRedA).toBe('🔴 20%') | ||
|
||
const shouldBeOrangeA = colorizePercentageByThreshold(40, 75, 30) | ||
expect(shouldBeOrangeA).toBe('🟠 40%') | ||
|
||
const shouldBeGreenA = colorizePercentageByThreshold(80, 75, 30) | ||
expect(shouldBeGreenA).toBe('🟢 80%') | ||
}) | ||
|
||
test('getInputs', () => { | ||
process.env.INPUT_GITHUB_TOKEN = 'token' | ||
process.env.INPUT_FILENAME = 'filename.xml' | ||
|
||
const f = getInputs() | ||
expect(f).toStrictEqual({ | ||
token: 'token', | ||
filename: 'filename.xml', | ||
badge: false, | ||
overallCoverageFailThreshold: 0, | ||
fileCoverageErrorMin: 50, | ||
fileCoverageWarningMax: 75, | ||
failOnNegativeDifference: false, | ||
markdownFilename: 'code-coverage-results', | ||
artifactDownloadWorkflowNames: null, | ||
artifactName: 'coverage-%name%' | ||
}) | ||
}) | ||
import { | ||
formatArtifactName, | ||
checkFileExists, | ||
createHash, | ||
roundPercentage, | ||
determineCommonBasePath, | ||
escapeRegExp, | ||
colorizePercentageByThreshold, | ||
getInputs, | ||
parseXML, | ||
parseCoverage | ||
} from '../src/utils' | ||
import { | ||
expect, | ||
test, | ||
beforeEach, | ||
afterEach, | ||
describe, | ||
jest | ||
} from '@jest/globals' | ||
|
||
const env = process.env | ||
|
||
beforeEach(() => { | ||
jest.resetModules() | ||
process.env = {...env} | ||
}) | ||
|
||
afterEach(() => { | ||
process.env = env | ||
}) | ||
|
||
test('formats the artifact name', async () => { | ||
process.env.INPUT_GITHUB_TOKEN = 'token' | ||
process.env.INPUT_FILENAME = 'filename.xml' | ||
process.env.INPUT_ARTIFACT_NAME = 'coverage-%name%' | ||
const name = formatArtifactName('bar') | ||
expect(name).toBe('coverage-bar') | ||
}) | ||
|
||
test('files exists', async () => { | ||
const ret = await checkFileExists(__filename) | ||
expect(ret).toBeTruthy() | ||
|
||
const ret1 = await checkFileExists(__filename + 'bar') | ||
expect(ret1).toBeFalsy() | ||
}) | ||
|
||
test('created hash', () => { | ||
const hash = createHash('foo') | ||
expect(hash).toBeDefined() | ||
}) | ||
|
||
test('round percentage', () => { | ||
const a = roundPercentage(45.51234565) | ||
expect(a).toBe(45.51) | ||
|
||
const b = roundPercentage(45.51634565) | ||
expect(b).toBe(45.52) | ||
}) | ||
|
||
test('determine common base path from list of paths', () => { | ||
const path = determineCommonBasePath([ | ||
'/usr/src/app/foo.js', | ||
'/usr/src/app/foo/bar.js' | ||
]) | ||
|
||
expect(path).toBe('/usr/src/app') | ||
}) | ||
|
||
test('escaping regular expression input', () => { | ||
const output = escapeRegExp('\\^$.|?*+{}[]()') | ||
expect(output).toBe('\\\\\\^\\$\\.\\|\\?\\*\\+\\{\\}\\[\\]\\(\\)') | ||
}) | ||
|
||
test('colorize percentage by threshold', () => { | ||
const shouldBeZero = colorizePercentageByThreshold(null) | ||
expect(shouldBeZero).toBe('⚪ 0%') | ||
|
||
const shouldBeGrey = colorizePercentageByThreshold(0) | ||
expect(shouldBeGrey).toBe('⚪ 0%') | ||
|
||
const shouldBeRed = colorizePercentageByThreshold(20, 50) | ||
expect(shouldBeRed).toBe('🔴 20%') | ||
|
||
const shouldBeGreen = colorizePercentageByThreshold(70, 50) | ||
expect(shouldBeGreen).toBe('🟢 70%') | ||
|
||
const shouldBeRedA = colorizePercentageByThreshold(20, 75, 30) | ||
expect(shouldBeRedA).toBe('🔴 20%') | ||
|
||
const shouldBeOrangeA = colorizePercentageByThreshold(40, 75, 30) | ||
expect(shouldBeOrangeA).toBe('🟠 40%') | ||
|
||
const shouldBeGreenA = colorizePercentageByThreshold(80, 75, 30) | ||
expect(shouldBeGreenA).toBe('🟢 80%') | ||
}) | ||
|
||
test('parse xml', async () => { | ||
const ret = await parseXML(__filename) | ||
expect(ret).toBeTruthy() | ||
|
||
const ret1 = await parseXML(__filename + 'bar') | ||
expect(ret1).toBeFalsy() | ||
}) | ||
|
||
test('parse coverage', async () => { | ||
const ret = await parseCoverage(__filename) | ||
expect(ret).not.toBeNull | ||
|
||
const ret1 = await parseCoverage(__filename + 'bar') | ||
expect(ret1).toBeNull | ||
}) | ||
|
||
test('getInputs', () => { | ||
process.env.INPUT_GITHUB_TOKEN = 'token' | ||
process.env.INPUT_FILENAME = 'filename.xml' | ||
|
||
const f = getInputs() | ||
expect(f).toStrictEqual({ | ||
token: 'token', | ||
filename: 'filename.xml', | ||
badge: false, | ||
overallCoverageFailThreshold: 0, | ||
fileCoverageErrorMin: 50, | ||
fileCoverageWarningMax: 75, | ||
failOnNegativeDifference: false, | ||
markdownFilename: 'code-coverage-results', | ||
artifactDownloadWorkflowNames: null, | ||
artifactName: 'coverage-%name%', | ||
negativeDifferenceBy: 'package', | ||
retention: undefined | ||
}) | ||
}) |
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.