I am having a gulp based project, and use browserify
and debowerify
to build the application. The application
- Depends on Backbone - installed as bower component.
- Has some additional domain classes which
require
sbackbone
.
I build 1
above as vendor.js
and 2
above as app.js
,and include both these files in the html file, which runs fine
Now I am about to set up testing using tape, and I started off with testing the model
class:
var todoModel = require('../../libs/todo/model/todo.js').Todo;
var test = require('tape');
var aTodo = new todoModel();
test('todo model test',function(t){
eyes.inspect(atodo, "one");
t.equal(1,one.valueOf(),'one should be equal to one');
t.end();
});
libs/todo/model/todo.js:
var Backbone = require('backbone');
var Storage = require('../helpers/storage.js');
var Todo = Backbone.Model.extend({
...
})
When I run this test as tape test/model-test.js
, I am getting an (expteced) error as
Error: Cannot find module 'backbone'
. So now, how do I make the bower candidate backbone
be available to my node.js test script
Note: A simple workaround is to add the backbone
as a node dependency, but what if a hypothetical library is available only in bower?
Cant you try
?
Anyway I think this is more related on how to setup your test environment, not sure if you are using jasmine or others, but with jasmine I had to add an angularMock file to be able to test angular for example.
I can not understand why would you require backbone from your backend, if its intended to be used in the frontend, unless is for testing purposes as you mention, then the question should be more related to how to setup the test than to require backbone