Skip to content

How do I debug a failing vi.mock() resolution? It silently can't find __mocks__ #7592

Answered by fregante
fregante asked this question in Q&A
Discussion options

You must be logged in to vote

The solution was to start a node debugger in VS Code and wade my way through the code. There's no debugging/logging anywhere in that function. I ended up on the chunk:

  const dir = dirname(path);
  const baseId = basename(path);
  const fullPath = resolve(dir, "__mocks__", baseId);
  return existsSync(fullPath) ? fullPath : null;

Where I was able to determine that the expected path was not:

dist/__mocks__/@org/local-util/file.js

but

dist/@org/local-util/__mocks__/file.js

because the module was reported as not "external"

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fregante
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant