amdjs/amdjs-tests — Issue #3: relativeModuleId: Incorrect test.
Author: dschnare
Created: 2011-11-08 15:55:54+00:00
State: open

In the test [relativeModuleId](https://github.com/amdjs/amdjs-tests/blob/master/tests/anon/relativeModuleId-tests.js) the assertion `t.is("util", array.utilName)` should be `t.is("impl/util", array.utilName)`.

Original Test:

config({
paths: {
"array": "impl/array"
}
});

go(["require", "array"], function(require, array) {
doh.register(
"relativeModuleId",
[
function relativeModuleId(t){
t.is("impl/array", array.name);
t.is("util", array.utilName);
}
]
);

doh.run();
}
);

The `array` module from `impl/array.js`:

define(['./util'], function (util) {
return {
name: 'impl/array',
utilName: util.name
};
});

Note that the `array` module has a `./util` dependency relative to the _current_ module. The current module would in fact be `impl/array`, yielding a path of `impl/`, causing `./util` to be resolved to `impl/util`.

The [relativeModuleId](https://github.com/amdjs/amdjs-tests/blob/master/tests/anon/relativeModuleId-tests.js) test incorrectly assumes that the `tests/anon/util.js` file is loaded.

If this is not a bug but in fact implemented this way by design I would like to suggest changing to follow the above scenario. Following the above scenario will result in predictable relative module loading behaviour.

**Side Effect (If implementation remains the same)**

// This would cause our `impl/array.js` to attempt to load `arrays/are/so/great/util.js`.
config({
paths: {
"arrays/are/so/great": "impl/array"
}
});

go(["require", "arrays/are/so/great"], function(require, array) {
doh.register(
"relativeModuleId",
[
function relativeModuleId(t){
t.is("impl/array", array.name);
t.is("util", array.utilName);
}
]
);

doh.run();
}
);