Skip to content

Commit b22011a

Browse files
add component templates to analyzEmberObject output
1 parent 16bc825 commit b22011a

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

lib/gather/analyze-ember-object.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
module.exports = function analyzeEmberObject(possibleEmberObject) {
1+
module.exports = function analyzeEmberObject(possibleEmberObject, modulePath) {
2+
let isTemplate = false;
3+
24
if (typeof possibleEmberObject !== 'object' || possibleEmberObject === null) {
35
return undefined;
46
}
@@ -10,6 +12,18 @@ module.exports = function analyzeEmberObject(possibleEmberObject) {
1012
type: 'Helper',
1113
};
1214
} else if (typeof eObjDefault.proto !== 'function') {
15+
/**
16+
* this is for JavaScript-less components that only have a template. Only
17+
* components with a backing JavaScript file will be in the `require.entries`
18+
* that will have a `proto()` we can instantiate.
19+
*/
20+
if (modulePath && modulePath.includes('templates/components/')) {
21+
isTemplate = true;
22+
return {
23+
isTemplate,
24+
type: 'Component',
25+
};
26+
}
1327
return undefined;
1428
}
1529
}

lib/gather/gather-telemetry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const puppeteer = require('puppeteer');
22
const { setTelemetry } = require('../utils/telemetry');
33

4-
const DEFAULT_PUPPETEER_ARGS = { ignoreHTTPSErrors: true };
4+
const DEFAULT_PUPPETEER_ARGS = { ignoreHTTPSErrors: true, devtools: true };
55

66
module.exports = async function gatherTelemetry(url, gatherFn, ...args) {
77
let puppeteerArgs = [...args].pop();
@@ -42,7 +42,7 @@ module.exports = async function gatherTelemetry(url, gatherFn, ...args) {
4242

4343
try {
4444
let module = require(modulePath);
45-
telemetry[modulePath] = await gFn(module);
45+
telemetry[modulePath] = await gFn(module, modulePath);
4646
} catch (error) {
4747
// log the error, but continue
4848
window.logErrorInNodeProcess(`error evaluating \`${modulePath}\`: ${error.message}`);

lib/gather/gather-telemetry.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('Provide a personalized `Gathering Function`', () => {
4949
test('can determine most Ember types with a robust function', async () => {
5050
await gatherTelemetry('http://localhost:4200', analyzeEmberObject);
5151
let telemetry = getTelemetry();
52-
expect(Object.values(telemetry).filter(Boolean).length).toEqual(34);
52+
expect(Object.values(telemetry).filter(Boolean).length).toEqual(38);
5353
});
5454

5555
test('can handle external functions', async () => {
@@ -58,6 +58,15 @@ describe('Provide a personalized `Gathering Function`', () => {
5858
expect(Object.values(telemetry).filter(Boolean).length).toEqual(1);
5959
});
6060

61+
test('can enumerate template only classic components', async () => {
62+
await gatherTelemetry('http://localhost:4200', analyzeEmberObject);
63+
let telemetry = getTelemetry();
64+
let components = Object.values(telemetry).filter(obj => obj.isTemplate);
65+
expect(components.length).toEqual(4);
66+
expect(components[0].type).toEqual('Component');
67+
expect(components[0].isTemplate).toBe(true);
68+
});
69+
6170
afterAll(async () => {
6271
console.log(`Killing PID: ${app.emberServe.pid}`);
6372
await app.emberServe.kill('SIGTERM', {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
<p>I have no JavaScript class</p>
3+
</div>

0 commit comments

Comments
 (0)