UNPKG

@xutl/test-modules

Version:

Module Substitutor for Testing

13 lines (11 loc) 358 B
const { Module } = require('node:module'); const { pathToFileURL } = require('node:url'); const { substitute, pathOf } = require('./mockdata.cjs'); const findPath = Module._findPath; Module._findPath = (id, paths, ...args) => { id = substitute( id, (paths ?? []).map((p) => `${pathToFileURL(p)}/`), ); return findPath(pathOf(id), paths, ...args); };