diff --git a/lib/utils/telemetry.js b/lib/utils/telemetry.js index 94118f2..a48e3b6 100644 --- a/lib/utils/telemetry.js +++ b/lib/utils/telemetry.js @@ -36,12 +36,18 @@ function getTelemetry() { */ function getTelemetryFor(filePath) { let modulePath = getModulePathFor(filePath); - let moduleKey = modulePath.replace('templates/components/', 'components/'); + let moduleKey = _generateModuleKey(modulePath); let data = getTelemetry()[moduleKey]; return data; } +function _generateModuleKey(modulePath) { + let moduleKey = modulePath.replace('templates/components/', 'components/'); + // If `templates/` still exists in the path then it wasn't a component but a controller-level template instead + return moduleKey.replace('templates/', 'controllers/'); +} + module.exports = { getTelemetry, setTelemetry, diff --git a/lib/utils/telemetry.test.js b/lib/utils/telemetry.test.js index 274b2bc..17408f5 100644 --- a/lib/utils/telemetry.test.js +++ b/lib/utils/telemetry.test.js @@ -27,13 +27,25 @@ describe('getTelemetryFor', () => { expect(value).toEqual(1); }); - test('gets the data for the filePath in classic apps', () => { - let fakeTelemetry = { 'test-app/components/test-component': 1 }; + describe('classic apps', () => { + test('gets the data for the component filePath', () => { + let fakeTelemetry = { 'test-app/components/test-component': 1 }; - setTelemetry(fakeTelemetry); + setTelemetry(fakeTelemetry); - let value = getTelemetryFor('test-app/templates/components/test-component'); + let value = getTelemetryFor('test-app/templates/components/test-component'); - expect(value).toEqual(1); + expect(value).toEqual(1); + }); + + test('gets the data for the controller filePath', () => { + let fakeTelemetry = { 'test-app/controllers/application': 1 }; + + setTelemetry(fakeTelemetry); + + let value = getTelemetryFor('test-app/templates/application'); + + expect(value).toEqual(1); + }); }); });