Improve code quality and write tests

This commit is contained in:
Shivam Mathur
2019-09-20 08:11:20 +05:30
parent db44db4b97
commit 43178a7254
3597 changed files with 255478 additions and 785554 deletions

29
node_modules/codecov/test/services/appveyor.test.js generated vendored Normal file
View File

@ -0,0 +1,29 @@
var appveyor = require('../../lib/services/appveyor')
describe('AppVeyor CI Provider', function() {
it('can detect appveyor', function() {
process.env.APPVEYOR = 'true'
expect(appveyor.detect()).toBe(true)
})
it('can get appveyor env info', function() {
process.env.APPVEYOR_ACCOUNT_NAME = 'a'
process.env.APPVEYOR_PROJECT_SLUG = 'b'
process.env.APPVEYOR_REPO_COMMIT = '5678'
process.env.APPVEYOR_REPO_BRANCH = 'master'
process.env.APPVEYOR_PULL_REQUEST_NUMBER = '1'
process.env.APPVEYOR_BUILD_VERSION = 'job'
process.env.APPVEYOR_JOB_ID = 'build'
process.env.APPVEYOR_REPO_NAME = 'owner/repo'
expect(appveyor.configuration()).toEqual({
service: 'appveyor',
commit: '5678',
build: 'build',
job: 'a/b/job',
pr: '1',
branch: 'master',
slug: 'owner/repo',
})
})
})

View File

@ -0,0 +1,31 @@
var azurePipelines = require('../../lib/services/azurePipelines')
describe('Azure Pipelines CI Provider', function() {
it('can detect azure pipelines', function() {
process.env.TF_BUILD = '1'
expect(azurePipelines.detect()).toBe(true)
})
it('can get azure pipelines env info', function() {
process.env.BUILD_SOURCEBRANCH = 'master'
process.env.SYSTEM_JOBID = '92a2fa25-f940-5df6-a185-81eb9ae2031d'
process.env.BUILD_BUILDID = '1'
process.env.SYSTEM_TEAMFOUNDATIONSERVERURI =
'https://dev.azure.com/codecov/'
process.env.SYSTEM_TEAMPROJECT = 'repo'
process.env.BUILD_SOURCEVERSION = '743b04806ea677403aa2ff26c6bdeb85005de658'
process.env.BUILD_REPOSITORY_ID = 'owner/repo'
process.env.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER = '1234'
expect(azurePipelines.configuration()).toEqual({
service: 'azure_pipelines',
build: '1',
build_url: 'https://dev.azure.com/codecov/repo/_build/results?buildId=1',
job: '92a2fa25-f940-5df6-a185-81eb9ae2031d',
commit: '743b04806ea677403aa2ff26c6bdeb85005de658',
pr: '1234',
branch: 'master',
slug: 'owner/repo',
})
})
})

25
node_modules/codecov/test/services/buildkite.test.js generated vendored Normal file
View File

@ -0,0 +1,25 @@
var buildkite = require('../../lib/services/buildkite')
describe('Buildkite CI Provider', function() {
it('can detect buildkite', function() {
process.env.BUILDKITE = 'true'
expect(buildkite.detect()).toBe(true)
})
it('can get buildkite env info', function() {
process.env.BUILDKITE_BUILD_NUMBER = '1'
process.env.BUILDKITE_BUILD_URL = 'url'
process.env.BUILDKITE_COMMIT = 'commit'
process.env.BUILDKITE_BRANCH = 'branch'
process.env.BUILDKITE_PROJECT_SLUG = 'slug'
expect(buildkite.configuration()).toEqual({
service: 'buildkite',
build: '1',
build_url: 'url',
commit: 'commit',
branch: 'branch',
slug: 'slug',
})
})
})

63
node_modules/codecov/test/services/circle.test.js generated vendored Normal file
View File

