From b5814f42c01a5322d4cd1803fbb7203395ee32f4 Mon Sep 17 00:00:00 2001 From: Ryan LaBouve Date: Wed, 12 Oct 2016 11:38:39 +0900 Subject: [PATCH] Filter container debug results based on module Don't return things from catalogEntriesByType that don't belong to your main app. --- addon/container-debug-adapter.js | 12 +++++++++++- tests/unit/container-debug-adapter-test.js | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/addon/container-debug-adapter.js b/addon/container-debug-adapter.js index 070099ee..8614669f 100644 --- a/addon/container-debug-adapter.js +++ b/addon/container-debug-adapter.js @@ -81,7 +81,7 @@ if (typeof ContainerDebugAdapter !== 'undefined') { for (let i = 0, l = moduleNames.length; i < l; i++) { let key = moduleNames[i]; - if(key.indexOf(type) !== -1) { + if (this.startsWithModuleOrPodModulePrefix(key) && key.indexOf(type) !== -1) { // Check if it's a pod module var name = getPod(type, key, this.namespace.podModulePrefix || prefix); if (!name) { @@ -102,6 +102,16 @@ if (typeof ContainerDebugAdapter !== 'undefined') { } } return types; + }, + + /** + @private + @method startsWithModuleOrPodModulePrefix + @param {string} moduleName Name of module being tested + @return {Boolean} + */ + startsWithModuleOrPodModulePrefix(moduleName) { + return moduleName.indexOf(this.namespace.modulePrefix) === 0 || moduleName.indexOf(this.namespace.podModulePrefix) === 0; } }); } diff --git a/tests/unit/container-debug-adapter-test.js b/tests/unit/container-debug-adapter-test.js index 8d9316ae..3af67282 100644 --- a/tests/unit/container-debug-adapter-test.js +++ b/tests/unit/container-debug-adapter-test.js @@ -110,3 +110,18 @@ test("Pods podModulePrefix support", function(assert) { assert.equal(models[0], 'user', "the name is correct"); assert.equal(models[1], 'users/user', "the name is correct"); }); + +test('Ignores browserify modules', function(assert) { + assert.expect(1); + def('npm:cool/model/package'); + var models = containerDebugAdapter.catalogEntriesByType('model'); + assert.equal(models.length, 0, 'Ignores the browserify modules'); +}); + +test('Ignores modules that are not part of the main app', function(assert) { + assert.expect(1); + def('liquid/awesome/model'); + def('liquid/models/awesome'); + var models = containerDebugAdapter.catalogEntriesByType('model'); + assert.equal(models.length, 0, 'Ignores packages not in the main app'); +});