Skip to content

Commit

Permalink
fix: modify jest config to look for absence of .env.test file
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnwesson committed Nov 29, 2023
1 parent 3c353ce commit 4346481
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { createConfig } = require('@edx/frontend-build');
const path = require('path');
const fs = require('fs');

const appEnvConfigPath = path.resolve(process.cwd(), './env.config.js');
const testEnvConfigPath = path.resolve(process.cwd(), './.env.test');

module.exports = createConfig('jest', {
setupFilesAfterEnv: [
Expand All @@ -27,12 +27,13 @@ module.exports = createConfig('jest', {
/*
Add environment variables here for testing with Jest Snapshot
Context: This is part of the gradual transformation from using .env.* to env.config.js
Snapshot is not aware of the JavaScript-based configuration, and without .env.test it
needs this logic to populate the process.env object.
TODO: Remove once all uses of process.env.[ENVIRONMENT_VARIABLE] are replaced in /src
This is part of the gradual transformation from using .env.* to env.config.js
Jest's Snapshot is not aware of the JavaScript-based configuration, and without
.env.test it needs this logic to populate the process.env object.
*/
if (fs.existsSync(appEnvConfigPath)) {
if (!fs.existsSync(testEnvConfigPath)) {
process.env = Object.assign(process.env, {
LMS_BASE_URL: 'http://localhost:18000',
LOGOUT_URL: 'http://localhost:18000/logout',
Expand Down

0 comments on commit 4346481

Please sign in to comment.