JupiterOne / integration-template

Template for JupiterOne integration projects.
Mozilla Public License 2.0
5 stars 3 forks source link

Add `test/config.ts` and `package.json` patterns to load `.env` only when intended #29

Closed aiwilliams closed 3 years ago

aiwilliams commented 3 years ago

@austinkelleher pointed out some time ago that it's not ideal to always load .env when running yarn test. This has proven to be true in a few situations. Instead, the developer that wants to perform recordings with the .env loaded (real credentials) will use yarn test:env, and the build will use yarn test:ci.

Move the integration template to this pattern:

"test": "jest",
"test:env": "LOAD_ENV=1 yarn test",
"test:ci": "yarn lint && yarn type-check && yarn test",
import * as dotenv from 'dotenv';
import * as path from 'path';
import { IntegrationConfig } from '../src/config';

if (process.env.LOAD_ENV) {
  dotenv.config({
    path: path.join(__dirname, '../.env'),
  });
}

export const integrationConfig: IntegrationConfig = {
  jamfHost:
    process.env.JAMF_HOST || 'https://jupiteronedev.jamfcloud.com/?failover',
  jamfUsername: process.env.JAMF_USERNAME || 'test-username',
  jamfPassword: process.env.JAMF_PASSWORD || 'test-password',
};
      - name: Run tests
        run: yarn test:ci
import { integrationConfig } from '../../../test/config';
aiwilliams commented 3 years ago

Fixed in https://github.com/JupiterOne/integration-template/pull/34