Skip to content

Commit

Permalink
fix(server): use run URL for statistics not finalUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Oct 24, 2019
1 parent 65feb1e commit f7e797e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
7 changes: 2 additions & 5 deletions packages/server/src/api/storage/storage-method.js
Expand Up @@ -213,10 +213,7 @@ class StorageMethod {

const runs = await storageMethod.getRuns(projectId, buildId);
/** @type {Array<Array<[LHCI.ServerCommand.Run, LH.Result]>>} */
const runsByUrl = _.groupBy(
runs.map(run => [run, JSON.parse(run.lhr)]),
([_, lhr]) => lhr.finalUrl
);
const runsByUrl = _.groupBy(runs.map(run => [run, JSON.parse(run.lhr)]), ([run, _]) => run.url);

const statisicDefinitionEntries = Object.entries(statisticDefinitions);
const existingStatistics = context.existingStatistics || [];
Expand All @@ -226,7 +223,7 @@ class StorageMethod {
const name = /** @type {LHCI.ServerCommand.StatisticName} */ (key);
return Promise.all(
runsByUrl.map(runs => {
const url = runs[0][1].finalUrl;
const url = runs[0][0].url;
const {value} = fn(runs.map(([_, lhr]) => lhr));
const existing = existingStatistics.find(
s => s.name === name && s.value === value && s.url === url
Expand Down
50 changes: 28 additions & 22 deletions packages/server/test/server-test-suite.js
Expand Up @@ -306,7 +306,7 @@ function runTests(state) {
const payload = {
projectId: projectA.id,
buildId: buildA.id,
url: 'https://example.com',
url: 'https://example.com:PORT/',
lhr: JSON.stringify(lhr),
};

Expand All @@ -321,7 +321,7 @@ function runTests(state) {
const payload = {
projectId: projectA.id,
buildId: buildA.id,
url: 'https://example.com',
url: 'https://example.com:PORT/',
lhr: JSON.stringify({
...lhr,
lighthouseVersion: '4.2.0',
Expand All @@ -341,7 +341,7 @@ function runTests(state) {
const payload = {
projectId: projectA.id,
buildId: buildA.id,
url: 'https://example.com',
url: 'https://example.com:PORT/',
lhr: JSON.stringify({
...lhr,
lighthouseVersion: '4.2.0',
Expand All @@ -361,7 +361,7 @@ function runTests(state) {
const payload = {
projectId: projectA.id,
buildId: buildA.id,
url: 'https://example.com/blog',
url: 'https://example.com:PORT/blog',
lhr: JSON.stringify({
finalUrl: 'https://example.com/blog',
lighthouseVersion: '4.2.0',
Expand Down Expand Up @@ -451,82 +451,82 @@ function runTests(state) {

expect(statistics).toMatchObject([
{
url: 'https://example.com/',
url: 'https://example.com:PORT/',
name: 'audit_first-contentful-paint_average',
value: 2000,
},
{
url: 'https://example.com/',
url: 'https://example.com:PORT/',
name: 'audit_interactive_average',
value: 5500,
},
{
url: 'https://example.com/',
url: 'https://example.com:PORT/',
name: 'audit_speed-index_average',
value: 5000,
},
{
url: 'https://example.com/',
url: 'https://example.com:PORT/',
name: 'category_accessibility_average',
value: -1,
},
{
url: 'https://example.com/',
url: 'https://example.com:PORT/',
name: 'category_best-practices_average',
value: -1,
},
{
url: 'https://example.com/',
url: 'https://example.com:PORT/',
name: 'category_performance_average',
value: 0.45,
},
{
url: 'https://example.com/',
url: 'https://example.com:PORT/',
name: 'category_pwa_average',
value: 0.1,
},
{
url: 'https://example.com/',
url: 'https://example.com:PORT/',
name: 'category_seo_average',
value: 0.9,
},
{
url: 'https://example.com/blog',
url: 'https://example.com:PORT/blog',
name: 'audit_first-contentful-paint_average',
value: 1000,
},
{
url: 'https://example.com/blog',
url: 'https://example.com:PORT/blog',
name: 'audit_interactive_average',
value: 1000,
},
{
url: 'https://example.com/blog',
url: 'https://example.com:PORT/blog',
name: 'audit_speed-index_average',
value: 1000,
},
{
url: 'https://example.com/blog',
url: 'https://example.com:PORT/blog',
name: 'category_accessibility_average',
value: -1,
},
{
url: 'https://example.com/blog',
url: 'https://example.com:PORT/blog',
name: 'category_best-practices_average',
value: -1,
},
{
url: 'https://example.com/blog',
url: 'https://example.com:PORT/blog',
name: 'category_performance_average',
value: 0.9,
},
{
url: 'https://example.com/blog',
url: 'https://example.com:PORT/blog',
name: 'category_pwa_average',
value: 0.4,
},
{
url: 'https://example.com/blog',
url: 'https://example.com:PORT/blog',
name: 'category_seo_average',
value: 0.7,
},
Expand All @@ -537,14 +537,20 @@ function runTests(state) {
describe('/:projectId/urls', () => {
it('should list urls', async () => {
const urls = await client.getUrls(projectA.id);
expect(urls).toEqual([{url: 'https://example.com/blog'}, {url: 'https://example.com'}]);
expect(urls).toEqual([
{url: 'https://example.com:PORT/blog'},
{url: 'https://example.com:PORT/'},
]);
});
});

describe('/:projectId/builds/:buildId/urls', () => {
it('should list urls', async () => {
const urls = await client.getUrls(projectA.id, buildA.id);
expect(urls).toEqual([{url: 'https://example.com/blog'}, {url: 'https://example.com'}]);
expect(urls).toEqual([
{url: 'https://example.com:PORT/blog'},
{url: 'https://example.com:PORT/'},
]);
});
});

Expand Down

0 comments on commit f7e797e

Please sign in to comment.