From bfaf81bd9e5c98f8c25fc5e5b4f068fca49d3943 Mon Sep 17 00:00:00 2001 From: Ryan LaBouve Date: Thu, 1 Dec 2016 15:29:34 -0600 Subject: [PATCH] Filtering 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 | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/addon/container-debug-adapter.js b/addon/container-debug-adapter.js index 9029839c..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 && key.indexOf('npm:') !== 0) { + 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 3a0a2cd1..3af67282 100644 --- a/tests/unit/container-debug-adapter-test.js +++ b/tests/unit/container-debug-adapter-test.js @@ -117,3 +117,11 @@ test('Ignores browserify modules', function(assert) { 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'); +});