mustafa5253 / js-test-driver

Automatically exported from code.google.com/p/js-test-driver
0 stars 0 forks source link

Issue with using RequireJs #418

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I've followed the thread 
(https://groups.google.com/forum/#!topicsearchin/js-test-driver/requirejs$20/js-
test-driver/-2X9uJ-A0No) to setup my testing environment using jsTestDriver + 
REquireJs + Mocha. Here is what my configurations look like:

**** jsTestDriver.conf ****
server: http://localhost:9876

load:
 - src-test/libs/mocha.js
 - src-test/libs/chai.js
 - src-test/libs/MochaAdapter.js
 - libs/require.js
 - src-test/config.js
 - common/store.js
 - src/PostingModelNew.js

test:
 - src-test/PostingModelNew-spec.js

serve:
 - common/store.js
 - libs/backbone.js
 - src-test/libs/mocha.js
 - src-test/libs/chai.js
 - libs/jquery.js
 - libs/rosie.js
 - src-test/data/dataFactory.js
 - libs/require.js
 - src-test/config.js

*** config.js (configuration for RequireJs ****

require.config({
  baseUrl:"./",
  paths: {
    jquery: '/test/libs/jquery',
    backbone: '/test/libs/backbone',
    require: '/test/libs/require',
    mocha: '/test/src-test/libs/mocha',
    chai: '/test/src-test/libs/chai',
    MochaAdapter: '/test/src-test/libs/MochaAdapter',
    Store: '/test/common/store'
    ,Rosie: 'test/libs/rosie'
    ,DataFactory: '/test/src-test/data/dataFactory'   
  }
});

**** Sample Module ****
define('PostingModelNew', function (require) {

    var store = require("Store");
    var backbone = require("libs/backbone");

    var GetName = function(){
        return "Posting Model";
    };

    var AddToStore = function(postType, property, value){
        store.add(postType + '_' + property, value);
        return store.get(postType+ '_' + property);
    };

    var postingModel = {};

    postingModel.Name = GetName();
    postingModel.AddToStore = function(postType, property, value){
        return AddToStore(postType, property, value);
    };
    postingModel.GetStoreCount = function(){
        return store.count();
    };
    postingModel.ClearStore = function(){
        store.removeAll();
    }
  return postingModel;
});

*** Test Module ***
mocha.setup('bdd');
expect = chai.expect;
should = chai.should();
require(["PostingModelNew"], function (PostingModelNew) {

//    var dataFactory = require("/test/src-test/data/dataFactory.js");

    describe("PostingModelName", function () {
        it("should return Quan!", function () {
            console.log(PostingModelNew.Name);
            expect(PostingModelNew.Name).to.eql("Posting Model");
        });
    });

    describe("LocalStorageTests", function () {
        beforeEach(function () {
            PostingModelNew.ClearStore();
        });

        it("Local Storage should successfully add item to its store.", function () {
            var value = PostingModelNew.AddToStore('load', 'length', 99);
            expect(parseInt(value)).to.eql(99);
        });

        it("Local Storage should increment count correctly.", function () {

            PostingModelNew.AddToStore('load', 'length', 99);
            PostingModelNew.AddToStore('load', 'weight', 1000);
            var count = PostingModelNew.GetStoreCount();
            expect(count).to.eql(2);
        });
    });
});

*** Folder Structure ***
- Project Root
  -- libs <folder>
     -- config.js
     -- backone.js
     -- rosie.js
     -- underscore.js
     -- etc...
  -- src <folder>
     PostingModelNew.js
  -- src-test <folder>
     -- common <folder>
     -- data <folder>
        -- dataFactory.js
     -- libs <folder>
        -- chai.js
        -- mocha.js
        -- MochaAdapter.js
        -- sinon-chai.js
        -- sinon.js
     -- config.js
     -- PostingModelNew-spec.js
  -- jsTestDriver.conf
  -- JsTestDriver.jar

That seems to work for the most part except for the following:

1. FireFox seems to complain about this error every now and then eventhough it 
passed the tests:

Firefox 17.0 Windows: Run 4 tests (Passed: 3; Fails: 0; Errors 1) (0.00 ms)
    error loading file: /test/src-test/config.js:156: Error: Mismatched anonymous define() module: function () {
      return definition();
    }
http://requirejs.org/docs/errors.html#mismatch

2. It seems that the -spec.js module did not like how I tried to reference the 
'dataFactory' module. I've tried:

// PostingModelNew-spec.js
require(["PostingModelNew"], function (PostingModelNew) {

   - var dataFactory = require("/test/src-test/data/dataFactory.js") 
   [OR] var dataFactory = require("DataFactory");

I am stuck as to how to can reference a library in my -spec file. Perhaps I 
didn't have the path configured correctly.

I would very much appreciate any help I could get in order to solving these 
issues.

Thanks,
Quan

What version of the product are you using? On what operating system?

I am using v.1.3.5 on Windows 7 Ultimate (x64)

Original issue reported on code.google.com by QT.Ngu...@gmail.com on 10 Jan 2013 at 11:20