@ -0,0 +1,63 @@
var circle = require('../../lib/services/circle')
describe('Circle CI Provider', function() {
it('can detect circle', function() {
process.env.CIRCLECI = 'true'
expect(circle.detect()).toBe(true)
})
it('can get circle env info (CircleCI 1.0)', function() {
process.env.CIRCLECI = 'true'
process.env.CIRCLE_BUILD_NUM = '1234'
process.env.CIRCLE_SHA1 = '5678'
process.env.CIRCLE_BRANCH = 'master'
process.env.CIRCLE_NODE_INDEX = '1'
process.env.CIRCLE_PR_NUMBER = 'blah'
process.env.CIRCLE_PROJECT_USERNAME = 'owner'
process.env.CIRCLE_PROJECT_REPONAME = 'repo'
expect(circle.configuration()).toEqual({
service: 'circleci',
commit: '5678',
build: '1234.1',
job: '1234.1',
branch: 'master',
pr: 'blah',
slug: 'owner/repo',
})
})
it('can get circle env info (CircleCI 2.0)', function() {
process.env.CIRCLECI = 'true'
process.env.CIRCLE_BRANCH = 'master'
process.env.CIRCLE_BUILD_NUM = '1234'
process.env.CIRCLE_SHA1 = 'abcd'
process.env.CIRCLE_NODE_INDEX = '1'
process.env.CIRCLE_BUILD_URL = 'https://circleci.com/gh/owner/repo/1234'
process.env.CIRCLE_COMPARE_URL =
'https://github.com/owner/repo/2408ca9...3c36cfa'
process.env.CIRCLE_NODE_INDEX = '1'
process.env.CIRCLE_REPOSITORY_URL = 'git@github.com:owner/repo.git'
delete process.env.CIRCLE_PR_NUMBER
delete process.env.CIRCLE_PROJECT_USERNAME
delete process.env.CIRCLE_PROJECT_REPONAME
expect(circle.configuration()).toEqual({
service: 'circleci',
commit: 'abcd',
build: '1234.1',
job: '1234.1',
branch: 'master',
pr: undefined,
slug: 'owner/repo',
})
})
it('throws if repo slug cannot be detected', function() {
delete process.env.CIRCLE_PR_NUMBER
delete process.env.CIRCLE_PROJECT_USERNAME
delete process.env.CIRCLE_PROJECT_REPONAME
delete process.env.CIRCLE_REPOSITORY_URL
expect(function() {
circle.configuration()
}).toThrow()
})
})

27
node_modules/codecov/test/services/cirrus.test.js generated vendored Normal file
View File

@ -0,0 +1,27 @@
var cirrus = require('../../lib/services/cirrus')
describe('Cirrus CI Provider', function() {
it('can detect cirrus', function() {
process.env.CIRRUS_CI = 'true'
expect(cirrus.detect()).toBe(true)
})
it('can get cirrus env info', function() {
process.env.CIRRUS_CI = 'true'
process.env.CIRRUS_BUILD_ID = '1234.1'
process.env.CIRRUS_CHANGE_IN_REPO = '5678'
process.env.CIRRUS_BRANCH = 'master'
process.env.CIRRUS_TASK_ID = '1234.1'
process.env.CIRRUS_PR = 'blah'
process.env.CIRRUS_REPO_FULL_NAME = 'owner/repo'
expect(cirrus.configuration()).toEqual({
service: 'cirrusci',
commit: '5678',
build: '1234.1',
job: '1234.1',
branch: 'master',
pr: 'blah',
slug: 'owner/repo',
})
})
})

53
node_modules/codecov/test/services/codebuild.test.js generated vendored Normal file
View File

