Comments (17)
Two changes fix this package for the latest versions of node,
- The module loader "getSource" definition must be exported as "load". node shows this in the test process "(node:14251) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getSource". I searched for ways to conditionally export "getSource" or "load" depending upon the node version but didn't find a way to it.
- The value returned by "load" needs to include a property
format: 'module'
or an error is thrown.
Here's what I propose,
- release a minor version, exporting both 'load' and 'getSource' hooks. The deprecation warning will show when this package gets used,
- release a new major version, removing 'getSource' and updating the README with some information about that
Maybe "getSource" should be kept rather than removed, I'm not sure.
@mroderick do you have any input?
cc @Swivelgames feel free to give your opinion or ignore as well.
from esmock.
I can confirm that the issue has been resolved 👍
from esmock.
@mroderick thanks for messaging me here. I'll take a look this evening to try resolving this.
from esmock.
The mac+node issue described here affects me (though they are discussing a different version) https://stackoverflow.com/questions/69452504/zlib-error-when-attempting-to-run-npm-install-or-yarn#answer-69743293
I'll need to resolve environment issues before I can look into this
from esmock.
the PR auto-closed this ticket...
from esmock.
its published as version 0.4.2 https://www.npmjs.com/package/esmock
feel free to re-open this issue @mroderick
I didn't intend close the issue but wrote 'closes #16' in the PR description and github closed it. Anyway, I think its resolved.
from esmock.
With version [email protected] on 16.13.0 you get this warning:
(node:13737) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getSource
from esmock.
@maherma-adg do you recommend a way to resolve this? I searched for a way to conditionally export 'getSource' if node version is less than 16.12, but node forces the file to declare exports statically.
what do you think of think of this idea... two module loaders, one for node v12-v16.11 and another for node v16.13+
node v12-v16.11
mocha --loader=esmock/loader.getSource.mjs
node v16.12+
mocha --loader=esmock
I'm not exactly sure if it will work, but I think it could work.
from esmock.
I would prefer if "--loader=esmock" could be used always but how does one make that load a file that only exports "getSource" for node v12-v16.11?
from esmock.
@maherma-adg I found a way to make the warning go away #19
from esmock.
@maherma-adg try the newest version
from esmock.
It's works with ava, but I can't make it work with jest, anyone can?
from esmock.
@maherma-adg I haven't tried it with jest, but doesn't jest process everything through a transpiler? Maybe that's why it doesn't work... maybe its transforming the sources into cjs or something similar
from esmock.
As far as I know, jest only transpile when needed ( and you must configure transpiler ) for TS, Vue, JSX, etc. I'll try to dig deeper.
Thanks for your useful tool.
Manuel.
UPDATE: My mistake, reading more into doc, I see automatic transform through babel is done for JS files.
from esmock.
@maherma-adg https://jestjs.io/docs/ecmascript-modules try disabling transformations or configuring them to produce esm
from esmock.
How can I set the loader for jest on esm?
from esmock.
@OlaoluwaM if you make a PR with a sample basic jest test in it, I can try and make things work with that
from esmock.
Related Issues (20)
- Error: invalid moduleId when trying to stub a module dependency ES6 HOT 4
- What about Yarn PnP support? HOT 13
- Minified sources in esmock package HOT 4
- Invalid check in esmockIsLoader.js HOT 8
- Unable to mock the native node:zlib module with TypeScript and Mocha/Chai/Sinon. HOT 2
- Partial mocking not working as expected HOT 18
- Issues with pnpm HOT 8
- strictest silently allows to pass {} or undefined as defs -> real dependencies are used HOT 1
- Is it possible to mock `process.cwd()`? HOT 6
- Overriding `globalThis` per mock HOT 6
- Node 20.x: import.meta.resolve is not a promise anymore HOT 1
- Unexpected token 'delete' HOT 9
- Mock a package globally HOT 1
- Add factory method(s) to avoid code duplication / custom wrappers HOT 4
- `invalid moduleId` error when using tsx HOT 16
- Mock dependency HOT 8
- Is it possible to mock a binary's imports? HOT 6
- Mocking a file with a hashbang using the `import` key fails HOT 7
- Error when using `import` key with modules that have CJS imports HOT 9
- 2.3.4 - 'RangeError [ERR_UNKNOWN_MODULE_FORMAT]: Unknown module format: undefined' HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esmock.