-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from codecov/circleci-tests
test: Add CircleCI tests and refactor testing
- Loading branch information
Showing
7 changed files
with
111 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,59 +25,14 @@ describe('CI Providers', () => { | |
it('has a detect() method', () => { | ||
expect(provider.detect).toBeInstanceOf(Function) | ||
}) | ||
it('has a getService() method', () => { | ||
expect(provider.private._getService).toBeInstanceOf(Function) | ||
}) | ||
it('has a getServiceName() method', () => { | ||
expect(provider.getServiceName).toBeInstanceOf(Function) | ||
}) | ||
it('has a getServiceParams() method', () => { | ||
expect(provider.getServiceParams).toBeInstanceOf(Function) | ||
}) | ||
describe('getServiceParams()', () => { | ||
it('has all properties set', () => { | ||
props = ['branch', 'build', 'buildURL', 'commit', 'job', 'pr', 'service', 'slug'] | ||
const serviceParams = provider.getServiceParams(inputs) | ||
it("has it's branch property set", () => { | ||
expect(serviceParams.branch).toBe( | ||
provider.private._getBranch(inputs) | ||
) | ||
}) | ||
it("has it's build property set", () => { | ||
expect(serviceParams.build).toBe( | ||
provider.private._getBuild(inputs) | ||
) | ||
}) | ||
it("has it's buildURL property set", () => { | ||
expect(serviceParams.buildURL).toBe( | ||
provider.private._getBuildURL(inputs) | ||
) | ||
}) | ||
it("has it's commit property set", () => { | ||
expect(serviceParams.commit).toBe( | ||
provider.private._getSHA(inputs) | ||
) | ||
}) | ||
it("has it's job property set", () => { | ||
expect(serviceParams.job).toBe( | ||
provider.private._getJob(inputs.envs) | ||
) | ||
}) | ||
it("has it's pr property set", () => { | ||
expect(serviceParams.pr).toBe(provider.private._getPR(inputs)) | ||
}) | ||
it("has it's service property set", () => { | ||
expect(serviceParams.service).toBe( | ||
provider.private._getService(inputs) | ||
) | ||
}) | ||
it("has it's slug property set", () => { | ||
expect(serviceParams.slug).toBe( | ||
provider.private._getSlug(inputs) | ||
) | ||
}) | ||
}) | ||
it('has a getSlug() method', () => { | ||
expect(provider.private._getSlug).toBeInstanceOf(Function) | ||
for (const prop of props) { | ||
expect(serviceParams).toHaveProperty(prop) | ||
} | ||
}) | ||
|
||
describe('getSlug()', () => { | ||
it('can get the slug from a git url', () => { | ||
const spawnSync = td.replace(childProcess, 'spawnSync') | ||
|
@@ -87,7 +42,18 @@ describe('CI Providers', () => { | |
'remote.origin.url'])).thenReturn({ | ||
stdout: '[email protected]:testOrg/testRepo.git' | ||
}) | ||
expect(provider.private._getSlug(inputs)).toBe( | ||
td.when(spawnSync('git', [ | ||
'rev-parse', | ||
'--abbrev-ref', | ||
'HEAD'])).thenReturn({ | ||
stdout: 'main' | ||
}) | ||
td.when(spawnSync('git', [ | ||
'rev-parse', | ||
'HEAD'])).thenReturn({ | ||
stdout: 'testSHA' | ||
}) | ||
expect(provider.getServiceParams(inputs).slug).toBe( | ||
'testOrg/testRepo' | ||
) | ||
}) | ||
|
@@ -99,7 +65,18 @@ describe('CI Providers', () => { | |
'remote.origin.url'])).thenReturn({ | ||
stdout: 'http://github.com/testOrg/testRepo.git' | ||
}) | ||
expect(provider.private._getSlug(inputs)).toEqual( | ||
td.when(spawnSync('git', [ | ||
'rev-parse', | ||
'--abbrev-ref', | ||
'HEAD'])).thenReturn({ | ||
stdout: 'main' | ||
}) | ||
td.when(spawnSync('git', [ | ||
'rev-parse', | ||
'HEAD'])).thenReturn({ | ||
stdout: 'testSHA' | ||
}) | ||
expect(provider.getServiceParams(inputs).slug).toBe( | ||
'testOrg/testRepo' | ||
) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const td = require('testdouble') | ||
const childProcess = require('child_process') | ||
|
||
const providerCircleci = require('../../src/ci_providers//provider_circleci') | ||
|
||
describe('CircleCI Params', () => { | ||
afterEach(function () { | ||
td.reset() | ||
}) | ||
|
||
it('does not run without CircleCI env variable', () => { | ||
const inputs = { | ||
args: {}, | ||
envs: {} | ||
} | ||
const detected = providerCircleci.detect(inputs.envs) | ||
expect(detected).toBeFalsy() | ||
}) | ||
|
||
it('gets correct params', () => { | ||
const inputs = { | ||
args: {}, | ||
envs: { | ||
CI: true, | ||
CIRCLECI: true, | ||
CIRCLE_BRANCH: 'master', | ||
CIRCLE_SHA1: 'testingsha', | ||
CIRCLE_PROJECT_REPONAME: 'testRepo', | ||
CIRCLE_PROJECT_USERNAME: 'testOrg', | ||
CIRCLE_REPOSITORY_URL: '[email protected]:testOrg/testRepo.git', | ||
CIRCLE_BUILD_NUM: 2, | ||
CIRCLE_PR_NUMBER: 1, | ||
CIRCLE_NODE_INDEX: 3 | ||
} | ||
} | ||
const expected = { | ||
branch: 'master', | ||
build: 2 , | ||
buildURL: '', | ||
commit: 'testingsha', | ||
job: 3, | ||
pr: 1, | ||
service: 'circleci', | ||
slug: 'testOrg/testRepo' | ||
} | ||
const params = providerCircleci.getServiceParams(inputs) | ||
expect(params).toMatchObject(expected) | ||
}) | ||
|
||
it('gets correct slug when empty reponame', () => { | ||
const inputs = { | ||
args: {}, | ||
envs: { | ||
CI: true, | ||
CIRCLECI: true, | ||
CIRCLE_BRANCH: 'master', | ||
CIRCLE_SHA1: 'testingsha', | ||
CIRCLE_PROJECT_REPONAME: '', | ||
CIRCLE_REPOSITORY_URL: '[email protected]:testOrg/testRepo.git', | ||
CIRCLE_BUILD_NUM: 2, | ||
CIRCLE_PR_NUMBER: 1, | ||
CIRCLE_NODE_INDEX: 3 | ||
} | ||
} | ||
const expected = { | ||
branch: 'master', | ||
build: 2 , | ||
buildURL: '', | ||
commit: 'testingsha', | ||
job: 3, | ||
pr: 1, | ||
service: 'circleci', | ||
slug: 'testOrg/testRepo' | ||
} | ||
const params = providerCircleci.getServiceParams(inputs) | ||
expect(params).toMatchObject(expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters