theintern / intern

A next-generation code testing stack for JavaScript.
https://theintern.io/
Other
4.36k stars 310 forks source link

Intern's internal dojo loader fails to load a module when the optional "mid" parameter is passed in #169

Closed tapasvimoturu closed 10 years ago

tapasvimoturu commented 10 years ago

source/object.js

define("BaseObject",["dojo/_base/lang", "dojo/_base/declare"], function(lang, declare) {

    var baseObject;

    baseObject = declare(null, {
        constructor : function(){
        },
        mixin : function(sources){
            lang.mixin(this, sources);
        }
    });

    baseObject.subClass = function(subClass){
        return declare(this, subClass);
    };

    baseObject.extend = function(properties){
        return lang.extend(this,properties);
    };

    return baseObject;
});

test.js

define([
    'intern!object',
    'intern/chai!assert',
    'source/object'

], function (registerSuite, assert, π) {
    registerSuite({
        name: 'hello',

        validateTrue: function() {
            assert.strictEqual(true,true, "Obvious");
       }
  });
});

Error Returned

Uncaught TypeError: Object BaseObject has no method 'map'

Root Cause

Intern 1.5 seems to be using a internal version of dojo from the following pacakges.json config.

 ],
  "dependencies": {
    ...
    "dojo": "https://github.com/csnover/dojo2-core/archive/9f825f8793b57b15c1e64b0ab6dd2b8b94a1f7ff.tar.gz",
    ....
  },

The dojo.js in this tar file seems to only have two properties in the define method as compared to three in dojo 1.9.3 or 2.1 Tar file method definition looks like the one below (dojo.js line 817)

var define = mix(function (deps, factory) {...

current master version
var def = function(
        mid,          //(commonjs.moduleId, optional)
        dependencies, //(array of commonjs.moduleId, optional) list of modules to be loaded before running factory
        factory       //(any)
    ){ ...

https://github.com/dojo/dojo/blob/master/dojo.js#L1752

Now since we are passing argument in order. The loader assumes that the first parameter is an array that contains dependencies and fails.

Why does this need to be fixed ?

This is breaking the tests with popular dependencies like _ as well as custom module in our project source. This is a standard in amd as well where module id is an optional parameter in the define method call.

Let me know if you have questions Tapasvi

dylans commented 10 years ago

I believe this is fixed in 1.6.0, see release notes: https://github.com/theintern/intern/releases/tag/1.6.0

csnover commented 10 years ago

As @dylans noted, support for legacy 3-argument AMD signature was added to the loader for Intern 1.6. If you are using Intern 1.5, you can use an alternative loader with useLoader that supports this signature. However, as noted, the 3-argument signature is legacy and strongly discouraged when authoring any AMD modules, so if you are doing it yourself, you should remove it from your code. :)