From a8e15f3d85f903a4facdbd9da41b0fa3df6548a6 Mon Sep 17 00:00:00 2001
From: Peter Hedenskog
Date: Tue, 3 Nov 2020 13:34:48 +0100
Subject: [PATCH] If we upload to s3/gcs then wait on sending budget message
until data is uploaded (#3180)
* If we upload to s3/gcs then wait on sending budget message until data is uploaded.
* Fix uploading
* Also collect errors
---
lib/plugins/matrix/index.js | 65 +++++++++++++++++++++++++++++--------
1 file changed, 51 insertions(+), 14 deletions(-)
diff --git a/lib/plugins/matrix/index.js b/lib/plugins/matrix/index.js
index edc2999ad..eca991411 100644
--- a/lib/plugins/matrix/index.js
+++ b/lib/plugins/matrix/index.js
@@ -8,15 +8,17 @@ const cliUtil = require('../../cli/util');
const send = require('./send');
function getBrowserData(data) {
- return `${data.browser.name} ${data.browser.version} ${get(
- data,
- 'android.model',
- ''
- )} ${get(data, 'android.androidVersion', '')} ${get(
- data,
- 'android.id',
- ''
- )} `;
+ if (data && data.browser) {
+ return `${data.browser.name} ${data.browser.version} ${get(
+ data,
+ 'android.model',
+ ''
+ )} ${get(data, 'android.androidVersion', '')} ${get(
+ data,
+ 'android.id',
+ ''
+ )} `;
+ } else return '';
}
module.exports = {
@@ -33,6 +35,7 @@ module.exports = {
throwIfMissing(options.matrix, ['accessToken', 'host', 'room'], 'matrix');
this.resultUrls = context.resultUrls;
this.errorTexts = '';
+ this.waitForUpload = false;
},
async processMessage(message) {
const options = this.matrixOptions;
@@ -41,7 +44,14 @@ module.exports = {
this.browserData = message.data;
break;
}
- case 'render': {
+ case 'gcs.setup':
+ case 'ftp.setup':
+ case 's3.setup': {
+ this.waitForUpload = true;
+ break;
+ }
+
+ case 'sitespeedio.render': {
if (this.errorTexts !== '') {
const room = get(options, 'rooms.error', options.room);
try {
@@ -98,15 +108,42 @@ module.exports = {
}
text += ``;
}
- } else {
- text += `⚠️ All (${
+ }
+ if (Object.keys(message.data.error).length > 0) {
+ const errorURLs = Object.keys(message.data.error);
+ text += `⚠️ Budget errors testing ${
+ errorURLs.length
+ } URLs
`;
+ for (let url of errorURLs) {
+ text += `❌ ${url}
`;
+ text += `${message.data.error[url]}`;
+ }
+ }
+ if (
+ Object.keys(message.data.error).length === 0 &&
+ Object.keys(message.data.failing).length === 0
+ ) {
+ text += `
🎉 All (${
message.data.working.length
- } URLs passed the budget.
`;
+ }) URLs passed the budget.
`;
text += `${get(this.options, 'name', '') +
' '}${getBrowserData(this.browserData)}
`;
}
+ if (!this.waitForUpload) {
+ const room = get(options, 'rooms.budget', options.room);
+ await send(options.host, room, options.accessToken, text);
+ } else {
+ this.budgetText = text;
+ }
+ }
+ break;
+ }
+ case 'gcs.finished':
+ case 'ftp.finished':
+ case 's3.finished': {
+ if (this.waitForUpload && options.messages.indexOf('budget') > -1) {
const room = get(options, 'rooms.budget', options.room);
- await send(options.host, room, options.accessToken, text);
+ await send(options.host, room, options.accessToken, this.budgetText);
}
break;
}