diff --git a/src/loadrunner.js b/src/loadrunner.js index f76edbb..e456e48 100644 --- a/src/loadrunner.js +++ b/src/loadrunner.js @@ -54,7 +54,8 @@ // pushObjPath(thing, 'a/b/c', new) //=> thing.a.b.c = new var names = path.split('/'), cursor = obj; while (names.length > 1) { - cursor = cursor[names.shift()] = {}; + var name = names.shift(); + cursor = cursor[name] = cursor[name] || {}; } cursor[names[0]] = newobj; } diff --git a/test/modules/sub/submoda.js b/test/modules/sub/submoda.js new file mode 100644 index 0000000..d5a394e --- /dev/null +++ b/test/modules/sub/submoda.js @@ -0,0 +1,5 @@ +provide(function(exports) { + using('moda', function(moda) { + exports(moda); + }); +}); \ No newline at end of file diff --git a/test/modules/sub/submodb.js b/test/modules/sub/submodb.js new file mode 100644 index 0000000..9b1e3db --- /dev/null +++ b/test/modules/sub/submodb.js @@ -0,0 +1,5 @@ +provide(function(exports) { + using('modb', function(modb) { + exports(modb); + }); +}); \ No newline at end of file diff --git a/test/test.html b/test/test.html index 16ca83c..7648cb3 100644 --- a/test/test.html +++ b/test/test.html @@ -193,6 +193,17 @@
}); }); + QUnit.test('should collect module results without overwriting namespaces', function() { + expect(2); + stop(1000); + + using('sub/submoda', 'sub/submodb', true, function(results) { + equals('success', results.sub.submodb.test(), 'sub.submodb exports loaded'); + equals('success', results.sub.submoda.test, 'sub.submoda exports loaded'); + start(); + }); + }); + QUnit.module('loadrunner.Script.loaded'); QUnit.test('should list files loaded in order', function() {