Skip to content

Commit 8be63a6

Browse files
authored
Coverage directory -s (#89)
* coverage directory * fix tests
1 parent 71b2d37 commit 8be63a6

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

bin/codecov

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ var argv = require("yargs") // eslint-disable-line
4343
alias: "P",
4444
description: "Specify the pull request number mannually"
4545
},
46+
dir: {
47+
alias: "s",
48+
description: "Directory to search for coverage reports.\nAlready searches project root and current working directory"
49+
},
4650
token: {
4751
alias: "t",
4852
default: "",

src/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function dryRun (uploadHost, token, query, uploadFile) {
1919
* @param {Object} args
2020
* @param {string} args.build Specify the build number manually
2121
* @param {string} args.branch Specify the branch manually
22+
* @param {string} args.dir Directory to search for coverage reports.
2223
* @param {string} args.env Specify environment variables to be included with this build
2324
* @param {string} args.sha Specify the commit SHA mannually
2425
* @param {string} args.file Target file(s) to upload
@@ -82,7 +83,7 @@ async function main (args) {
8283
let coverageFilePaths = []
8384
if (!args.file) {
8485
coverageFilePaths = fileHelpers.getCoverageFiles(
85-
projectRoot,
86+
args.dir || projectRoot,
8687
// TODO: Determine why this is so slow (I suspect it's walking paths it should not)
8788
fileHelpers.coverageFilePatterns()
8889
)
@@ -117,7 +118,7 @@ async function main (args) {
117118
for (let index = 0; index < coverageFilePaths.length; index++) {
118119
const coverageFile = coverageFilePaths[index]
119120
const fileContents = await fileHelpers.readCoverageFile(
120-
'.',
121+
args.dir || projectRoot,
121122
coverageFile
122123
)
123124
uploadFile = uploadFile.concat(fileHelpers.fileHeader(coverageFile))

test/fixtures/coverage.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
An example coverage root file

test/fixtures/other/coverage.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
An example coverage other file

test/index.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,31 @@ describe('Uploader Core', function () {
109109
})
110110
expect(result).toEqual({ status: 'success', resultURL: 'https://results.codecov.io' })
111111
}, 30000)
112+
113+
it('Can find all coverage from root dir', async function () {
114+
jest.spyOn(process, 'exit').mockImplementation(() => {})
115+
const log = jest.spyOn(console, 'log')
116+
await app.main({
117+
name: 'customname',
118+
token: 'abcdefg',
119+
url: 'https://codecov.io',
120+
dryRun: true,
121+
})
122+
expect(log).toHaveBeenCalledWith(expect.stringMatching(/An example coverage root file/))
123+
expect(log).toHaveBeenCalledWith(expect.stringMatching(/An example coverage other file/))
124+
})
125+
126+
it('Can find only coverage from custom dir', async function () {
127+
jest.spyOn(process, 'exit').mockImplementation(() => {})
128+
const log = jest.spyOn(console, 'log')
129+
await app.main({
130+
name: 'customname',
131+
token: 'abcdefg',
132+
url: 'https://codecov.io',
133+
dryRun: true,
134+
dir: './test/fixtures/other'
135+
})
136+
expect(log).toHaveBeenCalledWith(expect.stringMatching(/An example coverage other file/))
137+
expect(log).not.toHaveBeenCalledWith(expect.stringMatching(/An example coverage root file/))
138+
})
112139
})

0 commit comments

Comments
 (0)