diff --git a/src/helpers/validate.js b/src/helpers/validate.js index c19cd752c..89e5db677 100644 --- a/src/helpers/validate.js +++ b/src/helpers/validate.js @@ -9,7 +9,7 @@ function validateURL (url) { } function validateFlags (flags) { - const mask = /^[\w,]+$/ + const mask = /^(?!-)[\w,-]+$/ return mask.test(flags) } diff --git a/test/helpers/validate.test.js b/test/helpers/validate.test.js index ef3e4ae40..72c41d15e 100644 --- a/test/helpers/validate.test.js +++ b/test/helpers/validate.test.js @@ -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) }) }) diff --git a/test/index.test.js b/test/index.test.js index 082e26757..d523060ef 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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'