Skip to content

Commit

Permalink
Use a special environment variable for testing rather than `NODE… (#260)
Browse files Browse the repository at this point in the history
Use a special environment variable for testing rather than `NODE_ENV`.
  • Loading branch information
abernix authored Dec 11, 2019
2 parents 1e5dc48 + 25f44ba commit c7bfeaf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const config = require('../../jest.config.base');

module.exports = Object.assign(Object.create(null), config);
const packageSpecificSetupFiles = ['<rootDir>/src/__tests__/jestSetup.ts'];

const setupFiles = (Array.isArray(config.setupFiles)
? config.setupFiles
: []
).concat(packageSpecificSetupFiles);

module.exports = Object.assign(Object.create(null), config, { setupFiles });
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Since we memoize the environment variables which are used to control the
// override variables for the manifest location (in an effort to avoid the
// costly checking of `process.env` on each check; a notable production
// performance win), it's difficult to temporarily override those in Jest mocks
// without needing to carefully call `jest.resetModules` on anything they might
// have touched.We set this in order to allow a more simplified approach to
// testing. While we could have (and previously did) leverage a check against
// the `process.env.NODE_ENV === 'test' variable, this is problematic because
// customer's tests would also have that set. Using this environment variable
// allows us to make sure we're only running in the test suite for this plugin,
// and not implementors' tests.
process.env['__APOLLO_OPERATION_REGISTRY_TESTS__'] = 'true';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const fakeTestBaseUrl = 'https://fake-host-for-apollo-op-reg-tests/';
export const urlOperationManifestBase: string = ((): string => {
const desiredUrl =
process.env[envOverrideOperationManifest] ||
process.env['NODE_ENV'] === 'test'
// See src/__tests__/jestSetup.ts for more details on this env. variable.
process.env['__APOLLO_OPERATION_REGISTRY_TESTS__'] === 'true'
? fakeTestBaseUrl
: 'https://storage.googleapis.com/engine-op-manifest-storage-prod/';

Expand All @@ -24,7 +25,8 @@ export const urlOperationManifestBase: string = ((): string => {
export const urlStorageSecretBase: string = ((): string => {
const desiredUrl =
process.env[envOverrideStorageSecretBaseUrl] ||
process.env['NODE_ENV'] === 'test'
// See src/__tests__/jestSetup.ts for more details on this env. variable.
process.env['__APOLLO_OPERATION_REGISTRY_TESTS__'] === 'true'
? fakeTestBaseUrl
: 'https://storage.googleapis.com/engine-partial-schema-prod/';

Expand Down

0 comments on commit c7bfeaf

Please sign in to comment.