View Full Version : Setup JSTestDriver with ExtJS 4 & jasmine

4 Feb 2013, 9:07 AM

I'm trying to setup unit-tests in my existing ExtJS 4.1 project. I'm using jasmine for logical unit testing, and it's working fine so far. (testing in browser and via terminal)...

Now, I'm trying to setup JSTestDriver for better IDE integration. I followed already an old thread (here (http://www.sencha.com/forum/showthread.php?148326)) .. but didn't get it to work. JSTestDriver-Server is working fine, but, as I need to load my ExtJS-files dynamically, I get some errors on the jstd-server while it's async loading the required js-files:


Uncaught SyntaxError: Unexpected token <

Does anybody have experiences with JSTestDriver & jasmine & ExtJS? I'm using jstd in Webstorm 5. Do I need to setup Ext.Loader in a special way?

My JSTestDriver.conf (located in the root folder)

server: http://localhost:9876

- ext/ext-all.js
- app/controller/main/IdentityManager.js
- app-test/lib/jasmine-1.3.1/jasmine.js
- app-test/lib/jasmine-1.3.1/JasmineAdapter.js

- app-test/specs/identity.js

- app/**.js

13 Apr 2013, 12:37 PM
I just ran into the same problem this morning trying to integrate my Jasmine unit tests with my IntelliJ IDE through JsTestDriver for a Sencha Touch 2.0 app using dynamic loading. It turns out that the JsTestDriver web server changes the path to your JS files, so you have to modify your Ext.Loader paths.

I had the same problem ("Uncaught SyntaxError: Unexpected token <"). The problem is that the Sencha dynamic loader sends an AJAX request to load a JS file, but it gets back an HTML document from JsTestDriver's embedded web server, and the Sencha framework then tries to call `eval` on the HTML string, which causes that '<' syntax error.

It turns out that JsTestDriver's built-in web server serves your files under a prepended "/test" path in the URL. So if you configure your classes to be available as, say, app/controller/AppController.js, then it'll actually be served as /test/app/controller/AppController.js.

I solved that problem with a custom config of Ext.Loader just for JsTestDriver. First, the jsTestDriver.conf:

- lib/jasmine-1.3.1/jasmine.js
- lib/JasmineAdapter.js
- sdk/sencha-touch-all.js
- test/jstdExtLoaderConfig.js
#- app.js

- test/jasmine/spec/*.js

- app/config/*.js
- app/controller/*.js
- app/model/*.js
- app/store/*.js
- app/util/*.js
- app/view/*.js

Note that I currently have this file at the root of project, although I'd like to move it into the test/ folder once I figure out how to get everything working.

My test/jstdExtLoaderConfig.js looks like the following:

enabled: true,
paths: {
Ext: 'sdk',
App: '/test/app'

Note that in the "paths" config, I had to change {App: 'app'}, to {App: '/test/app'} to get it to load my app's classes correctly. It had to be the absolute path "/test/app", not the relative path "test/app", to work correctly.

You might notice that I have app.js commented out in my jsTestDriver.conf above. I still haven't gotten this thing to load that file correctly, so any tests that depend on the top-level application class are still broken. When I tell it to load app.js, for some reason, it tries to load it from the wrong path and breaks the whole thing. For reasons I haven't figured out yet, instead of loading the correct path, project/app.js, it attempts to load project/archive/app.js, which doesn't exist. I have no clue which part of this setup is sticking "archive" into the path or why.

19 Apr 2013, 11:42 AM
After I posted that previous message, I thought about it some more and decided that not being able to load app.js is not really a problem. With Jasmine, I'm writing unit tests, not integration tests, so the classes under test really should not be coupled to anything that happens in app.js.

So far, it's all working reasonably well, although I have to be very careful about how I include my utility classes (anything that's not a controller, model, store, or view). Sometimes those classes are not loaded despite being Ext.require'd, and when that happens, instead of getting useful info from the tests, jsTestDriver just hangs forever. I've worked around it by manually forcing those classes to be parsed, but it's not ideal, because I'm duplicating configuration in different places (I need "load:" config for those classes in jsTestDriver.conf, SCRIPT tags for those classes in Jasmine's index.html, etc.).

22 Apr 2013, 2:42 PM
Just wondering what set-up you are using? I've tried to set up a similar thing on my machine using 6.01 of Webstorm, using Jasmine 1.3.1 and https://nodeload.github.com/ibolmo/jasmine-jstd-adapter/ with jstestdriver 1.3.5. However even using the config you have suggested set up I still get the

Uncaught SyntaxError: Unexpected token <
error. Oh I'm also on OSX. I can definitely get at my classes if they are placed in load: but I cannot seem to get the Ext.Loader to work

14 May 2013, 9:11 PM
If you're getting "
Uncaught SyntaxError: Unexpected token <
", then you're probably trying to load classes with Ext.Loader with the wrong path config. Ext.Loader is trying to load a JS class file with an AJAX call and then calling JavaScript's `eval` on the result, but the result is actually an HTML page returned for a 404 response instead of the literal JS source file that the loader is expecting. In my case, after debugging for a while, I was able to figure out that the URL needed to have /test prepended to it.

I'm using IntelliJ 12.1.x and Jasmine 1.3.1 with IntelliJ's built-in JsTestDriver server (and Chromium/Dartium as the captured browser for running tests), but so far the whole async class-loader thing seems to be pretty flaky and fragile under JsTestDriver. I spent a lot of time today trying to figure out why calling Ext.getStore('SomeUniqueStoreId') causes JsTestDriver to hang for 30 seconds and then throw a BrowserPanicException. I never figured it out; I just worked around it by forcing JsTestDriver to preload all the Model classes and the Store class that was causing problems... which is really annoying, because one of the reasons to use Ext.Loader is so that you DON'T have to manually curate a dependency-ordered list of classes to preload. :-(

25 Jul 2013, 6:36 AM
Hi, is there anyone who is able to test Ext.Application ?
It looks like JSTD does not wait until the application is launched.

No problems with Jasmine and a HTML spec runner

See http://stackoverflow.com/questions/17820893/typeerror-cannot-read-property-launched-of-null-in-netbeans-jsdt-running-ja

29 Dec 2013, 2:27 PM
Yep I think you were right, thanks for the response. Perhaps a little late to respond, but worth probably pointing out that I eventually moved onto Karma with Webstorm 7. We have our tests up and running nicely and it's pretty stable. I never found JSTestdriver and Webstorm 6 would behave for any length of time.