Skip to content

Commit

Permalink
feat: Check for CI env var to catch unknown CI envs
Browse files Browse the repository at this point in the history
This will let us know if a build is being ran in a CI system that we don't
support. Most CI systems will set the `CI` env var to true, so this can give us
a better understanding of how many folks are running in CI systems that we're
not supporting.
  • Loading branch information
Robdel12 committed Aug 27, 2019
1 parent b935c1b commit bcd027d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/environment.js
Expand Up @@ -49,6 +49,9 @@ class Environment {
return 'probo';
} else if (this._env.BITBUCKET_BUILD_NUMBER) {
return 'bitbucket';
} else if (this._env.CI) {
// this should always be the last branch
return 'CI/unknown';
}

return null;
Expand Down
26 changes: 26 additions & 0 deletions test/environment-test.js
Expand Up @@ -186,6 +186,32 @@ COMMIT_MESSAGE:A shiny new feature`);
});
});

context('in an unknown CI', function() {
beforeEach(function() {
environment = new Environment({
CI: 'true',
});
});

it('returns the right CI value', function() {
assert.strictEqual(environment.ci, 'CI/unknown');
});
});

context('in a known CI env with CI = true', function() {
beforeEach(function() {
environment = new Environment({
TRAVIS_BUILD_ID: '1234`',
CI: 'true',
});
});

it('returns the right CI value', function() {
assert.notEqual(environment.ci, 'CI/unknown');
assert.strictEqual(environment.ci, 'travis');
});
});

context('in Travis CI', function() {
beforeEach(function() {
environment = new Environment({
Expand Down

0 comments on commit bcd027d

Please sign in to comment.