@ -0,0 +1,53 @@
var codebuild = require('../../lib/services/codebuild')
describe('AWS CodeBuild Provider', function() {
it('can detect codebuild', function() {
process.env.CODEBUILD_CI = 'true'
expect(codebuild.detect()).toBe(true)
})
it('can get codebuild env info', function() {
process.env.CODEBUILD_CI = 'true'
process.env.CODEBUILD_BUILD_ID =
'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969'
process.env.CODEBUILD_RESOLVED_SOURCE_VERSION =
'39ec2418eca4c539d765574a1c68f3bd77e8c549'
process.env.CODEBUILD_WEBHOOK_HEAD_REF = 'refs/heads/master'
process.env.CODEBUILD_SOURCE_VERSION = 'pr/1'
process.env.CODEBUILD_SOURCE_REPO_URL =
'https://github.com/my-org/my-project.git'
expect(codebuild.configuration()).toEqual({
service: 'codebuild',
build: 'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969',
job: 'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969',
commit: '39ec2418eca4c539d765574a1c68f3bd77e8c549',
branch: 'master',
pr: '1',
slug: 'my-org/my-project',
})
})
it('throws if branch name cannot be detected', function() {
delete process.env.CODEBUILD_WEBHOOK_HEAD_REF
expect(function() {
codebuild.configuration()
}).toThrow()
})
it('throws if pr number cannot be detected', function() {
process.env.CODEBUILD_WEBHOOK_HEAD_REF = 'refs/heads/master'
delete process.env.CODEBUILD_SOURCE_VERSION
expect(function() {
codebuild.configuration()
}).toThrow()
})
it('throws if slug cannot be detected', function() {
process.env.CODEBUILD_RESOLVED_SOURCE_VERSION =
'39ec2418eca4c539d765574a1c68f3bd77e8c549'
delete process.env.CODEBUILD_SOURCE_REPO_URL
expect(function() {
codebuild.configuration()
}).toThrow()
})
})

23
node_modules/codecov/test/services/codeship.test.js generated vendored Normal file
View File

@ -0,0 +1,23 @@
var codeship = require('../../lib/services/codeship')
describe('Codeship CI Provider', function() {
it('can detect codeship', function() {
process.env.CI_NAME = 'codeship'
expect(codeship.detect()).toBe(true)
})
it('can get codeship env info', function() {
process.env.CI_BUILD_NUMBER = '1234'
process.env.CI_COMMIT_ID = '5678'
process.env.CI_BRANCH = 'master'
process.env.CI_BUILD_URL = 'https://...'
expect(codeship.configuration()).toEqual({
service: 'codeship',
commit: '5678',
build: '1234',
branch: 'master',
build_url: 'https://...',
})
})
})

24
node_modules/codecov/test/services/drone.test.js generated vendored Normal file
View File

@ -0,0 +1,24 @@
var drone = require('../../lib/services/drone')
var git = require('../../lib/git')
describe('Drone.io CI Provider', function() {
it('can detect drone', function() {
process.env.DRONE = 'true'
expect(drone.detect()).toBe(true)
})
it('can get drone env info', function() {
process.env.DRONE_BUILD_NUMBER = '1234'
process.env.DRONE_BRANCH = 'master'
process.env.DRONE_BUILD_URL = 'https://...'
process.env.DRONE_BUILD_DIR = '/'
expect(drone.configuration()).toEqual({
service: 'drone.io',
commit: git.head(),
build: '1234',
root: '/',
branch: 'master',
build_url: 'https://...',
})
})
})

48
node_modules/codecov/test/services/gitlab.test.js generated vendored Normal file
View File

@ -0,0 +1,48 @@
var gitlab = require('../../lib/services/gitlab')
describe('Gitlab CI Provider', function() {
it('can detect gitlab', function() {
process.env.GITLAB_CI = 'true'
expect(gitlab.detect()).toBe(true)
})
it('cannot detect gitlab', function() {
delete process.env.GITLAB_CI
expect(gitlab.detect()).toBe(false)
})
it('can get service env info', function() {
process.env.CI_BUILD_ID = '1234'
process.env.CI_BUILD_REPO = 'https://gitlab.com/owner/repo.git'
process.env.CI_BUILD_REF = '5678'
process.env.CI_BUILD_REF_NAME = 'master'
process.env.CI_PROJECT_DIR = '/'
expect(gitlab.configuration()).toEqual({
service: 'gitlab',
build: '1234',
root: '/',
commit: '5678',
slug: 'owner/repo',
branch: 'master',
})
delete process.env.CI_BUILD_REPO
process.env.CI_REPOSITORY_URL = 'https://gitlab.com/owner/repo2.git'
expect(gitlab.configuration()).toEqual({
service: 'gitlab',
build: '1234',
root: '/',
commit: '5678',
slug: 'owner/repo2',
branch: 'master',
})
delete process.env.CI_REPOSITORY_URL
expect(gitlab.configuration()).toEqual({
service: 'gitlab',
build: '1234',
root: '/',
commit: '5678',
slug: '',
branch: 'master',
})
})
})

