Mark R
Mark R

Reputation: 350

Testing Dojo 1.x apps in Intern 3.x

I'm trying to write some unit tests for code that uses Dojo 1.10.4 and so far I haven't had any success. I've tried lots of things, but I'm currently trying to use Intern 3.0.5. Here's what I've got in intern.js at the moment:

define({
  capabilities: { 'browserstack.selenium_version': '2.45.0' },
  environments: [ { browserName: 'firefox', version: '40', platform: ['WINDOWS'] } ],
  maxConcurrency: 2,
  tunnel: 'NullTunnel',
  //loaders: { 'host-browser': 'dojo/dojo.js' },
  loaderOptions: {
    packages: [
      { name: 'app', location: 'src' },
      { name: 'dojo', location: 'dojo' },
      { name: 'dijit', location: 'dijit' }
    ],

    map: {
      '*': {
        'dojo': 'dojo',
      },
      'intern': {
        'dojo': 'node_modules/intern/node_modules/dojo'
      }
    }
  },
  suites: ['tests/unit/ButtonTests'],
  excludeInstrumentation: true,
  useSauceConnect: false,
  proxyPort: 9000,
  proxyUrl: 'http://localhost:9000/'
});

dojoConfig = {
  has: { 'dojo-undef-api': true }
};

My hope is that I can let Intern use the Dojo 2 loader that it ships with, but then point my code at Dojo 1.10.4, so I set up a map in loaderOptions to take care of that. Unfortunately, my code doesn't seem to be picking up the right copy and I'm getting this error:

× firefox 40 on WINDOWS - unit tests - Button tests - icon uses correct class (0.001s)
TypeError: target is null
  at on  <dojo\on.js:69:6>
  at clazz<._initializeEventHandlers  <src\Button.js:35:1>
  at clazz<.constructor  <src\Button.js:29:9>
  at singleConstructor/<  <dojo\_base\declare.js:440:5>
@http://localhost:9000/tests/unit/ButtonTests.js:19:20
  at Test.prototype.run/<  <__intern\lib\Test.js:211:19>
  at Promise/this.then/</<  <node_modules\intern\node_modules\dojo\Promise.ts:393:15>
  at runCallbacks  <node_modules\intern\node_modules\dojo\Promise.ts:11:2>
  at settle/<  <node_modules\intern\node_modules\dojo\Promise.ts:317:4>
  at run  <node_modules\intern\node_modules\dojo\Promise.ts:237:7>
  at CallbackQueue</CallbackQueue.prototype.drain  <node_modules\intern\node_modules\dojo\CallbackQueue.ts:39:4>
  at nextTick</observer<  <node_modules\intern\node_modules\dojo\nextTick.ts:63:4>

I also tried making Intern use the loader that comes with Dojo 1.10 instead of the one it ships with, which is commented out in the config I pasted above. When I do that, I get this error:

Suite firefox 40 on WINDOWS - unit tests FAILED
Error: xhrFailed
  at makeError  <dojo\dojo.js:106:15>
  at req.getText  <dojo\dojo.js:331:1>
  at injectModule  <dojo\dojo.js:1539:8>
  at forEach  <dojo\dojo.js:93:6>
  at injectDependencies/<  <dojo\dojo.js:758:5>
  at guardCheckComplete  <dojo\dojo.js:1277:5>
  at injectDependencies  <dojo\dojo.js:757:4>
  at runDefQ/<  <dojo\dojo.js:1621:6>
  at forEach  <dojo\dojo.js:93:6>
  at runDefQ  <dojo\dojo.js:1620:5>
  at injectModule/xhrCallback  <dojo\dojo.js:1488:9>
  at req.getText  <dojo\dojo.js:328:7>
  at injectModule  <dojo\dojo.js:1539:8>
  at forEach  <dojo\dojo.js:93:6>
  at injectDependencies/<  <dojo\dojo.js:758:5>
  at guardCheckComplete  <dojo\dojo.js:1277:5>
  at injectDependencies  <dojo\dojo.js:757:4>
  at contextRequire  <dojo\dojo.js:821:6>
  at req  <dojo\dojo.js:124:11>
  at PreExecutor.prototype._loadExecutorWithLoader/<  <__intern\lib\executors\PreExecutor.js:287:5>
  at Promise  <__intern\node_modules\dojo\Promise.js:172:17>
  at PreExecutor.prototype._loadExecutorWithLoader  <__intern\lib\executors\PreExecutor.js:286:1>
  at loadExecutorWithLoader  <__intern\lib\executors\PreExecutor.js:365:12>
  at Promise/this.then/</<  <__intern\node_modules\dojo\Promise.js:156:41>
  at runCallbacks  <__intern\node_modules\dojo\Promise.js:19:13>
  at settle/<  <__intern\node_modules\dojo\Promise.js:103:21>
  at run  <__intern\node_modules\dojo\Promise.js:51:33>
  at CallbackQueue</CallbackQueue.prototype.drain  <__intern\node_modules\dojo\CallbackQueue.js:39:21>
  at nextTick</observer<  <__intern\node_modules\dojo\nextTick.js:52:21>

I was also getting this error yesterday, but I can't remember exactly how I did it! I was trying to use PhantomJS, so that might have done it:

Error: Repeated sequence for session 08ee5fa0-67a6-11e5-9d1c-49f2f4677a77: 0 last 0 cur
  at Proxy._publishInSequence  <node_modules\intern\lib\Proxy.js:181:11>
  at IncomingMessage.<anonymous>  <node_modules\intern\lib\Proxy.js:63:39>
  at IncomingMessage.emit  <events.js:104:17>
  at <_stream_readable.js:908:16>
  at process._tickCallback  <node.js:355:11>

On a side note, should I be able to set dojoConfig at the end of intern.js like I'm doing above? I'd like to enable dojo-undef-api.

Any help would be greatly appreciated!

Upvotes: 0

Views: 259

Answers (1)

C Snover
C Snover

Reputation: 18766

The Dojo Boilerplate includes an Intern configuration for Dojo applications, that can be adapted for use in your project.

Upvotes: 1

Related Questions