0

I am having a gulp based project, and use browserify and debowerify to build the application. The application

  1. Depends on Backbone - installed as bower component.
  2. Has some additional domain classes which requires backbone.

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?

gotofritz
  • 3,341
  • 1
  • 31
  • 47
jacquard
  • 1,307
  • 1
  • 11
  • 16
  • As user of Grunt I would recommend you [grunt-browserify-bower](https://www.npmjs.org/package/grunt-browserify-bower) module rather than `debowerify`. I am not sure if Gulp has anything similar. It basically loops through Bower packages and makes the bundle out of them. – FredyC Aug 27 '14 at 08:32

1 Answers1

0

Cant you try

require('./your/path/to/backbonejs/probably/bower_components/etc');

?

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

Santiago Rebella
  • 2,399
  • 2
  • 22
  • 29
  • No, because the `require('backbone')` is inside the todo.js, which is the source file that I am trying to test. As I mentioned above, the source files already are bundled and executed fine using browserify. Thanks! – jacquard Aug 26 '14 at 18:47
  • then unless you installed 'backbone' using npm install in your node, the error message is correct – Santiago Rebella Aug 26 '14 at 18:50