21
node_modules/codecov/test/services/heroku.test.js generated vendored Normal file
View File

@ -0,0 +1,21 @@
var heroku = require('../../lib/services/heroku')
describe('Heroku CI Provider', function() {
it('can detect heroku', function() {
process.env.HEROKU_TEST_RUN_ID = '454f5dc9-afa4-433f-bb28-84678a00fd98'
expect(heroku.detect()).toBe(true)
})
it('can get wercker env info', function() {
process.env.HEROKU_TEST_RUN_ID = '454f5dc9-afa4-433f-bb28-84678a00fd98'
process.env.HEROKU_TEST_RUN_COMMIT_VERSION =
'743b04806ea677403aa2ff26c6bdeb85005de658'
process.env.HEROKU_TEST_RUN_BRANCH = 'master'
expect(heroku.configuration()).toEqual({
service: 'heroku',
commit: '743b04806ea677403aa2ff26c6bdeb85005de658',
build: '454f5dc9-afa4-433f-bb28-84678a00fd98',
branch: 'master',
})
})
})

64
node_modules/codecov/test/services/jenkins.test.js generated vendored Normal file
View File

@ -0,0 +1,64 @@
var jenkins = require('../../lib/services/jenkins')
var git = require('../../lib/git')
describe('Jenkins CI Provider', function() {
it('can detect jenkins', function() {
process.env.JENKINS_URL = 'http://jenkins.jenkins.example/'
expect(jenkins.detect()).toBe(true)
})
it('can get service env info', function() {
process.env.BUILD_NUMBER = '1234'
process.env.BUILD_URL = 'http://asdf/'
process.env.GIT_COMMIT = '5678'
process.env.GIT_BRANCH = 'master'
process.env.WORKSPACE = '/'
expect(jenkins.configuration()).toEqual({
service: 'jenkins',
build_url: 'http://asdf/',
build: '1234',
root: '/',
commit: '5678',
pr: undefined,
branch: 'master',
})
})
it('can get service env info when using Blue Ocean', function() {
delete process.env.GIT_COMMIT
delete process.env.GIT_BRANCH
process.env.BUILD_NUMBER = '1234'
process.env.BUILD_URL = 'http://asdf/'
process.env.BRANCH_NAME = 'master'
process.env.WORKSPACE = '/'
expect(jenkins.configuration()).toEqual({
service: 'jenkins',
build_url: 'http://asdf/',
build: '1234',
root: '/',
commit: git.head(),
pr: undefined,
branch: 'master',
})
})
it('github pull request env variables win out over jenkins variables', function() {
process.env.BUILD_NUMBER = '1234'
process.env.BUILD_URL = 'http://asdf/'
process.env.GIT_COMMIT = '5678'
process.env.ghprbActualCommit = '8765'
process.env.GIT_BRANCH = 'master'
process.env.ghprbSourceBranch = 'retsam'
process.env.ghprbPullId = '1111'
process.env.WORKSPACE = '/'
expect(jenkins.configuration()).toEqual({
service: 'jenkins',
build_url: 'http://asdf/',
build: '1234',
root: '/',
commit: '8765',
pr: '1111',
branch: 'retsam',
})
})
})

17
node_modules/codecov/test/services/localGit.test.js generated vendored Normal file
View File

@ -0,0 +1,17 @@
var local = require('../../lib/services/localGit')
var execSync = require('child_process').execSync
describe('Local git/mercurial CI Provider', function() {
it('can get commit', function() {
expect(local.configuration().commit).toMatch(/^\w{40}$/)
expect(local.configuration().commit).toEqual(
execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'")
.toString()
.trim()
)
})
it('can get branch', function() {
expect(local.configuration().branch).not.toEqual(null)
})
})

