Closed cymen closed 10 years ago
So reading: https://github.com/substack/node-resolve
Looks like require
takes an option hash as second parameter and we could set opts.path
-- would be nicer to have a way to tell node globally "add these three paths to your fallback" so looking for that way to do it.
The answer appears to be NODE_PATH
environmental variable: http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
I'm going to see if I can hook that up to work with the configured asset paths we have already.
Unfortunately, it looks like support for NODE_PATH
went away -- it isn't working locally.
Update: might be wrong, exploring.
require() is expected to be relative path in node. Its a large caveat, but you can get around this by just having your spec files require relative paths. They tend to be ugly, but it works.
heres an example of a spec file I have
var tracking = require('../../../../app/assets/javascripts/shared/modules/tracking');
describe('tracking.js', function(){
it('should return an object', function() {
expect(typeof tracking).toBe('object');
});
...
});
});
That is what I was doing but it doesn't work with jasmine-rails -- it copies files to another directory breaking the relative path. It works fine with access /specs
while running the web server but running the rake task like so bundle exec rake spec:javascripts
fails.
Setting NODE_PATH
works however browserify --list fails with it although plain browserify works. It seems to be a browserify bug.
I opened a bug report on browserify for this:
https://github.com/substack/node-browserify/issues/726
I am starting to wonder if we're better off wrapping browserify so we can use the function browserify and not the command line interface.
I fixed the bug in node-browserify (actually, module-deps) -- with v3.41.0 we're working again!
So say I put a spec in
spec/javascripts/a_spec.js
then I want to dovar a = require('a');
however I can't becausea.js
is inapp/assets/javascripts
. Browserify-rails tries to open it relative to the location of the spec file and then bombs out when it doesn't find it. It should instead try to open it relative to the configured asset paths.