diff --git a/bin/build-entity-json-files.js b/bin/build-entity-json-files.js index 7f41122..1f02ec5 100644 --- a/bin/build-entity-json-files.js +++ b/bin/build-entity-json-files.js @@ -18,11 +18,16 @@ fs.writeFileSync(`${DIST_DIR}/entities.json`, JSON.stringify(sourceEntities)) const httpArchiveData = require('../data/2019-03-01-origin-scripting.json') const {getEntity} = require('../lib/index.js') // IMPORTANT: require this after entities have been written const entityExecutionStats = _(httpArchiveData) - .groupBy(({origin}) => getEntity(origin)) - .mapValues(dataset => ({ - totalExecutionTime: Math.round(_.sum(dataset.map(x => Number(x.totalExecutionTime)))), - totalOccurrences: Math.round(_.sum(dataset.map(x => Number(x.totalOccurrences)))), - })) + .groupBy(({origin}) => { + const entity = getEntity(origin) + return entity && entity.name + }) + .mapValues(dataset => { + return { + totalExecutionTime: Math.round(_.sum(dataset.map(x => Number(x.totalExecutionTime)))), + totalOccurrences: Math.round(_.sum(dataset.map(x => Number(x.totalOccurrences)))), + } + }) .value() const entitiesInHTTPArchive = _(httpArchiveData) @@ -35,7 +40,7 @@ const entitiesInHTTPArchive = _(httpArchiveData) .value() for (const entity of entitiesInHTTPArchive) { - Object.assign(entity, entityExecutionStats[entity]) + Object.assign(entity, entityExecutionStats[entity.name]) } fs.writeFileSync(`${DIST_DIR}/entities.json`, JSON.stringify(sourceEntities)) diff --git a/lib/index.test.js b/lib/index.test.js index 0f19301..a6e7cda 100644 --- a/lib/index.test.js +++ b/lib/index.test.js @@ -25,7 +25,7 @@ describe('getEntity', () => { it('works for direct domain usage', () => { expect(getEntity('https://js.connect.facebook.net/lib.js')).toMatchInlineSnapshot(` Object { - "averageExecutionTime": 233.43429691479307, + "averageExecutionTime": 119.80635511714381, "categories": Array [ "social", ], @@ -54,8 +54,8 @@ Object { ], "homepage": "https://www.facebook.com", "name": "Facebook", - "totalExecutionTime": 2249323397, - "totalOccurrences": 9635788, + "totalExecutionTime": 132167256, + "totalOccurrences": 1103174, } `) }) @@ -63,7 +63,7 @@ Object { it('works for inferred domain usage', () => { expect(getEntity('https://unknown.typekit.net/fonts.css')).toMatchInlineSnapshot(` Object { - "averageExecutionTime": 233.43429691479307, + "averageExecutionTime": 95.1277705345502, "categories": Array [ "library", ], @@ -75,8 +75,8 @@ Object { ], "homepage": "https://fonts.adobe.com/", "name": "Adobe TypeKit", - "totalExecutionTime": 2249323397, - "totalOccurrences": 9635788, + "totalExecutionTime": 656667, + "totalOccurrences": 6903, } `) })