40
node_modules/codecov/test/services/semaphore.test.js generated vendored Normal file
View File

@ -0,0 +1,40 @@
var semaphore = require('../../lib/services/semaphore')
describe('Semaphore CI Provider', function() {
var OLD_ENV = process.env
beforeEach(function() {
process.env = Object.assign({}, OLD_ENV)
})
afterEach(function() {
process.env = Object.assign({}, OLD_ENV)
})
it('can detect semaphore', function() {
process.env.SEMAPHORE = 'true'
process.env.SEMAPHORE_REPO_SLUG = 'owner/repo'
expect(semaphore.detect()).toBe(true)
})
it('does not detect semaphore 2.x', function() {
process.env.SEMAPHORE = 'true'
process.env.SEMAPHORE_WORKFLOW_ID = '65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf'
expect(semaphore.detect()).toBe(false)
})
it('can get semaphore env info', function() {
process.env.SEMAPHORE_BUILD_NUMBER = '1234'
process.env.REVISION = '5678'
process.env.SEMAPHORE_CURRENT_THREAD = '1'
process.env.BRANCH_NAME = 'master'
process.env.SEMAPHORE_REPO_SLUG = 'owner/repo'
expect(semaphore.configuration()).toEqual({
service: 'semaphore1x',
commit: '5678',
build: '1234.1',
branch: 'master',
slug: 'owner/repo',
})
})
})

37
node_modules/codecov/test/services/semaphore2x.test.js generated vendored Normal file
View File

@ -0,0 +1,37 @@
var semaphore2 = require('../../lib/services/semaphore2x')
describe('Semaphore 2.x CI Provider', function() {
var OLD_ENV = process.env
beforeEach(function() {
process.env = Object.assign({}, OLD_ENV)
})
afterEach(function() {
process.env = Object.assign({}, OLD_ENV)
})
it('can detect semaphore 2x', function() {
process.env.SEMAPHORE = 'true'
process.env.SEMAPHORE_WORKFLOW_ID = '65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf'
expect(semaphore2.detect()).toBe(true)
})
it('does not detect semaphore 1.x', function() {
process.env.SEMAPHORE = 'true'
process.env.SEMAPHORE_REPO_SLUG = 'owner/repo'
expect(semaphore2.detect()).toBe(false)
})
it('can get semaphore env info', function() {
process.env.SEMAPHORE_GIT_BRANCH = 'development'
process.env.SEMAPHORE_GIT_SHA = '5c84719708b9b649b9ef3b56af214f38cee6acde'
process.env.SEMAPHORE_WORKFLOW_ID = '65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf'
expect(semaphore2.configuration()).toEqual({
service: 'semaphore2x',
branch: 'development',
build: '65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf',
commit: '5c84719708b9b649b9ef3b56af214f38cee6acde',
})
})
})

27
node_modules/codecov/test/services/shippable.test.js generated vendored Normal file
View File

@ -0,0 +1,27 @@
var shippable = require('../../lib/services/shippable')
describe('Shippable CI Provider', function() {
it('can detect shippable', function() {
process.env.SHIPPABLE = 'true'
expect(shippable.detect()).toBe(true)
})
it('can get shippable env info get_commit_status', function() {
process.env.SHIPPABLE = 'true'
process.env.BUILD_URL = 'http://...'
process.env.COMMIT = '5678'
process.env.BUILD_NUMBER = '91011'
process.env.BUILD_URL = 'http://...'
process.env.BRANCH = 'master'
process.env.PULL_REQUEST = '2'
process.env.REPO_NAME = 'owner/repo'
expect(shippable.configuration()).toEqual({
service: 'shippable',
commit: '5678',
build: '91011',
build_url: 'http://...',
branch: 'master',
pr: '2',
slug: 'owner/repo',
})
})
})

40
node_modules/codecov/test/services/snap.test.js generated vendored Normal file
View File

