-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Run tests against source, CJS, and UMD builds #6209
Conversation
Hopefully this is never necessary, but it does provide a verification that there aren't issues with the builds. This does require the builds to be built before testing. A |
I was going to suggest that for the scripts. My concern is losing the ability to pass args to Jest easily. I tend to push back against scripts as aliases (npm run test:watching:coverage:regression:foo:bar and every combination of those options...), but this case makes sense. |
As long as the default runs against source, we can always use |
I was curious how React handles the tests on code that is stripped out in production builds (logs) and it turns out they use custom Jest matchers that just pass when the test isn't run in |
I really like the idea of running our tests on our builds, so thank you for this PR, @pshrmn. I'm sorry but I've been doing a lot of refactoring and adding new tests this past week, so this PR needs to be updated. But I think it's definitely worth it if we can make it work. |
Just FYI: I'm done messing around with the build for version 4.4 so it should be safe to rework this now. @timdorr actually found a bug in the CJS build this morning that I didn't catch because I changed the tests to pull directly from the |
Crap, I was working on this too... I'll let @pshrmn take over, but had some commits for moving the |
@pshrmn Did you back out the changes to react-router-config? That's where I was stuck too. |
@timdorr yeah, the "context mismatch" caused by importing from different builds (e.g. CJS tests import I also dropped testing the ES builds. I think those were actually working in my old commits, but I rebased everything together before rebasing on |
And feel free to add anything else to this commit. |
This looks great, thanks @pshrmn! :) A |
Can you please say more about this? I'm trying to think it through but I'm missing something. |
The The context created in the source code and the context created in the CJS build aren't compatible (different |
This could probably be solved by also mapping the |
Thanks for the clarification, @pshrmn. That makes sense. And the reason we don't have the same problem with the CJS But we would have the exact same problem with |
Yes, the And yes, importing the
|
I was just looking at how to implement this for Maybe updating to Babel 7 to take advantage of JS Babel configs would be helpful here? |
I tried updating to Babel 7 but decided to just stick with 6 for now. If you have time to look into upgrading, I'd be all for it. The JS config files are nice. But we were already doing that before with the |
Sorry this is a little off topic, but FWIW I think we should stop using the |
@pshrmn You were correct, the I also noticed another weird issue, which is that the website was actually pulling from the CJS build in one spot and the ESM build in another. I fixed it in 6460fe0, but it caught me off guard. I've always kind of used |
Hey @pshrmn, was just wondering if you'd still like to get this merged. Since you opened this PR, we've separated out the Jest config files (so we can use BTW, thank you for getting the ball rolling here! I'm going to feel so much better once we get this merged. |
Yeah, I can take a look at this soon to see what all of these conflicts are. |
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.
Not a whole lot to this now that the Jest configs were already moved.
packages/react-router-dom/modules/__tests__/BrowserRouter-test.js
Outdated
Show resolved
Hide resolved
I added the |
Awesome, thanks @pshrmn! I may keep the test script but may also get rid of it and just use the build matrix in Travis to run all the different builds. Then, if we want to run tests against a specific build we can just set the |
Huh, looks like the EDIT: You can see the error in the most recent build |
Oh shoot, I noticed that but forgot to mention it. Sorry! It looks like |
@TrySound mind if I pick your brain about this sutation? Given a module that uses named exports // node_modules/module/real-module.js
exports.thing = true; but its "main" module has a default export. // node_modules/module/index.js
module.exports = require("./real-module.js"); I believe that when Rollup converts the module to // src/index
import Module from "module";
console.log(Module.thing); but if the code is run without Rollup (e.g. testing the source code), it expects the import to look like this: // src/index.js
import { thing } from "module";
console.log(thing); How would you support both use cases? Would you use |
Ah, well in that case I think this means that you found an actual bug! Huh, imagine that... 😅 |
@pshrmn Could this be fixed by testing the ESM build directly (i.e. EDIT: Ah, nm. I forgot we can't use the |
I got it working locally by updating the Rollup config to: const commonjsOptions = {
include: /node_modules/,
namedExports: {
"node_modules/react-is/index.js": ["isValidElementType"]
}
}; and the import { isValidElementType } from "react-is"; I like having source code tests because you can run |
Yep, I would use |
Take advantage of Jest's
moduleNameMapper
to test thecjs
,es
, andumd
builds in addition to the source code. The React repo has a similar process for testing its builds.The
react-router
andreact-router-dom
tests skip the minimizedumd
builds because those have tests for warnings that get stripped from the minimized bundle.