Skip to content

Commit

Permalink
Filter container debug results based on module
Browse files Browse the repository at this point in the history
Don't return things from catalogEntriesByType that don't belong to your main app.
  • Loading branch information
ryanlabouve committed Dec 1, 2016
1 parent 744e766 commit b5814f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion addon/container-debug-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
});
}
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/container-debug-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit b5814f4

Please sign in to comment.