-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a special environment variable for testing rather than `NODE… (#260)
Use a special environment variable for testing rather than `NODE_ENV`.
- Loading branch information
Showing
3 changed files
with
24 additions
and
3 deletions.
There are no files selected for viewing
9 changes: 8 additions & 1 deletion
9
packages/apollo-server-plugin-operation-registry/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |
12 changes: 12 additions & 0 deletions
12
packages/apollo-server-plugin-operation-registry/src/__tests__/jestSetup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters