Skip to content

Commit

Permalink
Allow flags with dash (#88)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Becher <[email protected]>
  • Loading branch information
eddiemoore and drazisil-codecov authored May 10, 2021
1 parent 635cb4d commit 57eb95b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/helpers/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function validateURL (url) {
}

function validateFlags (flags) {
const mask = /^[\w,]+$/
const mask = /^(?!-)[\w,-]+$/
return mask.test(flags)
}

Expand Down
12 changes: 10 additions & 2 deletions test/helpers/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ describe('Input Validators', function () {
})

describe('Flags', function () {
it('Should fail with a dash', function () {
expect(validate.validateFlags('moo-foor')).toBe(false)

it('Should pass without a dash', function () {
expect(validate.validateFlags('moo')).toBe(true)
})
it('Should pass with a dash', function () {
expect(validate.validateFlags('moo-foor')).toBe(true)
})

it('Should fail with a dash at the start', function () {
expect(validate.validateFlags('-moo-foor')).toBe(false)
})
})

Expand Down
22 changes: 22 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ describe('Uploader Core', function () {
expect(result).toEqual({ status: 'success', resultURL: 'https://results.codecov.io' })
}, 30000)

describe('Flags', () => {
it('can upload with flags', async () => {
process.env.CI = 'true'
process.env.CIRCLECI = 'true'

nock('https://codecov.io')
.post('/upload/v4')
.query(actualQueryObject => actualQueryObject.flags === 'a-flag')
.reply(200, 'https://results.codecov.io\nhttps://codecov.io')

nock('https://codecov.io')
.put('/')
.reply(200, 'success')

const result = await app.main({
flags: 'a-flag',
token: 'abcdefg',
url: 'https://codecov.io'
})
expect(result).toEqual({ status: 'success', resultURL: 'https://results.codecov.io' })
}, 30000)
})
it('Can upload with parent sha', async function () {
process.env.CI = 'true'
process.env.CIRCLECI = 'true'
Expand Down

0 comments on commit 57eb95b

Please sign in to comment.