-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Adding static icon names to test env file #16078
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Hey @Gudahtt I see what you mean about this being tricky with stringifying the env variable. Is there any way of conditionally setting the
|
bdcdd2e
to
8098177
Compare
So the approach we've taken before is to make the environment variable a string all of the time, even in prod. We can use |
8098177
to
d9b8bec
Compare
BOOKMARK_FILLED: 'bookmark-filled', | ||
CALCULATOR_FILLED: 'calculator-filled', | ||
}; | ||
|
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.
No longer need to mock the icon names env var because we are setting it in test/env.js
@@ -1,3 +0,0 @@ | |||
<svg xmlns="http://www.w3.org/2000/svg" id="icon-user-cirlce-add-filled" viewBox="0 0 512 512"> | |||
<path d="m448 70c-14-17-36-27-60-27-23 0-43 9-58 24-9 9-15 20-19 31-3 8-4 17-4 26 0 15 4 30 12 42 4 7 9 13 15 18 14 13 33 21 54 21 9 0 18-1 25-4 19-6 35-19 45-35 4-7 7-15 9-23 2-6 2-13 2-19 0-21-8-40-21-54z m-30 69l-15 0 0 16c0 8-7 15-15 15-8 0-15-7-15-15l0-16-15 0c-9 0-15-7-15-15 0-9 6-16 15-16l15 0 0-14c0-8 7-15 15-15 8 0 15 7 15 15l0 14 15 0c9 0 16 7 16 16 0 8-7 15-16 15z m31 127c0-26-5-52-15-75-6 4-13 8-21 10-2 1-4 1-6 2 7 19 12 41 12 63 0 47-20 90-50 121-6-7-14-14-23-20-55-37-145-37-201 0-8 6-16 13-22 20-31-31-50-74-50-121 0-95 78-173 173-173 22 0 43 5 63 12 0-2 1-4 2-7 2-7 6-14 10-20-23-10-49-15-75-15-112 0-203 91-203 203 0 59 25 112 65 149 0 0 0 0 0 1 2 2 5 3 7 5 1 1 2 2 3 3 4 3 8 6 12 9 1 1 2 2 4 3 4 2 8 5 12 7 1 1 3 2 4 3 4 2 9 4 13 6 2 0 3 1 5 2 4 2 9 3 13 5 2 0 4 1 5 1 5 2 10 3 15 4 1 1 3 1 4 1 6 1 12 2 18 3 0 0 1 0 2 0 7 1 14 1 21 1 7 0 14 0 20-1 1 0 2 0 3 0 6-1 11-2 17-3 1 0 3-1 5-1 4-1 9-2 14-4 2 0 3-1 5-1 5-2 9-3 13-5 2-1 4-2 5-2 5-2 9-4 13-6 2-1 3-2 5-3 4-3 8-5 12-7 1-1 2-2 4-3 4-3 8-6 11-9 2-1 3-2 4-3 2-2 4-3 6-5 0-1 0-1 0-1 41-37 66-90 66-149z m-203-103c-42 0-76 34-76 76 0 42 32 75 75 76 0 0 1 0 2 0 0 0 1 0 1 0 0 0 0 0 0 0 42-1 74-34 74-76 0-42-34-76-76-76z"/> | |||
</svg> |
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.
Removing duplicate icon
d9b8bec
to
71bcede
Compare
return iconNames; | ||
const iconNamesStringified = JSON.stringify(iconNames); | ||
|
||
return iconNamesStringified; | ||
}; | ||
|
||
module.exports = { generateIconNames }; |
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.
Updating generateIconNames
to be synchronous because the genius that is @Gudahtt somehow figured out that to get it to work with jest
I was able to get it to work by making generateIconNames synchronous (swapping out fs.promises.readdir with fs.readdirSync), and calling it in test.env.js. Must be some Jest bug/quirk about async setup, I don't understand what's going on there,
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!
Edit: Whoops, mocha test failures now.
71bcede
to
46a5e7c
Compare
@@ -18,7 +18,7 @@ exports[`PickerNetwork should render the label inside the PickerNetwork 1`] = ` | |||
</p> | |||
<div | |||
class="box mm-picker-network__arrow-down-icon icon icon--size-xs box--flex-direction-row box--color-icon-default" | |||
style="mask-image: url('./images/icons/icon-undefined.svg;" | |||
style="mask-image: url('./images/icons/icon-arrow-down.svg;" | |||
/> | |||
</button> | |||
</div> |
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.
Having to update snapshots means that it's working!
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.
Still need to get the url formatting fixed
style="mask-image: url('./images/icons/icon-arrow-down.svg;')"
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.
Yup! It will be apart of the house keeping ticket
process.env.ICON_NAMES = { | ||
LOADING_FILLED: 'loading-filled', | ||
CLOSE_OUTLINE: 'close-outline', | ||
}; |
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.
These are now taken care of by generateIconNames
in test/jest/env.js
below
Builds ready [46a5e7c]
Page Load Metrics (2070 ± 97 ms)
Bundle size diffs
highlights:storybook
|
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!
Might also be worth mentioning that there is another reference to |
Explanation
Currently, any unit tests that use the
<Icon />
component will receive a propType error becauseICON_NAMES
environment variable doesn't exist in the testing environment.This is a problem because it makes it very hard to unit test components using Icons
In order to solve this problem, we are changing the environment variable
ICON_NAMES
from an object to a string. We can then parse it on the component end. It also duplicates theICON_NAMES
env variable inenv.js
so icon names will be available in the testing environment.The genius that is @Gudahtt figured out that we had to update the
generateIconNames
function to synchronous for it to work so this PR also does just that.More Information
Manual Testing Steps
The unit test apart of this PR should be sufficient
Pre-Merge Checklist
+ If there are functional changes: