-
Notifications
You must be signed in to change notification settings - Fork 95
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
Discussion: enable mix of cjs and es test code. #155
Comments
Oh, this is enough. And better for future improvements. export * from './index.cjs'; Reducing zora to a commonjs only package also works. (removing "exports" in package.json). |
This sounds interesting. I am a bit concerned that it implies committing to cjs where the global trend is on the contrary get rid of it. Have you tried outside of pta ? browser, simple node module, node regular cjs package etc. Would you mind providing a PR so I get a better picture ? |
Browser is different, nodejs module resolving is not in play. (Not exactly sure about latest development of bundlers on dealing with "exports" field.) Note "module" and "browser" are not in nodejs/npm spec, they are purely invented by browserify and webpack I think. I used zora in browser. Pta is irrelevant in that contex. The bundler would not bundle two zora (cjs and esm). Bundler resolves I tested pta and zora in many different setups, src in cjs or esm, test in cjs or esm, all combinations work well. I have converted quite a few projects from tape or ava to zora. Really enjoy zora. All In nodejs, wrapping cjs into esm is easy. The other way is unfortunately prohibited (otherwise much better choice). I'd rather Nodejs folks sided with usability rather than perfect spec conformance. I will raise a PR. |
Oh thanks, much appreciated. I'll get a look. From the browser, is it still possible to get zora working with no bundler (ie with a simple URL from a CDN for example) ? |
Sure, you mean native es module. Then cjs is out of picture anyway. This reminded me the wrapper may not work for browser, at least for those cdns serving plain npm files. |
Following up #153, there is an easy way to enable mix of cjs and es test codes, report all of them as one.
Currently pta has to use
--module-loader
to separate cjs and es zora instance. The reason of that separation is that zora package shipped two dist files, one for cjs, one for es.I tested following change, it all worked out:
In this way, no matter how zora is used, the same zora instance in cjs file is used. Even when you mix
test/a.spec.cjs
andtest/b.spec.mjs
, it's still the same zora instance used across cjs and es tests, hence one united report will be generated.The other benefit is it can remove the
--module-loader
option from pta, there is no function lost, just less friction for end users.The text was updated successfully, but these errors were encountered: