Skip to content

Commit 6484334

Browse files
patocallaghanNullVoxPopuli
authored andcommitted
Support retrieving telemetry data for controllers (#5)
1 parent c38a978 commit 6484334

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lib/utils/telemetry.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ function getTelemetry() {
3636
*/
3737
function getTelemetryFor(filePath) {
3838
let modulePath = getModulePathFor(filePath);
39-
let moduleKey = modulePath.replace('templates/components/', 'components/');
39+
let moduleKey = _generateModuleKey(modulePath);
4040
let data = getTelemetry()[moduleKey];
4141

4242
return data;
4343
}
4444

45+
function _generateModuleKey(modulePath) {
46+
let moduleKey = modulePath.replace('templates/components/', 'components/');
47+
// If `templates/` still exists in the path then it wasn't a component but a controller-level template instead
48+
return moduleKey.replace('templates/', 'controllers/');
49+
}
50+
4551
module.exports = {
4652
getTelemetry,
4753
setTelemetry,

lib/utils/telemetry.test.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,25 @@ describe('getTelemetryFor', () => {
2727
expect(value).toEqual(1);
2828
});
2929

30-
test('gets the data for the filePath in classic apps', () => {
31-
let fakeTelemetry = { 'test-app/components/test-component': 1 };
30+
describe('classic apps', () => {
31+
test('gets the data for the component filePath', () => {
32+
let fakeTelemetry = { 'test-app/components/test-component': 1 };
3233

33-
setTelemetry(fakeTelemetry);
34+
setTelemetry(fakeTelemetry);
3435

35-
let value = getTelemetryFor('test-app/templates/components/test-component');
36+
let value = getTelemetryFor('test-app/templates/components/test-component');
3637

37-
expect(value).toEqual(1);
38+
expect(value).toEqual(1);
39+
});
40+
41+
test('gets the data for the controller filePath', () => {
42+
let fakeTelemetry = { 'test-app/controllers/application': 1 };
43+
44+
setTelemetry(fakeTelemetry);
45+
46+
let value = getTelemetryFor('test-app/templates/application');
47+
48+
expect(value).toEqual(1);
49+
});
3850
});
3951
});

0 commit comments

Comments
 (0)