Skip to content

Commit 22e2558

Browse files
author
David Benson
committed
Modifications in response to change requests [WIP]
Strip out uneeded changes from prior commits on this branch. Add `configIsSubmitAndUpload()` to lib/index.ts Pass that fn to Sheets class. Add null value `viwerUrl` to Metrics class return object to prevent undefined type errors in Sheets paulirish#131
1 parent d770a4c commit 22e2558

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

lib/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ class PWMetrics {
9696
console.log(messages.getMessage('MEDIAN_RUN'));
9797
this.displayOutput(results.median);
9898
} else if (this.flags.submit) {
99-
const sheets = new Sheets(this.sheets, this.clientSecret);
100-
await sheets.appendResults(results.runs, this.flags.upload);
99+
const sheets = new Sheets(this.sheets, this.clientSecret, this.configIsSubmitAndUpload);
100+
await sheets.appendResults(results.runs);
101101
}
102102
}
103103

@@ -207,7 +207,6 @@ class PWMetrics {
207207
const driveResponse = await upload(data, this.clientSecret);
208208

209209
preparedData.fileId = driveResponse.id;
210-
preparedData.fileName = driveResponse.name;
211210

212211
this.view(driveResponse.id);
213212
}
@@ -235,6 +234,14 @@ class PWMetrics {
235234
return data;
236235
}
237236

237+
configIsSubmitAndUpload(data: MetricsResults) {
238+
if(this.flags.submit && this.flags.upload) {
239+
data.viewerUrl = getTimelineViewerUrl(data.fileId);
240+
}
241+
242+
return data;
243+
}
244+
238245
showChart(data: MetricsResults) {
239246
// reverse to preserve the order, because cli-chart.
240247
let timings = data.timings;

lib/metrics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ function prepareData(res: LighthouseResults): MetricsResults {
9090

9191
return {
9292
fileId: '',
93-
fileName: '',
9493
timings,
9594
timestamps,
9695
generatedTime: res.generatedTime,
9796
lighthouseVersion: res.lighthouseVersion,
9897
initialUrl: res.initialUrl,
99-
url: res.url
98+
url: res.url,
99+
viewerUrl: null
100100
};
101101
}

lib/sheets/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ const metricsIds = require('../metrics').ids;
1313
const SHEET_TYPES = {
1414
'GOOGLE_SHEETS': 'GOOGLE_SHEETS'
1515
};
16-
const VIEWER_URL_PREFIX = 'https://chromedevtools.github.io/timeline-viewer/?loadTimelineFromURL=drive://';
1716

1817
class Sheets {
19-
constructor(public config: SheetsConfig, public clientSecret: AuthorizeCredentials) {
18+
constructor(public config: SheetsConfig, public clientSecret: AuthorizeCredentials, public configIsSubmitAndUpload: Function) {
2019
this.validateOptions(config, clientSecret);
2120
}
2221

@@ -39,23 +38,20 @@ class Sheets {
3938
}
4039
}
4140

42-
appendResults(results: Array<MetricsResults>, upload: boolean) {
41+
appendResults(results: Array<MetricsResults>) {
4342
switch (this.config.type) {
4443
case SHEET_TYPES.GOOGLE_SHEETS:
45-
return this.appendResultsToGSheets(results, upload);
44+
return this.appendResultsToGSheets(results);
4645
}
4746
}
4847

49-
async appendResultsToGSheets(results: Array<MetricsResults>, upload: boolean) {
48+
async appendResultsToGSheets(results: Array<MetricsResults>) {
5049
let valuesToAppend: Array<GSheetsValuesToAppend> = [];
5150
results.forEach(data => {
5251
const getTiming = (key: string) => data.timings.find(t => t.id === key).timing;
5352
const dateObj = new Date(data.generatedTime);
54-
let viewerUrl = '';
5553

56-
if(upload && typeof data.fileId !== 'undefined') {
57-
viewerUrl = VIEWER_URL_PREFIX + data.fileId;
58-
}
54+
data = this.configIsSubmitAndUpload(data);
5955

6056
// order matters
6157
valuesToAppend.push([
@@ -70,7 +66,7 @@ class Sheets {
7066
getTiming(metricsIds.TTFI),
7167
getTiming(metricsIds.TTCI),
7268
getTiming(metricsIds.VC85),
73-
viewerUrl
69+
data.viewerUrl
7470
]);
7571
});
7672

types/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ interface FeatureFlags {
3131
expectations: Boolean;
3232
output: Boolean;
3333
chromeFlags: Array<string>;
34-
chromePath?: string
34+
chromePath?: string;
3535
port?: number;
3636
}
3737

3838
interface MetricsResults {
39-
fileName: string,
4039
fileId: string,
4140
timestamps: Timestamp[];
4241
timings: Timing[];
4342
generatedTime: string;
4443
lighthouseVersion: string;
4544
url: string;
4645
initialUrl: string;
46+
viewerUrl?: string;
4747
}
4848

4949
interface PWMetricsResults {

0 commit comments

Comments
 (0)