Loading modules in JsTestDriver

44 views
Skip to first unread message

Ken Cooper

unread,
Dec 28, 2013, 10:38:14 AM12/28/13
to js-test...@googlegroups.com
I'm using JsTestDriver to test code written for Parse's CloudCode, and as the project grows, I'm segmenting the code into modules. Some of the modules have nested dependencies (e.g. a common util module), so they need to load recursively. Some of these modules are loaded by various tests, so I need to figure out how to load them from JsTestDriver.

Parse CloudCode uses a common.js style require(), which I'm attempting to emulate when running in the context of the browser. I've implemented the emulation like so:

    function require(filename)
    {
        var savedExports = window.exports;
        window.exports = {};

        // open and send a synchronous request
        var xhrObj = new XMLHttpRequest();
        xhrObj.open('GET', filename, false);
        xhrObj.send('');
        // add the returned content to a newly created script tag
        var se = document.createElement('script');
        se.type = "text/javascript";
        se.text = xhrObj.responseText;
        document.getElementsByTagName('head')[0].appendChild(se);

        var returnVal = window.exports;
        window.exports = savedExports;

        return returnVal;
    };

Sadly, the response text is never the requested module .js file, but always a full html document for the test harness itself. My jsTestDriver.conf contains the following entries:

load:
  - test/lib/parse-1.2.13.js
  - test/lib/require-lite.js
  - cloud/utils.js
  - cloud/backgroundJob.js
  - cloud/models/*.js

test:
  - test/*.js

serve:
  - cloud/*.js
  - cloud/models/*.js

Any thoughts on what I'm doing wrong?

Cory Smith

unread,
Dec 28, 2013, 1:19:39 PM12/28/13
to js-test...@googlegroups.com
Try adding '/test/' to the filename. All the test and serve resources are exposed under that prefix.
--
You received this message because you are subscribed to the Google Groups "JsTestDriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to js-test-drive...@googlegroups.com.
To post to this group, send email to js-test...@googlegroups.com.
Visit this group at http://groups.google.com/group/js-test-driver.
For more options, visit https://groups.google.com/groups/opt_out.

Ken Cooper

unread,
Dec 29, 2013, 11:24:28 AM12/29/13
to js-test...@googlegroups.com
Thanks, Cory.
Reply all
Reply to author
Forward
0 new messages