7

I am trying to test a Require.js project using Intern. I'm running into errors in my tests where jQuery is not defined when jQuery plugins are being loaded. My loader config looks like this:

loader: {
    // Aliased paths
  paths: {
    'dt': 'dt',
    'jq': 'jquery',

    'jquery': 'jquery/jquery-1.8.3',
    'jquerymx': 'jquery/jquerymx-3.2.custom',
    'jquery.ui': 'jquery/jquery-ui-1.9.2.custom.min',
    'jquery.ui.widget': 'jquery/jquery.ui.widget',
    'jquery.jscrollpane': 'jquery/jquery.jscrollpane.min.edit',
    'jquery.colorbox': 'jquery/jquery.colorbox-min',
    'jquery.selectbox': 'jquery/jquery.selectbox-0.2.min.edit',
    'jquery.base64': 'jquery/jquery.base64',
    'jquery.cookie': 'jquery/jquery.cookie',
    'jquery.urldecoder': 'jquery/jquery.urldecoder.min',
    'jquery.fileupload': 'jquery/jquery.fileupload',
    'jquery.history': 'history/scripts/compressed/history.adapter.jquery',

    'openajax': 'openajax_2.0.7/OpenAjaxUnmanagedHub',
    'zeroclipboard': 'zeroclipboard/ZeroClipboard'
  },

  // Plugin mappings
  map: {
    '*': {
      'css': 'requirejs/require-css/css',
      'text': 'requirejs/text'
    }
  },

  // Shims for non-AMD libraries, mainly jQuery plugins
  shim: {
    'openajax': {
      exports: 'OpenAjax'
    },

    'zeroclipboard': {
      exports: 'ZeroClipboard'
    },

    'jquerymx': ['jquery'],
    'jquery.ui': ['jquery'],
    'jquery.ui.widget': ['jquery'],
    'jquery.jscrollpane': ['jquery'],
    'jquery.colorbox': ['jquery'],
    'jquery.selectbox': ['jquery'],
    'jquery.base64': ['jquery'],
    'jquery.cookie': ['jquery'],
    'jquery.urldecoder': ['jquery'],
    'jquery.fileupload': ['jquery'],
    'jquery.history': [
      'jquery',
      'history/scripts/compressed/history',
      'history/scripts/compressed/history.html4'
    ]
  }
}

I've checked to make sure jQuery and my other dependencies are actually being loaded, and they are, just not in the right order. Does the Dojo AMD loader that Intern use not handle the shim configuration?

coreyschram
  • 195
  • 3
  • 17

2 Answers2

3

The problem is that the AMD loader used by intern doesn't currently implement the shim configuration propertyAMD Specification. I was actually unaware that it was part of the standard until you asked this question.

At the moment, you could run functional tests using a different AMD loader via Intern, but at the moment, it would be difficult to run unit tests on the local machine.

Kitson
  • 1,650
  • 1
  • 18
  • 36
  • 1
    Ah, I had assumed it did implement shim since it was part of the spec. Might have to try and add that myself :) – coreyschram May 08 '13 at 14:19
  • You can use your own loader plugin to control the loading order. See http://stackoverflow.com/a/26531410/1859442 – Benjamin Oct 23 '14 at 15:29
1

All I had to do was point useLoader config to the require.js, and poof. I had the familiar shim config and path config I use in my app. Bam.

httpete
  • 2,765
  • 26
  • 34