Skip to content

Commit

Permalink
feat: added trace to debug output for require()
Browse files Browse the repository at this point in the history
  • Loading branch information
mhweiner committed Jul 28, 2024
1 parent 1b24e13 commit 961a507
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ Module.prototype.require = new Proxy(Module.prototype.require, {
// eslint-disable-next-line no-underscore-dangle
const absolutePath = Module._resolveFilename(name, thisArg);
const mock = registeredMocks.get(absolutePath);
const callerFile = callsites()[1].getFileName() as string;

if (mock) {

debug(`require(): REPLACING ${name} [${absolutePath}] WITH MOCK`);
debug(`require(): REPLACING ${name} [${absolutePath}] WITH MOCK\n at ${callerFile}`);
registeredMocks.delete(absolutePath);
return mock.mockReturnValue;

} else {

debug(`require(): ${name} [${absolutePath}]`);
debug(`require(): ${name} [${absolutePath}]\n at ${callerFile}`);

}

Expand Down

0 comments on commit 961a507

Please sign in to comment.