From 5b15cef74a2fe96f525bc83785703b18f7a557a0 Mon Sep 17 00:00:00 2001 From: Jason Wesson Date: Tue, 28 Nov 2023 17:08:47 +0000 Subject: [PATCH 1/5] feat: add env.config.js to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 57e97d2f..5f4d4c56 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store .eslintcache +env.config.js node_modules npm-debug.log coverage From f041d35c274b5ca240bcb404209086fb40ebd915 Mon Sep 17 00:00:00 2001 From: Jason Wesson Date: Wed, 29 Nov 2023 22:39:50 +0000 Subject: [PATCH 2/5] docs: add example env.config.js file --- example.env.config.js | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 example.env.config.js diff --git a/example.env.config.js b/example.env.config.js new file mode 100644 index 00000000..6fd893ed --- /dev/null +++ b/example.env.config.js @@ -0,0 +1,56 @@ +module.exports = { + NODE_ENV: 'development', + NODE_PATH: './src', + PORT: 1996, + BASE_URL: 'localhost:1996', + LMS_BASE_URL: 'http://localhost:18000', + ECOMMERCE_BASE_URL: 'http://localhost:18130', + LOGIN_URL: 'http://localhost:18000/login', + LOGOUT_URL: 'http://localhost:18000/logout', + LOGO_URL: 'https://edx-cdn.org/v3/default/logo.svg', + LOGO_TRADEMARK_URL: 'https://edx-cdn.org/v3/default/logo-trademark.svg', + LOGO_WHITE_URL: 'https://edx-cdn.org/v3/default/logo-white.svg', + LOGO_POWERED_BY_OPEN_EDX_URL_SVG: 'https://edx-cdn.org/v3/stage/open-edx-tag.svg', + FAVICON_URL: 'https://edx-cdn.org/v3/default/favicon.ico', + CSRF_TOKEN_API_PATH: '/csrf/api/v1/token', + REFRESH_ACCESS_TOKEN_ENDPOINT: 'http://localhost:18000/login_refresh', + ACCESS_TOKEN_COOKIE_NAME: 'edx-jwt-cookie-header-payload', + USER_INFO_COOKIE_NAME: 'edx-user-info', + SITE_NAME: 'localhost', + DATA_API_BASE_URL: 'http://localhost:8000', + // LMS_CLIENT_ID should match the lms DOT client application in your LMS container + LMS_CLIENT_ID: 'login-service-client-id', + SEGMENT_KEY: '', + FEATURE_FLAGS: {}, + MARKETING_SITE_BASE_URL: 'http://localhost:18000', + SUPPORT_URL: 'http://localhost:18000/support', + CONTACT_URL: 'http://localhost:18000/contact', + OPEN_SOURCE_URL: 'http://localhost:18000/openedx', + TERMS_OF_SERVICE_URL: 'http://localhost:18000/terms-of-service', + PRIVACY_POLICY_URL: 'http://localhost:18000/privacy-policy', + FACEBOOK_URL: 'https://www.facebook.com', + TWITTER_URL: 'https://twitter.com', + YOU_TUBE_URL: 'https://www.youtube.com', + LINKED_IN_URL: 'https://www.linkedin.com', + REDDIT_URL: 'https://www.reddit.com', + APPLE_APP_STORE_URL: 'https://www.apple.com/ios/app-store/', + GOOGLE_PLAY_URL: 'https://play.google.com/store', + ENTERPRISE_MARKETING_URL: 'http://example.com', + ENTERPRISE_MARKETING_UTM_SOURCE: 'example.com', + ENTERPRISE_MARKETING_UTM_CAMPAIGN: 'example.com Referral', + ENTERPRISE_MARKETING_FOOTER_UTM_MEDIUM: 'Footer', + LEARNING_BASE_URL: 'http://localhost:2000', + SESSION_COOKIE_DOMAIN: 'localhost', + ZENDESK_KEY: '', + HOTJAR_APP_ID: '', + HOTJAR_VERSION: 6, + HOTJAR_DEBUG: '', + NEW_RELIC_APP_ID: '', + NEW_RELIC_LICENSE_KEY: '', + ACCOUNT_SETTINGS_URL: 'http://localhost:1997', + ACCOUNT_PROFILE_URL: 'http://localhost:1995', + ENABLE_NOTICES: '', + CAREER_LINK_URL: '', + OPTIMIZELY_FULL_STACK_SDK_KEY: '', + EXPERIMENT_08_23_VAN_PAINTED_DOOR: true, +}; From ec4e9e8c60651cc18c8c9c3bb8cb378f1c6ad4e2 Mon Sep 17 00:00:00 2001 From: Jason Wesson Date: Thu, 30 Nov 2023 22:49:18 +0000 Subject: [PATCH 3/5] docs: add comments around how to set up env.config.js and testing with Jest --- example.env.config.js | 15 +++++++++++++++ src/setupTest.jsx | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/example.env.config.js b/example.env.config.js index 6fd893ed..ee2ebf32 100644 --- a/example.env.config.js +++ b/example.env.config.js @@ -1,3 +1,18 @@ +/* +Learner Dashboard is now able to handle JS-based configuration! + +Until a later release, the .env.* files will still be included in this repo. + +Note: having both .env and env.config.js files will follow a predictable order +frontend-platform's getConfig loads configuration: +- .env file config +- optional handlers (commonly used to merge MFE-specific config in via additional process.env variables) +- env.config.js file config +- runtime config + +Any env vars needed for Jest Snapshot to pass can be mocked in ./src/setupTest.jsx +*/ + module.exports = { NODE_ENV: 'development', NODE_PATH: './src', diff --git a/src/setupTest.jsx b/src/setupTest.jsx index 2ac2d1b2..7a31cbed 100755 --- a/src/setupTest.jsx +++ b/src/setupTest.jsx @@ -67,6 +67,23 @@ jest.mock('@edx/frontend-platform/i18n', () => { }; }); +/* +When .env.test is removed, uncomment the env vars below and add any environment variables for testing with Jest + +Context: Snapshot is not currently not set up to be able to parse the environment variables in env.config.js +*/ + +// jest.mock('@edx/frontend-platform', () => ({ +// getConfig: jest.fn(() => ({ +// LMS_BASE_URL: 'http://localhost:18000', +// LOGOUT_URL: 'http://localhost:18000/logout', +// LOGO_URL: 'https://edx-cdn.org/v3/default/logo.svg', +// MARKETING_SITE_BASE_URL: 'http://localhost:18000', +// SUPPORT_URL: 'http://localhost:18000/support', +// OPTIMIZELY_FULL_STACK_SDK_KEY: 'SDK Key', +// })), +// })); + jest.mock('@edx/paragon', () => jest.requireActual('testUtils').mockNestedComponents({ Alert: { Heading: 'Alert.Heading', From e191448bb8ae875b44eb82ec504834ed3b622370 Mon Sep 17 00:00:00 2001 From: Jason Wesson Date: Fri, 1 Dec 2023 16:20:00 +0000 Subject: [PATCH 4/5] docs: add more context in using env.config.js --- example.env.config.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/example.env.config.js b/example.env.config.js index ee2ebf32..67d23135 100644 --- a/example.env.config.js +++ b/example.env.config.js @@ -1,16 +1,20 @@ /* Learner Dashboard is now able to handle JS-based configuration! -Until a later release, the .env.* files will still be included in this repo. +For the time being, the `.env.*` files are still made available when cloning down this repo or pulling from +the master branch. To switch to using `env.config.js`, make a copy of `example.env.config.js` and configure as needed. -Note: having both .env and env.config.js files will follow a predictable order -frontend-platform's getConfig loads configuration: +For testing with Jest Snapshot, there is a mock in `/src/setupTest.jsx` for `getConfig` that will need to be +uncommented. + +Note: having both .env and env.config.js files will follow a predictable order, in which non-empty values in the +JS-based config will overwrite the .env environment variables. + +frontend-platform's getConfig loads configuration in the following sequence: - .env file config - optional handlers (commonly used to merge MFE-specific config in via additional process.env variables) - env.config.js file config - runtime config - -Any env vars needed for Jest Snapshot to pass can be mocked in ./src/setupTest.jsx */ module.exports = { From edc4afe4dd767181f315722e477db93a06c4b5b6 Mon Sep 17 00:00:00 2001 From: Jason Wesson Date: Mon, 4 Dec 2023 17:48:30 +0000 Subject: [PATCH 5/5] fix: typo in setUp context --- src/setupTest.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setupTest.jsx b/src/setupTest.jsx index 7a31cbed..dc29e966 100755 --- a/src/setupTest.jsx +++ b/src/setupTest.jsx @@ -70,7 +70,7 @@ jest.mock('@edx/frontend-platform/i18n', () => { /* When .env.test is removed, uncomment the env vars below and add any environment variables for testing with Jest -Context: Snapshot is not currently not set up to be able to parse the environment variables in env.config.js +Context: Snapshot is not currently set up to be able to parse the environment variables in env.config.js */ // jest.mock('@edx/frontend-platform', () => ({