Skip to content
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 not process.env #232

Merged
merged 3 commits into from
Nov 30, 2023

Conversation

cintnguyen
Copy link
Contributor

Changed process.env to getConfig() in order to support runtime configurations. Moved all process.env use in the index.html header to helmet.

Co-authored-by: @httpsmenahassan

@cintnguyen cintnguyen force-pushed the runtime-config branch 4 times, most recently from caaa9d7 to c4350cc Compare October 27, 2023 19:34
@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b83f128) 96.45% compared to head (81ce59e) 96.36%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #232      +/-   ##
==========================================
- Coverage   96.45%   96.36%   -0.10%     
==========================================
  Files         194      194              
  Lines        1835     1841       +6     
  Branches      322      324       +2     
==========================================
+ Hits         1770     1774       +4     
- Misses         60       62       +2     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hurtstotouchfire hurtstotouchfire added the needs maintainer attention Issue or PR specifically needs the attention of the maintainer. label Nov 20, 2023
@deborahgu deborahgu self-assigned this Nov 21, 2023
Copy link
Member

@deborahgu deborahgu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, but I have a few questions and a request for tests @cintnguyen

public/index.html Show resolved Hide resolved
src/App.jsx Show resolved Hide resolved
@@ -41,8 +42,21 @@ export const App = () => {
const { supportEmail } = reduxHooks.usePlatformSettingsData();
const loadData = reduxHooks.useLoadData();

const optimizelyScript = () => {
if (getConfig().OPTIMIZELY_URL) {
return <script src={getConfig().OPTIMIZELY_URL} />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing test; could you add one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried tackling this in 370aa3f, ran into issues with runBasicTests() not respecting dynamic getConfig mocks. It seems to be a test scope issue. I am not quite sure what refactoring of App.test.jsx would be needed to get this working yet.

I will be out of office until end of next week, in the meantime @brian-smith-tcril and @httpsmenahassan have offered to take a look at this.

const optimizelyScript = () => {
if (getConfig().OPTIMIZELY_URL) {
return <script src={getConfig().OPTIMIZELY_URL} />;
} if (getConfig().OPTIMIZELY_PROJECT_ID) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing test; could you add one?

@deborahgu deborahgu added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Nov 21, 2023
@brian-smith-tcril
Copy link
Contributor

@deborahgu I added tests that cover the lines you mentioned, but it seems the overall coverage is still down from before.

The only thing that stood out to me when looking at the diff between App.jsx coverage on master vs this PR was hotjar

master

image

PR

image

but I'm not sure what's testing this useEffect() block.

I'll gladly update whatever test was covering these lines before, I just don't know where I should be looking.

Copy link
Member

@deborahgu deborahgu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll gladly update whatever test was covering these lines before, I just don't know where I should be looking.

yeah, @brian-smith-tcril, I'm a little stumped by this as well. I'd think it's just the getConfig on line 77 it wants tested, but then it's complaining about 2 lines, not one.

I'm comfortable forcing this through with the codecov complaint, tbh. I won't merge until morning because I hate doing something weird when it's the end of the day, but I'm going to approve this.

@deborahgu deborahgu removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. changes requested labels Nov 29, 2023
@brian-smith-tcril
Copy link
Contributor

brian-smith-tcril commented Nov 29, 2023

I'd think it's just the getConfig on line 77 it wants tested, but then it's complaining about 2 lines, not one.

That part makes sense to me, it's testing the condition but it's never testing it with a HOTJAR_APP_ID. Before the switch to getConfig it would pull that from here

HOTJAR_APP_ID='hot-jar-app-id'
HOTJAR_VERSION='6'
HOTJAR_DEBUG=''

I tried adding hotjar stuff to the mocked return values for getConfig in the same way that I handled OPTIMIZELY_URL but coverage still complained about those lines. That makes me think that App.test.jsx doesn't include any tests that trigger that useEffect

  React.useEffect(() => {
    // [...]
  }, [authenticatedUser, loadData]);

Since HOTJAR_APP_ID was being set in every test before (by means of existing in .env.test) that means the test that was covering those lines could be anything.

I was hoping I could find a way to see what test covered what lines, but I didn't see anything in the codecov web UI or the html report generated by running jest locally. My searches ("jest coverage see what test is covering a line" and "codecov see what test is covering a line") also didn't lead anywhere helpful.

Hopefully I can figure that out at some point. It seems like a very useful thing when updating tests in scenarios like this.


I'm comfortable forcing this through with the codecov complaint, tbh. I won't merge until morning because I hate doing something weird when it's the end of the day, but I'm going to approve this.

Thank you so much!

@deborahgu deborahgu merged commit a4f14da into openedx:master Nov 30, 2023
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs maintainer attention Issue or PR specifically needs the attention of the maintainer.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants