testing-library / dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.
https://testing-library.com/dom
MIT License
3.27k stars 466 forks source link

have main detect node vs browser #507

Open benmonro opened 4 years ago

benmonro commented 4 years ago

Describe the feature you'd like:

According to this comment: https://github.com/DevExpress/testcafe/issues/4176#issuecomment-523916838 it may be possible for dom testing library to detect if its being used in node or in a browser.

The feature I'm requesting is to have it use the UMD module if it's in the browser and if not the existing main.

Suggested implementation:

🤔

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

would not break anything, would just allow main to be used in the browser (via umd)

This will help w/ client script injection for testcafe testing library and make it a bit easier to inject DTL on the page.

benmonro commented 4 years ago

@kentcdodds curious if you have thoughts on if this is possible and if so if you'd be ok with it, super low priority but wondering what you think...

kentcdodds commented 4 years ago

I don't have a problem with this conceptually, but I don't know how this would be accomplished. I don't think it's reasonably possible.

benmonro commented 4 years ago

Supposedly lodash does it... Testcafe uses that as their example. I'll do some digging.

weyert commented 4 years ago

Wouldn't be possible to check if based on the user agent? If DOM Testing Library is running in jsdom it has a specific user agent name, if I remember correctly. Node maybe by the existence of process-global?

kentcdodds commented 4 years ago

Right, but then what would we do with that information? How would we load the right thing dynamically in an environment that doesn't have a bundler/esmodules?