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

Question: Any projects based on this that ARE trying to be complete like JSDOM? #198

Open
isaacs opened this issue Mar 14, 2023 · 4 comments

Comments

@isaacs
Copy link

isaacs commented Mar 14, 2023

This is a cool project! Context: I'm dealing right now with trying to figure out how to have tests for React components that don't take forever to run, can live in a clean plain old node environment instead of Jest's parallel universe, use tap's API instead of the code poetry like expect(thing).toHave.something('i can never remember this junk').that.isnt.Null(), etc.

I have it working now, but the big bottleneck is jsdom. Every component test takes like 5-10 seconds to spin up, at minimum, for a test that runs in 50ms or less. If they do anything interesting with the dom (which a lot of them do), it gets much worse. I'm starting to see why jest runs tests in the parallel universe that it does.

It seems like @testing-library/react and @testing-library/userevents can almost work, but there are some missing pieces (by design, I realize). I totally understand not wanting to add those pieces to linkedom, and agree with that principle entirely.

So the question is, is there a project you're aware of that uses linkedom under the hood, but then does add that extra stuff? Some of what seem to be missing that I've run into:

  • Location isn't set. (Can kinda hack around it by setting window.location to a URL object, which is close enough, but a proper Location polyfill would obviously be needed for anything doing actual navigation.)
  • Navigator has userAgent, but navigator.clipboard is missing.
  • Document.createRange() returns an object that doen'st have setStart and setEnd methods.

I'm thinking it'd be possible to create a set of polyfills for all these things, and probably end up with something that would really only lack some of the finer points of JSDOM's tree structure, but still be close enough to simulate a browser for react testing.

Is someone doing this already? Or, if not, is there some reason you know of why linkedom isn't a suitable base for something like this?

Thanks!

@WebReflection
Copy link
Owner

All your points could be addressed in here ... fancy filing a PR?

@isaacs
Copy link
Author

isaacs commented Mar 21, 2023

I can't promise how soon I'll get to it, but if you're open to PRs in that direction, I'll add it to my todo stack, if no one gets to it sooner :)

Maybe a way to frame this is less "fully and faithfully implement every browser spec" (which is jsdom's intent), but instead "implement enough of the browser spec to work as a seamless drop-in replacement for global-jsdom in @testing-library/react and @testing-library/userevents".

Still a pretty audacious goal, but could be tackled in parts, and it'd sure be nice to speed up the load times for those testing libraries.

@WebReflection
Copy link
Owner

A mock is a mock … I admire JSDOM ambition and yet I would use a real browser instead if real browsers is what I’m after 🤷 … this project goal is SSR and it’s already a stretch to that goal

@isaacs
Copy link
Author

isaacs commented Mar 27, 2023

Yeah, that's why I ask, I guess. SSR and testing are two different use cases, and while jsdom CAN do both, it does it rather inefficiently, because it's also trying to be a feature complete scraper (which is much more ambitious than either). When I get around to picking this up, I guess we can always split up the layers if it gets too unwieldy.

@isaacs isaacs mentioned this issue Apr 13, 2023
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants