node-esm-mock 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# esm-mock
|
|
1
|
+
# node-esm-mock
|
|
2
2
|
|
|
3
3
|
Mock ES modules in Node.js using `registerHooks` (Node >=22.7.0).
|
|
4
4
|
|
|
@@ -7,13 +7,13 @@ No loader flags, no `--experimental-loader`.
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npm install esm-mock
|
|
10
|
+
npm install node-esm-mock
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { mock } from 'esm-mock';
|
|
16
|
+
import { mock } from 'node-esm-mock';
|
|
17
17
|
import assert from 'node:assert';
|
|
18
18
|
import sinon from 'sinon';
|
|
19
19
|
|
|
@@ -71,7 +71,7 @@ assert.ok(Worker instanceof worker_threads.Worker);
|
|
|
71
71
|
|
|
72
72
|
## How it works
|
|
73
73
|
|
|
74
|
-
`esm-mock` registers a [`registerHooks`](https://nodejs.org/api/module.html#moduleregisterhooksoptions) instance at module scope that intercepts `resolve` and `load` for any module URL registered via `add()`. When a mocked module is requested, resolution short-circuits to a synthetic `mock-facade:` URL and `load` serves auto-generated ES module source that re-exports the replacement values.
|
|
74
|
+
`node-esm-mock` registers a [`registerHooks`](https://nodejs.org/api/module.html#moduleregisterhooksoptions) instance at module scope that intercepts `resolve` and `load` for any module URL registered via `add()`. When a mocked module is requested, resolution short-circuits to a synthetic `mock-facade:` URL and `load` serves auto-generated ES module source that re-exports the replacement values.
|
|
75
75
|
|
|
76
76
|
Each `mock(mocks).for(specifier)` call:
|
|
77
77
|
1. Registers each mock entry via the internal `add()` function.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-esm-mock",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Mock ES modules in Node.js using registerHooks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"registerHooks"
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/prograpedia/node-esm-mock"
|
|
29
|
+
},
|
|
30
|
+
"author": "Cristian Torres <cris.torres15@gmail.com>",
|
|
26
31
|
"engines": {
|
|
27
32
|
"node": ">=22.7.0"
|
|
28
33
|
},
|