Skip to content

Commit

Permalink
Support retrieving telemetry data for controllers (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
patocallaghan authored and NullVoxPopuli committed Aug 10, 2019
1 parent c38a978 commit 6484334
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 7 additions & 1 deletion lib/utils/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 17 additions & 5 deletions lib/utils/telemetry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 6484334

Please sign in to comment.