4

I have an application built using ArcGIS Javascript API and I've been adding tests using intern. I run it under IIS in Windows 7 while developing. I had no trouble getting the intern tutorial working when getting started and after looking at How to specify alternate loader for intern I was able to set the loader in client.html to <script src="http://js.arcgis.com/3.7/"></script> and I was able get my tests running but only after I changed the path in both the query string and in intern.js to include the parent path as defined in IIS.

For example, say my app is hosted at http://localhost/testApp/mySite and I have js, css, tests, and node_modules folders defined in the mySite location. To run the tests I would have to go to http://localhost/testApps/mySite/node_modules/intern/client.html?config=mySite/tests/intern prepending mySite to the location of the config. Likewise, in my config, I had to define my suites like so:

suites: [
    'mySite/tests/suite1',
    'mySite/tests/suite2',
    'mySite/tests/suite3'
],

If I don't change the script tag to use a different loader in client.html and use the version of dojo in node_modules then I don't need to have the extra path (but the esri library cannot be found).

I have also since found the esri jsapi version of the intern tutorial and in that tutorial he does not have to change the loader. Difference is that he is using intern-geezer due to a bug in dojo 1.8.3 but I'm using esri jsapi 3.7 and thus have dojo 1.9.1 and I also don't care about old IE so would rather not use geezer if I don't have to. I did specify my packages in intern.js the same way he did.

I did take a copy of my app and installed intern-geezer instead of intern and I was able to run the tests. All but one passed (I suspect it to be because of something from chai not being supported in geezer) and I didn't have to modify the paths at all. The intern-geezer version of client.html is different from that in intern. It doesn't use require.

Is there a way I can get intern to work with esri jsapi without having to change the loader in client.html? I would like to have this run from the command line in an automated fashion as well.

Community
  • 1
  • 1
wizardbyte
  • 110
  • 5

1 Answers1

2

As of Intern 1.3, you may specify alternative loaders, such as the one from Esri, in the useLoader configuration property. For the Esri loader, you would use this:

// intern.js
define({
    /* … other configuration options … */
    useLoader: { 'host-browser': 'http://js.arcgis.com/3.7/' }
    /* … */
});

Note that Esri uses the old Dojo 1 loader; if you want to specify additional dojoConfig criteria like async: true, etc., add the dojoConfig global object within your configuration file:

define([], function () {
    this.dojoConfig = { async: 1 };

    return {
        /* … configuration … */
    };
});
C Snover
  • 17,908
  • 5
  • 29
  • 39
  • This looks promising. Thank you. What I've done is this: I installed intern 1.3 and added the useLoader property to my intern.js config file as well as the dojoConfig async property as suggested. This allowed me to successfully run my tests in a browser without editing client.html. I did have to leave the 'mySite' path component when specifying my test suites. To run from the command line however, I had to remove that but then I get an error that it failed to load an esri module required by my test suite despite having the correct url (http://js.arcgis.com/3.7/js/esri/geometry/Point.js) – wizardbyte Nov 19 '13 at 21:06
  • It's definitely an improvement. Even if I had to specify a root url for running in the browser or something. In the meantime I have created separate config files for using browser and command line clients. I still haven't figured out why the command line client can't load the esri modules. – wizardbyte Nov 19 '13 at 21:48
  • The command-line client loads modules from the filesystem only. Also, I don’t know that any of the Esri code is designed to run in Node.js. – C Snover Nov 20 '13 at 05:04
  • oh ok. Didn't realize that. I do have a local copy of the esri sdk so I will try that too. – wizardbyte Nov 20 '13 at 18:33
  • it doesn't look like it will work. Once I got my paths correct it seemed to load the version of dojo included in the esri library but gave the error `TypeError: Object esri/geometry/Point has no method 'map'` which sounds to me like esri code likely isn't designed to run in Node.js as you suggested. Guess I'll resign myself to only be able to run tests in the browser for now. Thanks for your help. – wizardbyte Nov 20 '13 at 18:50