diff --git a/README.md b/README.md index ce77432..479f3d9 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,10 @@ # inside-ci -Quick tool to check if we are inside a CI environment +Returns true if code is running inside CI, otherwise false. # API -`insideCi()` - -Returns true if inside CI. Otherwise returns false. +`const inside = require('inside-ci')` # CLI diff --git a/in.js b/in.js index 9fa08d9..c007514 100755 --- a/in.js +++ b/in.js @@ -1,12 +1,10 @@ #!/usr/bin/env node -let is = module.exports.insideCi = () => { - // Bail out if CI is overrided - return process.env.CI === 'false' - ? false - : !!['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x]) -} +// Bail out if CI is overrided +let is = module.exports = process.env.CI === 'false' + ? false + : !!['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x]) if (require.main === module) { - process.exit(is() ? 0 : 1) + process.exit(is ? 0 : 1) } diff --git a/not.js b/not.js index 5edd066..6ba9018 100755 --- a/not.js +++ b/not.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -process.exit(!require("./in.js").insideCi() ? 0 : 1) +process.exit(!require("./in.js") ? 0 : 1) diff --git a/package.json b/package.json index bba9454..65e69f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "inside-ci", - "version": "1.1.2", + "version": "2.0.0", "description": "Quick tool to check if we are inside CI", "main": "in.js", "scripts": { diff --git a/test.mjs b/test.mjs index b7abc6b..382a5c9 100644 --- a/test.mjs +++ b/test.mjs @@ -1,8 +1,9 @@ import { exec } from 'child_process' import { Eltro as t, assert } from 'eltro' -import { insideCi } from './in.js' +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); -t.describe('#insideCi()', function () { +t.describe('in.js', function () { // Most CI use env.CI (travis, Gitlab, etc.) // There are some exceptions though: // CI_APP_ID is used by Appflow: https://ionic.io/docs/appflow/package/environments#predefined-environments @@ -23,27 +24,35 @@ t.describe('#insideCi()', function () { } }) + let n = 1 + function insideCi() { + Object.keys(require.cache).forEach(key => { + delete require.cache[key] + }) + return import(`./in.js?${n++}`).then(x => x.default) + } + testVariables.forEach(name => { - t.test(`env.${name} should return true if set`, function () { + t.test(`env.${name} should return true if set`, async function () { process.env[name] = 'asdf' - assert.ok(insideCi()) + assert.ok(await insideCi()) }) }) - t.test('should return false by default', function() { - assert.notOk(insideCi()) + t.test('should return false by default', async function() { + assert.notOk(await insideCi()) }) - t.test('should return false if all are empty strings', function () { + t.test('should return false if all are empty strings', async function () { for (let name of testVariables) { process.env[name] = '' } - assert.notOk(insideCi()) + assert.notOk(await insideCi()) }) - t.test('should return false if env.CI is specifically "false"', function () { + t.test('should return false if env.CI is specifically "false"', async function () { process.env.CI = 'false' - assert.notOk(insideCi()) + assert.notOk(await insideCi()) }) })