Skip to content

Commit

Permalink
refactor: Refactor tests and add provider test template
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu committed Jun 9, 2021
1 parent b238723 commit c723ad7
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 111 deletions.
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
2. Collect the needed enviromental variables for each section (you can use provider_circleci.js if you get confused)
3. Copy provider_template.js and fill it in.
4. Add your new providers list in https://github.com/codecov/uploader/blob/master/src/ci_providers/index.js
5. Open a PR and we'll take a look!
5. Copy test/providers/provider_template.test.js and fill it in.
6. Ensure 100% code coverage on the new provider code.
7. Open a PR and we'll take a look!
2 changes: 1 addition & 1 deletion src/ci_providers/provider_gitlabci.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { parseSlugFromRemoteAddr } = require('../helpers/parseSlug')
const { parseSlugFromRemoteAddr } = require('../helpers/git')

function detect (envs) {
return envs.GITLAB_CI
Expand Down
2 changes: 1 addition & 1 deletion src/ci_providers/provider_local.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const childprocess = require('child_process')
const { parseSlug } = require('../helpers/parseSlug')
const { parseSlug } = require('../helpers/git')

function detect (envs) {
return !envs.CI
Expand Down
1 change: 0 additions & 1 deletion src/helpers/parseSlug.js → src/helpers/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var childProcess = require('child_process')

function parseSlug (slug) {
// origin https://github.com/torvalds/linux.git (fetch)

// git@github.com: codecov / uploader.git
if (typeof slug != 'string') {
return ''
Expand Down
33 changes: 3 additions & 30 deletions test/providers/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,9 @@ describe('CI Providers', () => {

it('is an array of CI providers', () => expect(providers).toBeInstanceOf(Array))
providers.forEach(provider => {
const inputs = {
args: {},
envs: {
CI: true,
CI_PROJECT_PATH: 'testOrg/testRepo',
CIRCLE_PROJECT_REPONAME: 'testRepo',
CIRCLE_PROJECT_USERNAME: 'testOrg',
CIRCLE_SHA1: 'testingSHA',
GITHUB_ACTIONS: true,
GITHUB_REF: 'refs/heads/test',
GITHUB_REPOSITORY: 'testOrg/testRepo',
GITLAB_CI: true,
JENKINS_URL: 'https://example.com',
SHIPPABLE: true,
SYSTEM_TEAMFOUNDATIONSERVERURI: 'https://example.azure.com',
TRAVIS: true,
TRAVIS_REPO_SLUG: 'testOrg/testRepo',
}
}
describe(`${provider.getServiceName() || ''}`, () => {
it('has a detect() method', () => {
expect(provider.detect).toBeInstanceOf(Function)
})
it('has all properties set', () => {
props = ['branch', 'build', 'buildURL', 'commit', 'job', 'pr', 'service', 'slug']
const serviceParams = provider.getServiceParams(inputs)
for (const prop of props) {
expect(serviceParams).toHaveProperty(prop)
}
})
it('has a service name', () => {
expect(typeof provider.getServiceName()).toBe('string')
expect(provider.getServiceName()).not.toBe('')
})
})
})
76 changes: 56 additions & 20 deletions test/providers/provider_appveyorci.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,66 @@ describe('AppveyorCI Params', () => {
td.reset()
})

it('does not run without AppveyorCI env variable', () => {
const inputs = {
args: {},
envs: {}
}
let detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeFalsy()
describe('detect()', () => {
it('does not run without AppveyorCI env variable', () => {
const inputs = {
args: {},
envs: {}
}
let detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeFalsy()

inputs.envs['CI'] = 'true'
detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeFalsy()

inputs.envs['CI'] = 'true'
detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeFalsy()
inputs.envs['CI'] = 'True'
detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeFalsy()

inputs.envs['CI'] = 'True'
detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeFalsy()
inputs.envs['CI'] = 'false'
inputs.envs['APPVEYOR'] = 'true'
detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeFalsy()

inputs.envs['CI'] = 'false'
inputs.envs['APPVEYOR'] = 'true'
detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeFalsy()
inputs.envs['APPVEYOR'] = 'True'
detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeFalsy()
})

inputs.envs['APPVEYOR'] = 'True'
detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeFalsy()
it('does run with AppveyorCI env variable', () => {
const inputs = {
args: {},
envs: {
'CI': 'true',
'APPVEYOR': 'true',
}
}
const detected = providerAppveyorci.detect(inputs.envs)
expect(detected).toBeTruthy()
})
})

it('gets the correct params on no env variables', () => {
const inputs = {
args: {},
envs: {
'CI': 'true',
'APPVEYOR': 'true',
},
}
const expected = {
branch: '',
build: '',
buildURL: '',
commit: '',
job: '',
pr: '',
service: '',
slug: ''
}
const params = providerAppveyorci.getServiceParams(inputs)
expect(expected).toBeTruthy()
})

it('gets correct params on push', () => {
Expand Down
42 changes: 38 additions & 4 deletions test/providers/provider_azurepipelines.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,47 @@ describe('Jenkins CI Params', () => {
td.reset()
})

it('does not run without AzurePipelines env variable', () => {
describe('detect()', () => {
it('does not run without AzurePipelines env variable', () => {
const inputs = {
args: {},
envs: {}
}
const detected = providerAzurepipelines.detect(inputs.envs)
expect(detected).toBeFalsy()
})

it('does run with AzurePipelines env variable', () => {
const inputs = {
args: {},
envs: {
SYSTEM_TEAMFOUNDATIONSERVERURI: 'true'
}
}
const detected = providerAzurepipelines.detect(inputs.envs)
expect(detected).toBeTruthy()
})
})

it('gets the correct params on no env variables', () => {
const inputs = {
args: {},
envs: {}
envs: {
SYSTEM_TEAMFOUNDATIONSERVERURI: 'true'
},
}
detected = providerAzurepipelines.detect(inputs.envs)
expect(detected).toBeFalsy()
const expected = {
branch: '',
build: '',
buildURL: '',
commit: '',
job: '',
pr: '',
service: '',
slug: ''
}
const params = providerAzurepipelines.getServiceParams(inputs)
expect(expected).toBeTruthy()
})

it('gets correct params on pr number', () => {
Expand Down
28 changes: 21 additions & 7 deletions test/providers/provider_circleci.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@ describe('CircleCI Params', () => {
td.reset()
})

it('does not run without CircleCI env variable', () => {
const inputs = {
args: {},
envs: {}
}
const detected = providerCircleci.detect(inputs.envs)
expect(detected).toBeFalsy()
describe('detect()', () => {
it('does not run without CircleCI env variable', () => {
const inputs = {
args: {},
envs: {}
}
const detected = providerCircleci.detect(inputs.envs)
expect(detected).toBeFalsy()
})

it('does run with CircleCI env variable', () => {
const inputs = {
args: {},
envs: {
CI: true,
CIRCLECI: true,
},
}
const detected = providerCircleci.detect(inputs.envs)
expect(detected).toBeTruthy()
})
})

it('gets correct params', () => {
Expand Down
54 changes: 44 additions & 10 deletions test/providers/provider_githubactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,54 @@ describe('GitHub Actions Params', () => {
td.reset()
})

it('does not run without GitHub Actions env variable', () => {
describe('detect()', () => {
it('does not run without GitHub Actions env variable', () => {
const inputs = {
args: {},
envs: {
GITHUB_ACTIONS: false,
GITHUB_REF: 'refs/heads/master',
GITHUB_REPOSITORY: 'testOrg/testRepo',
GITHUB_RUN_ID: 2,
GITHUB_SHA: 'testingsha',
GITHUB_WORKFLOW: 'testWorkflow',
}
}
const detected = providerGitHubactions.detect(inputs.envs)
expect(detected).toBeFalsy()
})

it('does not with GitHub Actions env variable', () => {
const inputs = {
args: {},
envs: {
GITHUB_ACTIONS: true,
},
}
const detected = providerGitHubactions.detect(inputs.envs)
expect(detected).toBeTruthy()
})
})

it('gets the correct params on no env variables', () => {
const inputs = {
args: {},
envs: {
GITHUB_ACTIONS: false,
GITHUB_REF: 'refs/heads/master',
GITHUB_REPOSITORY: 'testOrg/testRepo',
GITHUB_RUN_ID: 2,
GITHUB_SHA: 'testingsha',
GITHUB_WORKFLOW: 'testWorkflow',
}
GITHUB_ACTIONS: true,
},
}
const detected = providerGitHubactions.detect(inputs.envs)
expect(detected).toBeFalsy()
const expected = {
branch: '',
build: '',
buildURL: '',
commit: '',
job: '',
pr: '',
service: '',
slug: ''
}
const params = providerGitHubactions.getServiceParams(inputs)
expect(expected).toBeTruthy()
})

it('gets correct params for a push event', () => {
Expand Down
27 changes: 20 additions & 7 deletions test/providers/provider_gitlabci.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ describe('GitLabCI Params', () => {
td.reset()
})

it('does not run without GitLabCI env variable', () => {
const inputs = {
args: {},
envs: {}
}
const detected = providerGitLabci.detect(inputs.envs)
expect(detected).toBeFalsy()
describe('detect()', () => {
it('does not run without GitLabCI env variable', () => {
const inputs = {
args: {},
envs: {}
}
const detected = providerGitLabci.detect(inputs.envs)
expect(detected).toBeFalsy()
})

it('does run with GitLabCI env variable', () => {
const inputs = {
args: {},
envs: {
GITLAB_CI: true,
},
}
const detected = providerGitLabci.detect(inputs.envs)
expect(detected).toBeTruthy()
})
})

it('gets correct empty params', () => {
Expand Down
Loading

0 comments on commit c723ad7

Please sign in to comment.