-
Notifications
You must be signed in to change notification settings - Fork 62
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
interopDefault
proxy issue with testing
#341
Comments
interopDefault
option doesn't work the same past 2.2.0interopDefault
proxy issue with testing
Thanks for explaining the issue. I understand that the new behavior affects testing when modules are strictly being compared as objects. Unfortunately, it is not easy to avoid proxy, as it covers many edge cases in mixed CJS/ESM modules. I'm wondering is it affecting any real usecase in docusaurus too with wrong behavior of proxy? |
Yeah, I'm investigating that now. It seems like it does since the E2E tests were failing, specifically when importing the main config file in esm format. I actually just ended up wrapping the imported proxy in a The last remaining test failure seems to be something to do with a nested dependency not returning the proxy object. The usage of jiti is here. If you can see anything that might cause the dependencies to skip the jiti import, I'm all ears. |
Are both modules and configs having a default export? In this case, you might want to use |
No, plugins use named and default exports, and configs (typically) have a default export. Changing this behavior would be breaking so wouldn't be able to happen until the next major, and I'm not sure that is planned in the near future. For more detail, the larger test logic looks like this:
|
I will say that everything works as expected on 2.1.2 (last version before the proxy change, I believe), except for the need to add the Would you consider a PR that made the |
Surely feel free to make a PR to make Consider that I have another proposal. We could add a symbol to the jiti's interop proxy that allows accessing the raw module value to manually mix (but only for top level export). Currently something like this is also possible and I think should have similar effect (except that has one additional const { default: _default, ...namedExports } = entryWithDeps // proposal: entryWithDeps[Symbol.for('jiti.raw')]
const mixedExports = { ..._default, ...entryWithDeps } |
I like that second option much better. Would you want another option in |
We can do that too! Or what about |
On second thought, adding an option means it's potentially "normal" to access the module that way, and There are footguns with the mixed approach (see below), so while it will be nice to have the same functionality as v1, it seems like behavior that might want to be marked as unsafe and deprecated/removed in the next major version. // file1.ts
export const named = 42;
export default {
named: 43
}
// file2.ts
const mod = require('./file1.ts');
console.log(mod.named) // should this be 42 or 43? Perhaps the symbol is exported as such? // inside 'jiti' module
export const UNSAFE_FLAT_MODULE_EXPORTS = Symbol.for('jiti.unsafe_raw')
// user code
const entry = await jiti.import('./entry.ts');
const flatModule = entry[UNSAFE_FLAT_MODULE_EXPORTS]; |
|
Environment
See reproduction.
Reproduction
https://stackblitz.com/edit/jiti-interopdefault-testing?file=src%2Fmain.ts
Describe the bug
In upgrading to v2 for docusaurus, I'm discovering some odd behavior.
It seems that the Proxy implementation for interopDefault may not be entirely working as expected. In the repro link, you can see that the properties are accessible, but only when directly accessing the properties (since that's how Proxies work). The issue is that this is seemingly causing issues with testing.
Additional context
We are tracking the upgrade at facebook/docusaurus#10716
Logs
No response
The text was updated successfully, but these errors were encountered: