Skip to content

Commit

Permalink
Coverage directory -s (#89)
Browse files Browse the repository at this point in the history
* coverage directory

* fix tests
  • Loading branch information
eddiemoore authored May 12, 2021
1 parent 71b2d37 commit 8be63a6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bin/codecov
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ var argv = require("yargs") // eslint-disable-line
alias: "P",
description: "Specify the pull request number mannually"
},
dir: {
alias: "s",
description: "Directory to search for coverage reports.\nAlready searches project root and current working directory"
},
token: {
alias: "t",
default: "",
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function dryRun (uploadHost, token, query, uploadFile) {
* @param {Object} args
* @param {string} args.build Specify the build number manually
* @param {string} args.branch Specify the branch manually
* @param {string} args.dir Directory to search for coverage reports.
* @param {string} args.env Specify environment variables to be included with this build
* @param {string} args.sha Specify the commit SHA mannually
* @param {string} args.file Target file(s) to upload
Expand Down Expand Up @@ -82,7 +83,7 @@ async function main (args) {
let coverageFilePaths = []
if (!args.file) {
coverageFilePaths = fileHelpers.getCoverageFiles(
projectRoot,
args.dir || projectRoot,
// TODO: Determine why this is so slow (I suspect it's walking paths it should not)
fileHelpers.coverageFilePatterns()
)
Expand Down Expand Up @@ -117,7 +118,7 @@ async function main (args) {
for (let index = 0; index < coverageFilePaths.length; index++) {
const coverageFile = coverageFilePaths[index]
const fileContents = await fileHelpers.readCoverageFile(
'.',
args.dir || projectRoot,
coverageFile
)
uploadFile = uploadFile.concat(fileHelpers.fileHeader(coverageFile))
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/coverage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An example coverage root file
1 change: 1 addition & 0 deletions test/fixtures/other/coverage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An example coverage other file
27 changes: 27 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,31 @@ describe('Uploader Core', function () {
})
expect(result).toEqual({ status: 'success', resultURL: 'https://results.codecov.io' })
}, 30000)

it('Can find all coverage from root dir', async function () {
jest.spyOn(process, 'exit').mockImplementation(() => {})
const log = jest.spyOn(console, 'log')
await app.main({
name: 'customname',
token: 'abcdefg',
url: 'https://codecov.io',
dryRun: true,
})
expect(log).toHaveBeenCalledWith(expect.stringMatching(/An example coverage root file/))
expect(log).toHaveBeenCalledWith(expect.stringMatching(/An example coverage other file/))
})

it('Can find only coverage from custom dir', async function () {
jest.spyOn(process, 'exit').mockImplementation(() => {})
const log = jest.spyOn(console, 'log')
await app.main({
name: 'customname',
token: 'abcdefg',
url: 'https://codecov.io',
dryRun: true,
dir: './test/fixtures/other'
})
expect(log).toHaveBeenCalledWith(expect.stringMatching(/An example coverage other file/))
expect(log).not.toHaveBeenCalledWith(expect.stringMatching(/An example coverage root file/))
})
})

0 comments on commit 8be63a6

Please sign in to comment.