-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Hi,
I was having some trouble using the nodejs plugin and relative paths with esm and rewiremock.module(). I'm unable to provide a minimal case to reproduce the problem I'm having, but I'll try to explain:
lib/foo.jsis a modulelib/baz.jsis another modulelib/bar/quux.jsis yet another modulelib/bar/quux.jsdepends onlib/foo.jslib/foo.jsdepends onlib/baz.jstest/bar/quux.spec.jsis a test forlib/bar/quux.js, which uses rewiremock to stublib/foo.jstest/foo.spec.jsis a test forlib/foo.js, which uses rewiremock to stublib/baz.js
This is how I'm using rewiremock:
- stubs uses module paths relative to the test files
- I'm using
overrideEntryPoint()in a separate test helper file to load rewiremock - I'm running my tests via
mocha -r esm, and with thenodejsplugin enabled. - I'm using the
rewiremock.module(() => import('/path/to/module')syntax.
If I run each of those two tests individually, they both pass. If I run them together, test/bar/quux.spec.js runs first, then test/foo.spec.js runs. The latter fails, as it can't find lib/baz.js, which is stubbed via the relative path ../lib/baz.
In the resulting stack trace, test/bar/quux.spec.js appears at the top. Running the debugger, when test/foo.spec.js is trying to stub ../lib/baz, the "parent" module is test/bar/quux.spec.js, which seems incorrect.
A couple things I've noticed:
- If I disable the
nodejsplugin and use paths relative to the files under test (e.g.,lib/foo.jsstubs./bazinstead of../lib/baz), all tests pass together (in other words, I'm not blocking on a fix) - Using
rewiremock.enable()paired withrewiremock.disable()seems to have no effect whatsoever
So my question is if I should be using the nodejs plugin, or a different plugin, and how can I specify relative-to-test-file module paths to be stubbed? Is there a bug here?
Thanks for your work on this module!