1. #1
    Sencha Premium Member
    Join Date
    Jan 2013
    Posts
    3
    Vote Rating
    1
    dreebit is on a distinguished road

      1  

    Default Unanswered: Setup JSTestDriver with ExtJS 4 & jasmine

    Unanswered: Setup JSTestDriver with ExtJS 4 & jasmine


    Hi,

    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) .. 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:

    Error:
    Code:
    localhost:9876/slave/page/RUNNER/id/1359996445901/mode/quirks/upload_size/50/refresh/1359996450734/load_type/app/controller/main
    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)
    Code:
    server: http://localhost:9876
    
    
    load:
      - 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
    
    
    test:
      - app-test/specs/identity.js
    
    
    serve:
      - app/**.js

  2. #2
    Sencha Premium Member
    Join Date
    Apr 2011
    Location
    Chicago, IL
    Posts
    65
    Answers
    3
    Vote Rating
    11
    ccg will become famous soon enough

      1  

    Default JsTestDriver server adds /test to your app's URL paths

    JsTestDriver server adds /test to your app's URL paths


    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:

    Code:
    load:
    - lib/jasmine-1.3.1/jasmine.js
    - lib/JasmineAdapter.js
    - sdk/sencha-touch-all.js
    - test/jstdExtLoaderConfig.js
    #- app.js
    
    test:
    - test/jasmine/spec/*.js
    
    serve:
    - 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:
    Code:
    Ext.Loader.setConfig({
        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.

  3. #3
    Sencha Premium Member
    Join Date
    Apr 2011
    Location
    Chicago, IL
    Posts
    65
    Answers
    3
    Vote Rating
    11
    ccg will become famous soon enough

      0  

    Default Skipping app.js

    Skipping app.js


    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.).

  4. #4
    Sencha Premium Member
    Join Date
    Jan 2013
    Posts
    6
    Vote Rating
    1
    jamie.priest is on a distinguished road

      0  

    Default


    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/j...-jstd-adapter/ with jstestdriver 1.3.5. However even using the config you have suggested set up I still get the
    Code:
    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

  5. #5
    Sencha Premium Member
    Join Date
    Apr 2011
    Location
    Chicago, IL
    Posts
    65
    Answers
    3
    Vote Rating
    11
    ccg will become famous soon enough

      0  

    Default


    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. :-(
    Last edited by ccg; 14 May 2013 at 9:20 PM. Reason: Stupid UI posted before I was done typing.

  6. #6
    Sencha User
    Join Date
    Jul 2012
    Posts
    6
    Vote Rating
    0
    WitteStier is on a distinguished road

      0  

    Default


    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/1...sdt-running-ja

  7. #7
    Sencha Premium Member
    Join Date
    Jan 2013
    Posts
    6
    Vote Rating
    1
    jamie.priest is on a distinguished road

      1  

    Default


    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.