Added tests for named and wildcard import scenarios #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I ran into an issue yesterday that stemmed from a wildcard import, e.g.
import * as styles from 'some.module.css'
and using identity-obj-proxy in Jest config. The problem appeared using Gatsby's default config introduced in v3 where CSS modules are imported as ES modules.The recommended pattern is to use named imports, e.g.
import { wrapper, background } from 'some.module.css'
- good news, that works already! I've added a test caseimport-named-test.js
.But when we try and use a wildcard import, the resulting object in
* as object
does not become a proxy. If we look under the hood, it's clear why:becomes
Taking away some cache related code, that sums up to if our dependency is an ES Module
obj.__esModule == true
it returns it, otherwise it creates a new object using the dependency's exports.In identity-obj-proxy, we explicitly return
obj.__esModule
asfalse
for compatibility with other import patterns. And since the proxy doesn't have its own properties, the result will not work as expected.Changing the following lines in identity-obj-proxy satisfies wildcard imports, but breaks other types of imports.
And that's as far as I got... so I'm curious whether anyone can see another solution that adds support for wildcard imports while preserving support for other import patterns. If not, we could spin off an identity-wildcard-obj-proxy package for this purpose.
It's a subset of a subset of use-cases, but I'm all for saving others derailing from productivity by stuff like this 'just working'. This was an elusive issue in some test failures for me.