It builds on top of @dgobaud's PR, and adds tests.
There might be some rare cases when you want to use module-alias while running in a REPL (e.g. $ node -i). In that case, require.main is undefined.
This means introducing a way of having "require.main" undefined in our module. The require function is different between the test module and the module under test, so we can't just do require.main = null in the test function, as it won't affect the "require" function of the prod code. So we need to introduce a helper function for evaluating require.main, and inject a flag in the test module when running the tests.
Fixes #65
It builds on top of @dgobaud's PR, and adds tests.
There might be some rare cases when you want to use module-alias while running in a REPL (e.g.
$ node -i
). In that case,require.main
is undefined.This means introducing a way of having "require.main" undefined in our module. The require function is different between the test module and the module under test, so we can't just do
require.main = null
in the test function, as it won't affect the "require" function of the prod code. So we need to introduce a helper function for evaluating require.main, and inject a flag in the test module when running the tests.