This repository was archived by the owner on Mar 15, 2021. It is now read-only.
  
  
  
  
  
Description
When trying to reRequire a file named index that is in the local path, reRequire will instead return what mock-require exports, specifically the startMocking function.
Example code:
index.js:
const fs = require('fs')
// ...
module.exports = { fs }
test.js:
const mock = require('mock-require')
mock('fs', {})
const index = mock.reRequire('./index')
console.log(index)
Expected output:
Actual output:
function startMocking(path, mockExport) {
  const calledFrom = getCallerFile();
  if (typeof mockExport === 'string') {
    mockExport = getFullPathNormalized(mockExport, calledFrom);
  }
  pendingMockExports[getFullPathNormalized(path, calledFrom)] = mockExport;
}
Based on looking at the code (and specifically at getFullPath and isInNodePath, it looks like any file that can be resolved from the mock-require package will cause it to return that file rather than the actual local file.