-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use getConfig in order to support runtime configuration #286
Conversation
Before, gradebook was reading config from `process.env` directly, which locked the app into using only static (build-time) configuration. In order to enable dynamic (runtime) configuration, we update gradebook to use frontend-platform's standard configuration interface: `mergeConfig()` and `getConfig()`. Bump version from 1.5.0 to 1.6.0. (I would normally just do a patch release for a fix, but the version was hasn't been bumped for a while, so adding in full runtime configuration support seemed like it warranted a proper minor version bump.)
src/data/store.test.js
Outdated
describe('if no SEGMENT_KEY', () => { | ||
const key = configuration.SEGMENT_KEY; | ||
const key = getConfig().SEGMENT_KEY; | ||
beforeEach(() => { | ||
configuration.SEGMENT_KEY = false; | ||
getConfig().SEGMENT_KEY = false; | ||
}); | ||
it('exports thunk and logger middleware, composed and applied with dev tools', () => { | ||
expect(createStore().middleware).toEqual( | ||
composeWithDevTools(applyMiddleware(thunkMiddleware, createLogger())), | ||
); | ||
}); | ||
afterEach(() => { | ||
configuration.SEGMENT_KEY = key; | ||
getConfig().SEGMENT_KEY = key; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking for help with this case. I'm not sure how to change the result of getConfig()
for just one test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently it fails with:
FAIL src/data/store.test.js
● store aggregator module › exported store › middleware › if no SEGMENT_KEY › exports thunk and logger middleware, composed and applied with dev tools
expect(received).toEqual(expected) // deep equality
- Expected - 0
+ Received + 4
Object {
"withDevTools": Object {
"applied": Array [
"thunkMiddleware",
"logger",
+ Object {
+ "map": "EVENTS MAP",
+ "model": "Segment",
+ },
],
},
}
66 | });
67 | it('exports thunk and logger middleware, composed and applied with dev tools', () => {
> 68 | expect(createStore().middleware).toEqual(
| ^
69 | composeWithDevTools(applyMiddleware(thunkMiddleware, createLogger())),
70 | );
71 | });
at Object.<anonymous> (src/data/store.test.js:68:44)
I presume this is because getConfig().SEGMENT_KEY = false
isn't actually setting SEGMENT_KEY
to false
within the test body.
Codecov ReportBase: 100.00% // Head: 99.84% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #286 +/- ##
===========================================
- Coverage 100.00% 99.84% -0.16%
===========================================
Files 110 109 -1
Lines 1264 1264
Branches 248 248
===========================================
- Hits 1264 1262 -2
- Misses 0 2 +2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Oops, looks like I need to add a test that hits the |
@arbrandes since you're reviewing, let me know if you think of any way to cover the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Left a couple of comments. Will test it next.
This is what frontend-app-ora-grading does. Looks like a reasonable test, except for the fact having each-and-every MFE do the same thing feels kinda redundant, just for coverage. 🤷🏼♂️ |
@arbrandes Hold on, gradebook is testing the same thing: https://github.com/kdmccormick/frontend-app-gradebook/blob/master/src/index.test.jsx#L49-L57. And that test is definitely running (I know, because I had to fix it :) Now to figure out why that isn't enough to make Coverage happy... |
I tested the change, and AFAICT it works just fine. |
Add a heavily-mocked test to make Coverage happy. Based on a similar test from: https://github.com/edx/frontend-app-ora-grading/blob/open-release/olive.master/src/index.test.jsx#L76-L86 I guess what we are testing here is that `initialize` and `mergeConfig` are being called with the correct arguments. I'm not convinced this test is valuable, but 100% coverage is required on this repo, so here it is.
I pushed c3b16d0 , and coverage is now 100%. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arbrandes Ready for another round of review! I have two questions for you: this one, and the one posted below.
BASE_URL: process.env.BASE_URL, | ||
LMS_BASE_URL: process.env.LMS_BASE_URL, | ||
LOGIN_URL: process.env.LOGIN_URL, | ||
LOGOUT_URL: process.env.LOGOUT_URL, | ||
CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH, | ||
REFRESH_ACCESS_TOKEN_ENDPOINT: process.env.REFRESH_ACCESS_TOKEN_ENDPOINT, | ||
DATA_API_BASE_URL: process.env.DATA_API_BASE_URL, | ||
SECURE_COOKIES: process.env.NODE_ENV !== 'development', | ||
SEGMENT_KEY: process.env.SEGMENT_KEY, | ||
ACCESS_TOKEN_COOKIE_NAME: process.env.ACCESS_TOKEN_COOKIE_NAME, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have included the config settings that were previously in config/index.js
. I did not pull in everything from .env
, which contains a lot of unused settings.
I grepped for process.env
and found two remaining usages:
- A few checks for
process.env.NODE_ENV == 'development'|'production'
. These feel like anti-patterns, but I assume it is OK to leave them as they were, since runtime config won't be overridingNODE_ENV
. <Footer logo={process.env.LOGO_POWERED_BY_OPEN_EDX_URL_SVG} />
-- This one confuses me, because AFAICT no other MFE has such a setting. Do other MFEs use the "Powered by Open edX" logo? If so, do they configure it some other way? I didn't see it in the default brand package. Anyway, I left this as-is, because tests failed when I tried to put it behind thegetConfig()
interface. Let me know if this seems like an issue Adolfo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The footer thing does indeed seem like an issue, but not a blocker here.
+1 for not including all the .env
settings.
+1 for leaving process.env.NODE_ENV
usages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…#286) Before, gradebook was reading config from `process.env` directly, which locked the app into using only static (build-time) configuration. In order to enable dynamic (runtime) configuration, we update gradebook to use frontend-platform's standard configuration interface: `mergeConfig()` and `getConfig()`. Bumps version from 1.5.0 to 1.6.0. (I would normally just do a patch release for a fix, but the version was hasn't been bumped for a while, so adding in full runtime configuration support seemed like it warranted a proper minor version bump.) Co-authored-by: Ghassan Maslamani <ghassan.maslamani@gmail.com>
…287) Before, gradebook was reading config from `process.env` directly, which locked the app into using only static (build-time) configuration. In order to enable dynamic (runtime) configuration, we update gradebook to use frontend-platform's standard configuration interface: `mergeConfig()` and `getConfig()`. Bumps version from 1.5.0 to 1.6.0. (I would normally just do a patch release for a fix, but the version was hasn't been bumped for a while, so adding in full runtime configuration support seemed like it warranted a proper minor version bump.) Co-authored-by: Ghassan Maslamani <ghassan.maslamani@gmail.com>
Description
Before, gradebook was reading config from
process.env
directly, which locked the app into using only
static (build-time) configuration. In order to
enable dynamic (runtime) configuration, we update
gradebook to use frontend-platform's standard
configuration interface:
mergeConfig()
andgetConfig()
.Bump version from 1.5.0 to 1.6.0.
(I would normally just do a patch release for a fix, but the version
was hasn't been bumped for a while, so adding in full runtime
configuration support seemed like it warranted a proper
minor version bump.)
References
This is a fix to support of overhangio/tutor-mfe#69, which implements openedx/wg-build-test-release#235, which is necessary for the Dec 9 (!) Olive release.
I also have a draft PR to backport this to Olive.master queued up. Once this PR merges, we can rebase and then merge the backport.
Developer Checklist
Reviewers: I'm looking for help on how to resolve the one failing test case -- see my comment below.Thanks Ghassan!Testing Instructions
Making sure it won't break anything:: Just start up Gradebook locally with Devstack or Tutor and do a general smoke test.
Making sure it actually fixes runtime configuration: Follow @ghassanmas's tutor-mfe PR test instructions, but change
MFE_GRADEBOOK_MFE_APP["repository"]
to"https://github.com/kdmccormick/frontend-app-gradebook"
.Reviewer Checklist
Collectively, these should be completed by reviewers of this PR:
FYI: @openedx/content-aurora