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

Added Jest test to verify UMD API-forwarding for scheduling package #13532

Merged
merged 4 commits into from
Sep 1, 2018

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Sep 1, 2018

Additional automated check to ensure the two APIs stay in-sync.

@gaearon
Copy link
Collaborator

gaearon commented Sep 1, 2018

Seems good but I'm concerned these UMDs don't follow the convention. I understand why (there's no separate versions) but I'd prefer if they matched the naming scheme so we have the freedom to actually embed the implementation into them later without changing the paths.

If we do this, we'd need to change the test to compare both dev and prod bundles (even if they're the same).

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 1, 2018

Sure. Sounds reasonable.

@pull-bot
Copy link

pull-bot commented Sep 1, 2018

Details of bundled changes.

Comparing: 46950a3...3a33a3d

react-scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-scheduler.development.js +24.4% +23.6% 15.4 KB 19.17 KB 4.65 KB 5.74 KB UMD_DEV
react-scheduler.production.min.js 🔺+15.8% 🔺+21.0% 2.73 KB 3.16 KB 1.26 KB 1.53 KB UMD_PROD

Generated by 🚫 dangerJS

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 1, 2018

The future consideration was a good catch. Thanks for bringing that up.

I've copied the two files and renamed them to match our standard pattern. Also updated tests to cover them both, and updated the fixtures file.

const umdAPIProd = require('../../npm/umd/react-scheduler-tracking.production.min');
const cjsAPI = require('../../tracking');
const secretAPI = require('react/src/ReactSharedInternals').default;
compareAPIS([umdAPIDev, umdAPIProd, cjsAPI, secretAPI.SchedulerTracking]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel kind of clever about this test even though it's silly 😁

@@ -16,25 +16,26 @@ describe('Scheduling UMD bundle', () => {
jest.resetModules();
});

function compareAPIS(apis) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: maybe APIs 😄 (I don't care really)

function compareAPIS(apis) {
apis = apis.map(api => Object.keys(api).sort());
for (let i = 1; i < apis.length; i++) {
expect(apis[0]).toEqual(apis[i]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be a bit clearer if the "source of truth" API is passed as first argument. Then you can remove the let i = 1 special case. Also errors would be better if you do

expect(apis[i]).toEqual(nodeAPI);

because it's UMD/Secrets API that are actual and the original source code that is expected.

@gaearon
Copy link
Collaborator

gaearon commented Sep 1, 2018

Urrghhh GitHub shows my fresh comments as outdated whyyyy

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 1, 2018

Ran all test permutations and Flow checks locally since CircleCI/Yarn are still busted.

@bvaughn bvaughn merged commit bf8aa60 into facebook:master Sep 1, 2018
@bvaughn bvaughn deleted the scheduler-umd-api-forwarding-test branch September 1, 2018 19:52
@gaearon
Copy link
Collaborator

gaearon commented Sep 1, 2018

@bvaughn Did you see my comments?

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 1, 2018

Yikes. no, I didn't see any comments at all. Which ones did I miss?

@gaearon
Copy link
Collaborator

gaearon commented Sep 1, 2018

Let me repost lol

function compareAPIS(apis) {
apis = apis.map(api => Object.keys(api).sort());
for (let i = 1; i < apis.length; i++) {
expect(apis[0]).toEqual(apis[i]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be a bit clearer if the "source of truth" API is passed as first argument. Then you can remove the let i = 1 special case. Also errors would be better if you do

expect(apis[i]).toEqual(nodeAPI);

because it's UMD/Secrets API that are actual and the original source code that is expected.

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 1, 2018

Yuck! They just popped in!

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 1, 2018

Why is everything half broken today 😅 I will do another commit here in a sec.

@gaearon
Copy link
Collaborator

gaearon commented Sep 1, 2018

(By the way this is why I sometimes just use "add comment" instead of "review". I just don't have trust GitHub won't insta-hide them..)

@sebmarkbage
Copy link
Collaborator

I think we should undo the prod/dev split.

The mental model here is that Webpack should ideally include the scheduler in its runtime for everyone. So it needs to be tiny and way unopinionated.

@gaearon
Copy link
Collaborator

gaearon commented Sep 1, 2018

Should we undo it for CJS too? Should there be an ESM version? I think we'll need a more detailed plan there. After this change it's consistent with other React packages. If we want to make it sufficiently different let's first decide what's the intended layout structure and what UMD bundle will contain.

Otherwise it's neither here nor there.

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 1, 2018

I added a bullet to our Tuesday sync to decide on these specific things ^ Let's figure it out then 😄

jetoneza pushed a commit to jetoneza/react that referenced this pull request Jan 23, 2019
…acebook#13532)

* Added Jest test to verify UMD API-forwarding for scheduling package
* Added separate dev/prod UMD bundles for scheduler package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants