Skip to content

Commit

Permalink
Add feature toggle param (#108)
Browse files Browse the repository at this point in the history
feat: add feature toggle param
  • Loading branch information
eddiemoore authored Jun 1, 2021
1 parent 3901770 commit 5e3fff9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
6 changes: 6 additions & 0 deletions bin/codecov
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ var argv = require("yargs") // eslint-disable-line
type: "string",
description: "Change the upload host (Enterprise use)",
default: "https://codecov.io"
},
feature: {
alias: 'X',
type: "string",
description: `Toggle functionalities
-X network Disable uploading the file network`
}
})
.version()
Expand Down
14 changes: 9 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function dryRun (uploadHost, token, query, uploadFile, args, start) {
* @param {boolean} args.dryRun Don't upload files to Codecov
* @param {string} args.slug Specify the slug manually (Enterprise use)
* @param {string} args.url Change the upload host (Enterprise use)
* @param {string} args.feature Toggle features
*/
async function main (args) {
const start = Date.now()
Expand Down Expand Up @@ -90,8 +91,14 @@ async function main (args) {
log(`=> Project root located at: ${projectRoot}`)

// == Step 3: get network
log('Start of network processing...', { level: 'debug', args })
const fileListing = await fileHelpers.getFileListing(projectRoot, args)
let uploadFile = ''

if (!args.feature || args.feature.split(',').includes('network') === false) {
log('Start of network processing...', { level: 'debug', args })
const fileListing = await fileHelpers.getFileListing(projectRoot, args)

uploadFile = uploadFile.concat(fileListing).concat(fileHelpers.endNetworkMarker())
}

// == Step 4: select coverage files (search or specify)

Expand Down Expand Up @@ -127,9 +134,6 @@ async function main (args) {

// == Step 5: generate upload file
// TODO: capture envs
let uploadFile = fileListing

uploadFile = uploadFile.concat(fileHelpers.endNetworkMarker())

// Get coverage report contents
for (let index = 0; index < coverageFilePaths.length; index++) {
Expand Down
25 changes: 25 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,29 @@ describe('Uploader Core', function () {
expect(log).toHaveBeenCalledWith(expect.stringMatching(/An example coverage other file/))
expect(log).not.toHaveBeenCalledWith(expect.stringMatching(/An example coverage root file/))
})

it('Can include the network', async function () {
jest.spyOn(process, 'exit').mockImplementation(() => {})
const log = jest.spyOn(console, 'log').mockImplementation(() => {})
await app.main({
name: 'customname',
token: 'abcdefg',
url: 'https://codecov.io',
dryRun: true,
})
expect(log).toHaveBeenCalledWith(expect.stringMatching(/<<<<<< network/))
})

it('Can ignore the network', async function () {
jest.spyOn(process, 'exit').mockImplementation(() => {})
const log = jest.spyOn(console, 'log').mockImplementation(() => {})
await app.main({
name: 'customname',
token: 'abcdefg',
url: 'https://codecov.io',
dryRun: true,
feature: 'network'
})
expect(log).not.toHaveBeenCalledWith(expect.stringMatching(/<<<<<< network/))
})
})

0 comments on commit 5e3fff9

Please sign in to comment.