Skip to content

Commit

Permalink
Fix typo and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmquinn committed Jan 18, 2018
1 parent f8b282b commit ed8c85a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/loader/loader.js
Expand Up @@ -286,7 +286,7 @@ var loader, define, requireModule, require, requirejs;
var mod = registry[id] || registry[id + '/index'];

while (mod && mod.isAlias) {
mod = registry[mod.id] || registry[id + '/index'];
mod = registry[mod.id] || registry[mod.id + '/index'];
}

if (!mod) { missingModule(id, referrer); }
Expand Down
63 changes: 63 additions & 0 deletions tests/all.js
Expand Up @@ -1362,6 +1362,32 @@ test('alias chain (simple)', function() {
});
});

test('alias chain (simple) with implicit /index', function() {
define('bar/index', [], function() {
return 'I AM BAR';
});

define('quz', define.alias('foo'));
define('foo', define.alias('bar'));

equal(require('quz'), 'I AM BAR');

var stats = statsForMonitor('loaderjs', tree);

deepEqual(stats, {
findDeps: 1,
define: 3,
exports: 1,
findModule: 1,
modules: 3,
reify: 1,
require: 1,
resolve: 0,
resolveRelative: 0,
pendingQueueLength: 1
});
});

test('alias chain (long)', function() {
define('bar', [], function() {
return 'I AM BAR';
Expand Down Expand Up @@ -1465,6 +1491,43 @@ test('alias chains propogate unsee', function() {
});
});

test('alias chains propogate unsee with implicit /index', function() {
var counter = 0;

define('bar/index', [], function() {
counter++;
return 'I AM BAR';
});

define('a', define.alias('bar'));
define('b', define.alias('a'));

equal(counter, 0);
equal(require('b'), 'I AM BAR');
equal(counter, 1);
equal(require('b'), 'I AM BAR');
equal(counter, 1);
require.unsee('b');
equal(counter, 1);
equal(require('b'), 'I AM BAR');
equal(counter, 2);

var stats = statsForMonitor('loaderjs', tree);

deepEqual(stats, {
findDeps: 2,
define: 3,
exports: 2,
findModule: 4,
modules: 3,
reify: 2,
require: 3,
resolve: 0,
resolveRelative: 0,
pendingQueueLength: 2
});
});

test('alias chaining with relative deps works', function() {
define('foo/baz', [], function() {
return 'I AM baz';
Expand Down

0 comments on commit ed8c85a

Please sign in to comment.