jasmine-node
jasmine-node copied to clipboard
Can not require modules from node_modules
Hello,
i cant get this working:
modules/testRequire.js
define(function () {
return require("express");
});
setup.js
var requirejs = require('requirejs');
requirejs.config({
nodeRequire: require,
baseUrl: "/Users/Manuel/Dropbox/Synced/Git/require/modules"
});
tests/sampleSpec.js
requirejs(["testRequire"],function(test){
describe("check if object", function () {
it("hallo ",function(){
waitsFor(function() {
return expect(test).toEqual(jasmine.any(Object));
}, "The Value should be incremented", 750);
});
});
});
it run:
jasmine-node --requireJsSetup setup.js --captureExceptions /Users/Manuel/Dropbox/Synced/Git/require/tests
and get
Error: Tried loading "express" at /Users/Manuel/Dropbox/Synced/Git/require/modules/express.js then tried node's require("express") ....
any ideas why it cant find express in /Users/Manuel/Dropbox/Synced/Git/require/node_modules ?
Thx a lot
I believe it considers the test file the root so it will look adjacent and down the directory for a modules directory. Try using relative pathing to look up using ./../ and ./../ combinations
But why should someone have different modules for testing? Where should i use relative pathes?
Require will take a relative path. so require(./../modules/express) should look up one directory. Can you change modules back to node_modules? Node, and it's various modules, expect that hard coded directory to be there and it may be easier if you use that directory.
I dont get what you mean in any way, sry.
I thing is if i run the same code without jasmine-node and instead use node like that:
node app.js
app.js
var requirejs = require('requirejs');
requirejs.config({
nodeRequire: require,
baseUrl: "/Users/Manuel/Dropbox/Synced/Git/require/modules"
});
requirejs( ['testRequire'], function( express ) {
console.log(express);
});
it works without error, it seams like the jasmine-node replaces the require, and uses wrong pathes...
This should be marked as a bug since it does not conform to the normal Node behavior. Node looks at current directory and then traverses up, not down.
Yes. I agree this is a bug. It looks in the global jasmine-node directory (and parents) instead of node_modules itself. To test this out for yourself, try
define([
'gaze'
],function(gaze) {
return "anything";
});
I use gaze in my example because I don't use that package in my own app but it's a dependency for jasmine-node.
For me, it looks through
paths:
[ '/usr/local/lib/node_modules/jasmine-node/bin/node_modules',
'/usr/local/lib/node_modules/jasmine-node/node_modules',
'/usr/local/lib/node_modules',
'/usr/local/node_modules',
'/usr/node_modules',
'/node_modules' ] },
The way to solve this issue is to install jasmine-node locally, not -g
, and run it from there (node_modules/jasmine-node/bin/jasmine-node
). That way, it will search ./node_modules
, ../node_modules
, ../../node_modules
, etc. and eventually find your app's node_modules dir.