In component testing user can import esm modules in the test file, because it executes in the browser, which support them. But test files also import in nodejs environment which supports only cjs. Because of this all esm only modules throw ERR_REQUIRE_ESM error in nodejs env.
So i implement replacing import esm module to variable with proxy. Like this:
// From:
import esmPkg from "esm-module";
// To:
const esmPkg = new Proxy({}, {
get: function (target, prop) {
return prop in target ? target[prop] : new Proxy(() => {}, this);
},
apply: function () {
return new Proxy(() => {}, this);
}
});
This proxy gives ability to call every method or getter that user want.
What is done
In component testing user can import esm modules in the test file, because it executes in the browser, which support them. But test files also import in nodejs environment which supports only cjs. Because of this all esm only modules throw
ERR_REQUIRE_ESM
error in nodejs env.So i implement replacing import esm module to variable with proxy. Like this:
This proxy gives ability to call every method or getter that user want.
Need review only second commit.