dom-testing-library icon indicating copy to clipboard operation
dom-testing-library copied to clipboard

have main detect node vs browser

Open benmonro opened this issue 5 years ago • 5 comments

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 avatar Mar 27 '20 22:03 benmonro

@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...

benmonro avatar Mar 27 '20 22:03 benmonro

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.

kentcdodds avatar Mar 28 '20 13:03 kentcdodds

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

benmonro avatar Mar 28 '20 14:03 benmonro

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?

weyert avatar May 28 '20 16:05 weyert

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?

kentcdodds avatar May 29 '20 01:05 kentcdodds