Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better missing module message for td.replace() #363

Merged
merged 5 commits into from
Apr 29, 2018

Conversation

searls
Copy link
Member

@searls searls commented Apr 29, 2018

Resolves #355.

When calling td.replace('./no-such-thing'), write a meaningful error message.

Before:

TypeError: Cannot read property 'join' of undefined

After:

Error: testdouble.js - td.replace - failed to load the module being replaced.

Why am I seeing this?
------------------------
You called `td.replace('./no-such-thing')`, but we failed to locate that
module. How td.replace() works is that it first loads the actual module
being faked in order to properly imitate it (i.e. to see whether it exports
a default function, or an object of other named functions, and so on).

How do I fix it?
----------------
You probably specified a path that could not be resolved relative
to your test file (or whatever listing from which  you called `td.replace()`).
Be sure you didn't specify the path relative to the subject under test!

First, we tried to absolutify that path and require it, with:
  `require('/Users/justin/code/testdouble/testdouble.js/no-such-thing')`

But requiring that absolute path threw this error:
  "Cannot find module '/Users/justin/code/testdouble/testdouble.js/no-such-thing'"

Next, we tried to require it as you specified it (in case it's the name of
a Node.js built-in or an npm package), with:
  `require('./no-such-thing')`

But that threw this error:
  "Cannot read property 'join' of undefined"

Make sure the path specified exists (either relative to the call-site or
as an installed module). If any of the paths above seem to be internal to
testdouble.js or a dependency, that's probably a bug and you should open an
issue. (see: https://github.com/testdouble/testdouble.js#module-replacement-with-nodejs )

I want better coffeescript-like template strings for
all these messages tbqh. gonna go try those again
Fixes #355

add common-tags for nicer heredocs
@searls searls merged commit b93fbeb into master Apr 29, 2018
@searls searls deleted the better-missing-module-message branch April 29, 2018 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve td.replace error message for incorrect module path
1 participant