Skip to content

Commit 4bb0f23

Browse files
committed
Add tests
1 parent a231eef commit 4bb0f23

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

src/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ async function main(args) {
105105
// Look for files
106106
let coverageFilePaths = []
107107
if (!args.file) {
108+
log('Searching for coverage files...')
108109
coverageFilePaths = fileHelpers.getCoverageFiles(
109110
args.dir || projectRoot,
110111
// TODO: Determine why this is so slow (I suspect it's walking paths it should not)
@@ -119,15 +120,15 @@ async function main(args) {
119120
)
120121
}
121122
} else {
122-
if (typeof(args.file) === 'object') {
123-
for (const file of args.file) {
124-
coverageFilePaths.push(validateHelpers.validateFileNamePath(file) ? file : '')
125-
}
123+
if (typeof(args.file) === 'string') {
124+
coverageFilePaths = [args.file]
126125
} else {
127-
coverageFilePaths[0] = validateHelpers.validateFileNamePath(args.file)
128-
? args.file
129-
: ''
126+
coverageFilePaths = args.file
130127
}
128+
129+
coverageFilePaths.filter((file) => {
130+
return validateHelpers.validateFileNamePath(file);
131+
})
131132
if (coverageFilePaths.length === 0) {
132133
throw new Error('Not coverage file found, exiting.')
133134
}
@@ -141,12 +142,14 @@ async function main(args) {
141142
for (const coverageFile of coverageFilePaths) {
142143
let fileContents
143144
try {
145+
log(`Processing ${coverageFile}...`),
144146
fileContents = await fileHelpers.readCoverageFile(
145147
args.dir || projectRoot,
146148
coverageFile,
147149
)
148150
} catch (error) {
149-
throw new Error(`Error reading coverage file (${coverageFile}): ${error}`)
151+
log(`Could not read coverage file (${coverageFile}): ${error}`)
152+
continue;
150153
}
151154

152155
uploadFile = uploadFile

test/index.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,45 @@ describe('Uploader Core', () => {
133133
)
134134
})
135135

136+
it('Can find a single specified file', async () => {
137+
jest.spyOn(process, 'exit').mockImplementation(() => {})
138+
const log = jest.spyOn(console, 'log').mockImplementation(() => {})
139+
await app.main({
140+
dryRun: true,
141+
file: 'test/fixtures/coverage.txt',
142+
name: 'customname',
143+
token: 'abcdefg',
144+
url: 'https://codecov.io',
145+
})
146+
expect(log).toHaveBeenCalledWith(
147+
expect.stringMatching("Processing test/fixtures/coverage.txt..."),
148+
)
149+
})
150+
151+
it('Can find multiple specified files', async () => {
152+
jest.spyOn(process, 'exit').mockImplementation(() => {})
153+
const log = jest.spyOn(console, 'log').mockImplementation(() => {})
154+
await app.main({
155+
dryRun: true,
156+
file: ['test/fixtures/coverage.txt', 'test/fixtures/other/coverage.txt', 'test/does/not/exist.txt'],
157+
name: 'customname',
158+
token: 'abcdefg',
159+
url: 'https://codecov.io',
160+
})
161+
expect(log).toHaveBeenCalledWith(
162+
expect.stringMatching("Processing test/fixtures/coverage.txt..."),
163+
)
164+
expect(log).toHaveBeenCalledWith(
165+
expect.stringMatching("Processing test/fixtures/coverage.txt..."),
166+
)
167+
expect(log).toHaveBeenCalledWith(
168+
expect.stringMatching("Processing test/does/not/exist.txt..."),
169+
)
170+
expect(log).toHaveBeenCalledWith(
171+
expect.stringContaining("Could not read coverage file (test/does/not/exist.txt):"),
172+
)
173+
})
174+
136175
it('Can find only coverage from custom dir', async () => {
137176
jest.spyOn(process, 'exit').mockImplementation(() => {})
138177
const log = jest.spyOn(console, 'log').mockImplementation(() => {})

0 commit comments

Comments
 (0)