node.js - How to run NodeJS unit tests with a different NODE_PATH -
the question
can run unit tests within node/gulp have different node_path has been inherited environment?
the issue
i have project being run within rhino based application, require
loads scripts set of defined locations.
i want have unit tests components. in order run tests need able call scripts node environment. ends error similar this:
error: cannot find module 'lib/foo/foo.js'
this because scripts contain require(foo/foo)
... fine if node_path
have contained lib
. issue here want folder present unit tests, not other gulp tasks.
i guess issue facing test runners came across (e.g. karma) browser based. question might be: is there test runner runs pure nodejs tests?
well can along lines of
node_path=node_path:/path/to/lib npm test`.
node_path
environment variable. rely on value persists through login shell profile. can set/unset/change suits you.
to set environment variable duration of execution of 1 command...
variable=value command <args...>
to set environment variable duration of shell session i.e. until exit/logout or reset shell...
export variable=value command <args...>
to make persist through shell sessions, have add export varibale=value
your
.bashrc
or
.bash_profile
or
/etc/profile
or
file inside /etc/profile.d/
depending on preference , environment.
edit: have made unfair assumption using linux or mac. apologize if not case. windows, can like
%node_path%=%node_path%;\path\to\lib\
or something. can go system properties -> advanced settings -> environment variables , set/unset/change globally persistent environment variables there.
edit #2: refactored clarity.
Comments
Post a Comment