{"_id":"@arbendium/mock-esm","_rev":"3-3552883349d91723e4ee9b216c088b54","name":"@arbendium/mock-esm","dist-tags":{"latest":"2.3.0"},"versions":{"2.2.0":{"name":"@arbendium/mock-esm","version":"2.2.0","keywords":["mock","esm","loader","test"],"author":{"name":"Keijo Kapp","email":"keijo.kapp@gmail.com"},"license":"ISC","_id":"@arbendium/mock-esm@2.2.0","maintainers":[{"name":"keijokapp","email":"keijo.kapp@gmail.com"}],"homepage":"https://github.com/arbendium/mock-esm#readme","bugs":{"url":"https://github.com/arbendium/mock-esm/issues"},"dist":{"shasum":"429a2b5b554aa5bc0d148691dfa0dece819cc3d7","tarball":"https://registry.npmjs.org/@arbendium/mock-esm/-/mock-esm-2.2.0.tgz","fileCount":4,"integrity":"sha512-dN+exTjwGOLxFAOCFvHV6+xOj1K4KT/yJSznSXUICWuqsSxlDsiseOUlWRmcfQ6h7x7+xYxgdgR6f2T9sysGIA==","signatures":[{"sig":"MEYCIQDiTOyHvpljMjo0sMYzlGQ2krw9Q+JBTOCwU4QOyptYuAIhAIEG9VtJ9cFwNQkcjGIzlnuZiwnplrUZb21BespBsTXd","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":7011},"main":"index.js","type":"module","exports":{".":"./index.js","./loader":"./loader.js","./loader.js":"./loader.js"},"gitHead":"2842253f48a9cd8c6c7a85344b64f4705102bedf","scripts":{"test":"node test.js"},"_npmUser":{"name":"keijokapp","email":"keijo.kapp@gmail.com"},"repository":{"url":"git+https://github.com/arbendium/mock-esm.git","type":"git"},"_npmVersion":"10.2.0","description":"A small mocking library for Node ESM based codebase","directories":{},"_nodeVersion":"20.8.0","_hasShrinkwrap":false,"devDependencies":{"mock-esm":"."},"_npmOperationalInternal":{"tmp":"tmp/mock-esm_2.2.0_1697198160795_0.3691376031061886","host":"s3://npm-registry-packages"}},"2.2.1":{"name":"@arbendium/mock-esm","version":"2.2.1","keywords":["mock","esm","loader","test"],"author":{"name":"Keijo Kapp","email":"keijo.kapp@gmail.com"},"license":"ISC","_id":"@arbendium/mock-esm@2.2.1","maintainers":[{"name":"keijokapp","email":"keijo.kapp@gmail.com"}],"homepage":"https://github.com/arbendium/mock-esm#readme","bugs":{"url":"https://github.com/arbendium/mock-esm/issues"},"dist":{"shasum":"1f66a4d0c1b4bdaff6f3230572a13a35daa418dc","tarball":"https://registry.npmjs.org/@arbendium/mock-esm/-/mock-esm-2.2.1.tgz","fileCount":4,"integrity":"sha512-2qT7WBb7hEb00AxB5Hs8gMEjoM/86EAl71h5N4kOVF9ynxul0dSp89xcmCyH2FKocMKck/UJSG9lT1isaVsn3Q==","signatures":[{"sig":"MEYCIQDGrFR7cnexOsDY9Tk/Lh7tB25bJaOHxlff3+Z1bjQTzAIhAN6kuQbPCkXUqCGYz0Z+nzhZdkUicFL5dOLPHS1OAJkv","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":7077},"main":"index.js","type":"module","exports":{".":"./index.js","./loader":"./loader.js","./loader.js":"./loader.js"},"gitHead":"18b7eed5a2195a6864ff84052bca29b73670f73a","scripts":{"test":"node test.js"},"_npmUser":{"name":"keijokapp","email":"keijo.kapp@gmail.com"},"repository":{"url":"git+https://github.com/arbendium/mock-esm.git","type":"git"},"_npmVersion":"10.2.0","description":"A small mocking library for Node ESM based codebase","directories":{},"_nodeVersion":"20.8.0","_hasShrinkwrap":false,"devDependencies":{"@arbendium/mock-esm":"."},"_npmOperationalInternal":{"tmp":"tmp/mock-esm_2.2.1_1697201170311_0.5943948005086646","host":"s3://npm-registry-packages"}},"2.3.0":{"type":"module","name":"@arbendium/mock-esm","version":"2.3.0","description":"A small mocking library for Node ESM based codebase","keywords":["mock","esm","loader","test"],"author":{"name":"Keijo Kapp","email":"keijo.kapp@gmail.com"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/arbendium/mock-esm.git"},"exports":{".":"./index.js","./loader":"./loader.js","./loader.js":"./loader.js"},"main":"index.js","scripts":{"test":"node --test test/synchronous.js test/asynchronous.js"},"devDependencies":{"@arbendium/mock-esm":"."},"gitHead":"d738ae1ede6a78b41fbf29e384e78879cc0bbcd4","types":"./index.d.ts","_id":"@arbendium/mock-esm@2.3.0","bugs":{"url":"https://github.com/arbendium/mock-esm/issues"},"homepage":"https://github.com/arbendium/mock-esm#readme","_nodeVersion":"26.7.0","_npmVersion":"12.0.2","dist":{"integrity":"sha512-yX28kzxWSvbmhHFBlayJ0k7RBCEoFGgoc0e3iyEDLTvojsXRYXqLO4EvXFuq51QgrKEg0zHsItukJI8ITwRpBQ==","shasum":"c50a0934141fe876df6b3837311c34164ff29430","tarball":"https://registry.npmjs.org/@arbendium/mock-esm/-/mock-esm-2.3.0.tgz","fileCount":6,"unpackedSize":8451,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBTZttyWucBhbfoXIJ1Sqo7VCxxirydEQwTg8Thi0dp2AiEA15U4vRiYBP6xUUU19pK9YUv/4vkocu/7xhMVuW15CU0="}]},"_npmUser":{"name":"keijokapp","email":"keijo.kapp@gmail.com"},"directories":{},"maintainers":[{"name":"keijokapp","email":"keijo.kapp@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mock-esm_2.3.0_1787328240083_0.4195979798225731"},"_hasShrinkwrap":false}},"time":{"created":"2023-10-13T11:56:00.679Z","modified":"2026-08-21T16:04:00.372Z","2.2.0":"2023-10-13T11:56:00.953Z","2.2.1":"2023-10-13T12:46:10.481Z","2.3.0":"2026-08-21T16:04:00.228Z"},"bugs":{"url":"https://github.com/arbendium/mock-esm/issues"},"author":{"name":"Keijo Kapp","email":"keijo.kapp@gmail.com"},"license":"ISC","homepage":"https://github.com/arbendium/mock-esm#readme","keywords":["mock","esm","loader","test"],"repository":{"type":"git","url":"git+https://github.com/arbendium/mock-esm.git"},"description":"A small mocking library for Node ESM based codebase","maintainers":[{"name":"keijokapp","email":"keijo.kapp@gmail.com"}],"readme":"#### A small mocking library for Node ESM based codebase\n\n**Warning:** This library uses [customization hooks](https://nodejs.org/api/module.html#customization-hooks) which, at the time of writing, is in a \"Release candidate\" stage.\n\n## Usage\n\n```js\nimport { registerHooks } from \"node:module\";\nregisterHooks(await import(\"@arbendium/mock-esm/loader\"));\n\nimport mock from '@arbendium/mock-esm';\n\nconst mockedConfig = { listen: { port: 8080 } }\n\nconst { load, cleanup } = await mock(import.meta.url, {\n\t'./config.js': {\n\t\tdefault: mockedConfig\n\t}\n});\n\nconst app = await load('./app.js');\ncleanup();\n```\n\n#### API\n\n`mock(entryModuleUrl, mocks)`\n\nInitialize mock context.\n\n - `entryModuleUrl` - the root module url from which relative module specifiers are derived, usually `import.meta.url`\n - `mocks` - module specifier -> exports maps. Exports are always identifier -> value maps, even for CommonJS modules (since all mocks are exposed as ESM). Use `default` identifier for CommonJS exports.\n\n`load(specifier)`\n\nLoad module in given mock context and given specifier relative to entry module.\n\n`cleanup()`\n\nDelete mocked modules from internal map for garbage collection. This is usually safe to call right after all needed modules are loaded, except when there are further dynamic imports of mocked modules. In this case, these imports will fail with exception.\n\nLimitations/notes:\n\n - Modules imported from CommoonJS or built-in modules cannot be mocked because Node does not use custom loader for these.\n - Every `mock` call creates new namespace in module cache, which means all modules reexecuted, except modules imported from unmocked CommonJS & built-in modules. This is desired behaviour for me. If you need to cache certain modules, import them separately and pass as mocks.\n - The library does not account for module specifiers with query parameters. I guess it's easy to fix but I have no need for this at the moment.\n","readmeFilename":"README.md"}