@ -0,0 +1,40 @@
var snap = require('../../lib/services/snap')
describe('Snap CI Provider', function() {
it('can detect snap', function() {
process.env.SNAP_CI = 'true'
expect(snap.detect()).toBe(true)
})
it('can get snap env info get_commit_status', function() {
process.env.SNAP_CI = 'true'
process.env.SNAP_PIPELINE_COUNTER = '1234'
process.env.SNAP_COMMIT = '5678'
process.env.SNAP_BRANCH = 'master'
process.env.SNAP_PULL_REQUEST_NUMBER = 'blah'
expect(snap.configuration()).toEqual({
service: 'snap',
commit: '5678',
build: '1234',
branch: 'master',
pr: 'blah',
})
})
it('can get snap env info get_commit_status for pull requests', function() {
process.env.SNAP_COMMIT = ''
process.env.SNAP_BRANCH = ''
process.env.SNAP_CI = 'true'
process.env.SNAP_PIPELINE_COUNTER = '1234'
process.env.SNAP_UPSTREAM_COMMIT = '5678'
process.env.SNAP_UPSTREAM_BRANCH = 'upstream-branch'
process.env.SNAP_PULL_REQUEST_NUMBER = 'blah'
expect(snap.configuration()).toEqual({
service: 'snap',
commit: '5678',
build: '1234',
branch: 'upstream-branch',
pr: 'blah',
})
})
})

22
node_modules/codecov/test/services/teamcity.test.js generated vendored Normal file
View File

@ -0,0 +1,22 @@
var teamcity = require('../../lib/services/teamcity')
describe('TeamCity CI Provider', function() {
it('can detect teamcity', function() {
process.env.TEAMCITY_VERSION = '8910'
expect(teamcity.detect()).toBe(true)
})
it('can get teamcity env info get_commit_status', function() {
process.env.TEAMCITY_VERSION = '8910'
process.env.BUILD_VCS_NUMBER = '4567'
process.env.BRANCH_NAME = 'ABranch'
process.env.BUILD_NUMBER = '1234'
expect(teamcity.configuration()).toEqual({
service: 'teamcity',
commit: '4567',
branch: 'ABranch',
build: '1234',
})
})
})

28
node_modules/codecov/test/services/travis.test.js generated vendored Normal file
View File

@ -0,0 +1,28 @@
var travis = require('../../lib/services/travis')
describe('Travis CI Provider', function() {
it('can detect travis', function() {
process.env.TRAVIS = 'true'
expect(travis.detect()).toBe(true)
})
it('can get travis env info get_commit_status', function() {
process.env.TRAVIS = 'true'
process.env.TRAVIS_JOB_ID = '1234'
process.env.TRAVIS_COMMIT = '5678'
process.env.TRAVIS_JOB_NUMBER = '91011'
process.env.TRAVIS_BRANCH = 'master'
process.env.TRAVIS_PULL_REQUEST = 'blah'
process.env.TRAVIS_BUILD_DIR = '/'
process.env.TRAVIS_REPO_SLUG = 'owner/repo'
expect(travis.configuration()).toEqual({
service: 'travis',
commit: '5678',
build: '91011',
branch: 'master',
root: '/',
job: '1234',
pr: 'blah',
slug: 'owner/repo',
})
})
})

25
node_modules/codecov/test/services/wercker.test.js generated vendored Normal file
View File

@ -0,0 +1,25 @@
var wercker = require('../../lib/services/wercker')
describe('Wercker CI Provider', function() {
it('can detect wercker', function() {
process.env.WERCKER_MAIN_PIPELINE_STARTED = '1399372237'
expect(wercker.detect()).toBe(true)
})
it('can get wercker env info', function() {
process.env.WERCKER_MAIN_PIPELINE_STARTED = '1399372237'
process.env.WERCKER_GIT_COMMIT = '5678'
process.env.WERCKER_GIT_BRANCH = 'master'
process.env.WERCKER_BUILD_URL = 'https://...'
process.env.WERCKER_GIT_OWNER = 'owner'
process.env.WERCKER_GIT_REPOSITORY = 'repo'
expect(wercker.configuration()).toEqual({
service: 'wercker',
commit: '5678',
build: '1399372237',
branch: 'master',
build_url: 'https://...',
slug: 'owner/repo',
})
})
})