Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tommy-mitchell/esmock-repro-cjs
Repro for iambumblehead/esmock#218
https://github.com/tommy-mitchell/esmock-repro-cjs
Last synced: 8 days ago
JSON representation
Repro for iambumblehead/esmock#218
- Host: GitHub
- URL: https://github.com/tommy-mitchell/esmock-repro-cjs
- Owner: tommy-mitchell
- Created: 2023-07-30T18:43:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-07T18:22:14.000Z (about 1 year ago)
- Last Synced: 2023-08-07T20:16:00.293Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# esmock-repro-cjs
Repro for https://github.com/iambumblehead/esmock/issues/218. Run `node test` to reproduce error.
## Issue
Mocking globally with the `import` key fails if a module has a CJS import:
```js
// src/test.js
import esmock from "esmock";const logs = [];
await esmock("./index.js", import.meta.url, {}, {
import: {
console: { log: (...args) => logs.push(...args) },
},
});console.log("logs:", ...logs);
```Error message:
```
file:///.../node_modules/camelcase-keys/index.js?esmkgdefs=file:///import?esmkTreeId=1&esmkModuleId=import&isfound=false&isesm=false&exportNames=console:1
import {console} from 'file:///import?esmkTreeId=1&esmkModuleId=import&isfound=false&isesm=false&exportNames=console';import mapObject from 'map-obj';
^^^^^^^^^
SyntaxError: The requested module 'map-obj' does not provide an export named 'default'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
```