0

Right now i have grunt setup to watch for file changes and feed them to mocha, and mocha runs the tests. The problem is when modules include something like "nw.gui" the test case cannot find them. Is there any way to get around that, some way that i can include it?

//indexeddb.spec.js

var assert = require("assert");
var IndexedDB = require("../scripts/indexeddb");
db = new IndexedDB();
console.log(db);
describe('IndexedDB', function(){
  describe('initialize', function(){
    it('Should throw an error when the paramaters are null', function(){
      expect(db.initialize()).to.throwError();
    });
  });
});

//indexeddb.js

module.exports = exports = function(){
    var indexedDB = require("nw.gui").Window.get().window.indexedDB;
    var _ = require("../bower_components/underscore/underscore.js")
    this.initialize = function(databaseName,version,schema) {
    }
}

Should i do this differently? I did think about running the tests in a gui window in webkit, but that would require that i include all the spec file's on the page and reload the page every time i wanted to run the test. With grunt and watch i was trying to get it to run the test for each file when i edited either the spec or the src file.

I will also need to test the html/js/backbone pages that i open in a webkit window.

Thanks for any insight.

1 Answers1

2

Code example at https://github.com/varunvairavan/node-webkit-unit-testing

Found a way to run test's on node webkit, with a watch to reload the page on file changes.

I was going through this post https://github.com/visionmedia/mocha/issues/960 when i found a link to https://github.com/BenoitZugmeyer/chwitt/tree/5f9bc6c0b8c0328f1dc06a554e9fdd3a969c36ae/tests

The way it works is, create a new node webkit app in your test directory, it then includes all the files in that directory that end with .spec.js and runs the tests in them. It also does a page reload on file changes in the source/test folder.

I had my files in sub directories in the test folder so i used the walk function from node.js fs.readdir recursive directory search to find all the files ending with ".spec.js".

Community
  • 1
  • 1
  • 1
    Hey Varun! You should consider an [edit] to this post with a code example. It will "bump" the post back to the top of the main page where others can then see and vote on it. :) – jamesmortensen Apr 05 '14 at 20:48