Feed plugins with messageMaker (#1760)
This commit is contained in:
parent
3da3493adb
commit
e81be5d689
|
|
@ -1,16 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
const messageMaker = require('../../support/messageMaker');
|
||||
const isEmpty = require('lodash.isempty');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const aggregator = require('./aggregator');
|
||||
|
||||
const make = messageMaker('assets').make;
|
||||
|
||||
const DEFAULT_METRICS_LARGEST_ASSETS = ['image.0.transferSize'];
|
||||
|
||||
module.exports = {
|
||||
open(context, options) {
|
||||
this.make = context.messageMaker('assets').make;
|
||||
this.options = options;
|
||||
this.resultUrls = context.resultUrls;
|
||||
filterRegistry.registerFilterForType(
|
||||
|
|
@ -23,6 +20,7 @@ module.exports = {
|
|||
filterRegistry.registerFilterForType([], 'largestthirdpartyassets.summary');
|
||||
},
|
||||
processMessage(message, queue) {
|
||||
const make = this.make;
|
||||
switch (message.type) {
|
||||
case 'pagexray.run': {
|
||||
aggregator.addToAggregate(
|
||||
|
|
@ -41,7 +39,9 @@ module.exports = {
|
|||
if (!isEmpty(summary)) {
|
||||
for (let group of Object.keys(summary.groups)) {
|
||||
queue.postMessage(
|
||||
make('aggregateassets.summary', summary.groups[group], { group })
|
||||
make('aggregateassets.summary', summary.groups[group], {
|
||||
group
|
||||
})
|
||||
);
|
||||
|
||||
queue.postMessage(
|
||||
|
|
@ -49,7 +49,9 @@ module.exports = {
|
|||
);
|
||||
|
||||
queue.postMessage(
|
||||
make('slowestassets.summary', summary.timing[group], { group })
|
||||
make('slowestassets.summary', summary.timing[group], {
|
||||
group
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
const browsertime = require('browsertime');
|
||||
const Promise = require('bluebird');
|
||||
const messageMaker = require('../../support/messageMaker');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const aggregator = require('./aggregator');
|
||||
const api = require('webcoach');
|
||||
|
|
@ -14,8 +13,6 @@ const analyzer = require('./analyzer');
|
|||
const moment = require('moment');
|
||||
const isEmpty = require('lodash.isempty');
|
||||
|
||||
const make = messageMaker('browsertime').make;
|
||||
|
||||
const visitedUrls = new Set();
|
||||
|
||||
const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
|
||||
|
|
@ -80,6 +77,7 @@ const DEFAULT_METRICS_SUMMARY = [
|
|||
module.exports = {
|
||||
concurrency: 1,
|
||||
open(context, options) {
|
||||
this.make = context.messageMaker('browsertime').make;
|
||||
this.options = merge({}, defaultConfig, options.browsertime);
|
||||
this.firstParty = options.firstParty;
|
||||
this.options.mobile = options.mobile;
|
||||
|
|
@ -107,6 +105,7 @@ module.exports = {
|
|||
);
|
||||
},
|
||||
processMessage(message, queue) {
|
||||
const make = this.make;
|
||||
function processCoachOutput(url, group, results) {
|
||||
return Promise.resolve(results.browserScripts).each((run, runIndex) => {
|
||||
const coachAdvice = run.coach.coachAdvice;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
const messageMaker = require('../../support/messageMaker');
|
||||
const aggregator = require('./aggregator');
|
||||
const pagexrayAggregator = require('./pagexrayAggregator');
|
||||
const pagexray = require('pagexray');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
|
||||
const make = messageMaker('coach').make;
|
||||
|
||||
const DEFAULT_METRICS_SUMMARY = [
|
||||
'score.*',
|
||||
'performance.score.*',
|
||||
|
|
@ -56,6 +52,8 @@ const DEFAULT_PAGEXRAY_SUMMARY_METRICS = [
|
|||
module.exports = {
|
||||
open(context, options) {
|
||||
this.options = options;
|
||||
this.make = context.messageMaker('coach').make;
|
||||
|
||||
filterRegistry.registerFilterForType(
|
||||
DEFAULT_METRICS_SUMMARY,
|
||||
'coach.summary'
|
||||
|
|
@ -74,6 +72,7 @@ module.exports = {
|
|||
);
|
||||
},
|
||||
processMessage(message, queue) {
|
||||
const make = this.make;
|
||||
switch (message.type) {
|
||||
case 'coach.run': {
|
||||
if (message.runIndex === 0) {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@ const Promise = require('bluebird');
|
|||
const path = require('path');
|
||||
const merge = require('lodash.merge');
|
||||
const log = require('intel').getLogger('sitespeedio.plugin.crawler');
|
||||
const messageMaker = require('../../support/messageMaker');
|
||||
const Crawler = require('simplecrawler');
|
||||
|
||||
const make = messageMaker('crawler').make;
|
||||
|
||||
const defaultOptions = {
|
||||
depth: 3
|
||||
};
|
||||
|
|
@ -16,8 +13,10 @@ const defaultOptions = {
|
|||
module.exports = {
|
||||
open(context, options) {
|
||||
this.options = merge({}, defaultOptions, options.crawler);
|
||||
this.make = context.messageMaker('crawler').make;
|
||||
},
|
||||
processMessage(message, queue) {
|
||||
const make = this.make;
|
||||
if (message.type === 'url' && message.source !== 'crawler') {
|
||||
const maxPages = this.options.maxPages || Number.MAX_SAFE_INTEGER;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
const messageMaker = require('../../support/messageMaker');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const isEmpty = require('lodash.isempty');
|
||||
const aggregator = require('./aggregator');
|
||||
|
||||
const make = messageMaker('domains').make;
|
||||
|
||||
module.exports = {
|
||||
open() {
|
||||
open(context) {
|
||||
this.make = context.messageMaker('domains').make;
|
||||
// '*.requestCounts, 'domains.summary'
|
||||
filterRegistry.registerFilterForType([], 'domains.summary');
|
||||
},
|
||||
processMessage(message, queue) {
|
||||
const make = this.make;
|
||||
switch (message.type) {
|
||||
case 'browsertime.har': {
|
||||
aggregator.addToAggregate(message.data, message.url);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
const messageMaker = require('../../support/messageMaker');
|
||||
const aggregator = require('./aggregator');
|
||||
const log = require('intel').getLogger('sitespeedio.plugin.gpsi');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const analyzer = require('./analyzer');
|
||||
|
||||
const make = messageMaker('gpsi').make;
|
||||
const DEFAULT_METRICS_PAGESUMMARY = ['ruleGroups.SPEED.score'];
|
||||
|
||||
module.exports = {
|
||||
open(context, options) {
|
||||
this.make = context.messageMaker('gpsi').make;
|
||||
this.options = {
|
||||
gpsi: options.gpsi,
|
||||
mobile: options.mobile
|
||||
|
|
@ -21,6 +20,7 @@ module.exports = {
|
|||
);
|
||||
},
|
||||
processMessage(message, queue) {
|
||||
const make = this.make;
|
||||
switch (message.type) {
|
||||
case 'url': {
|
||||
const url = message.url;
|
||||
|
|
|
|||
|
|
@ -5,11 +5,8 @@ const HTMLBuilder = require('./htmlBuilder');
|
|||
const get = require('lodash.get');
|
||||
const set = require('lodash.set');
|
||||
const reduce = require('lodash.reduce');
|
||||
const messageMaker = require('../../support/messageMaker');
|
||||
const DataCollector = require('../../support/dataCollector');
|
||||
|
||||
const make = messageMaker('html').make;
|
||||
|
||||
// lets keep this in the HTML context, since we need things from the
|
||||
// regular options object in the output
|
||||
const defaultConfig = {
|
||||
|
|
@ -20,6 +17,7 @@ const defaultConfig = {
|
|||
|
||||
module.exports = {
|
||||
open(context, options) {
|
||||
this.make = context.messageMaker('html').make;
|
||||
this.options = merge({}, defaultConfig, options);
|
||||
this.HTMLBuilder = new HTMLBuilder(context, this.options);
|
||||
this.dataCollector = new DataCollector(context);
|
||||
|
|
@ -27,6 +25,7 @@ module.exports = {
|
|||
},
|
||||
processMessage(message, queue) {
|
||||
const dataCollector = this.dataCollector;
|
||||
const make = this.make;
|
||||
|
||||
if (
|
||||
message.type.endsWith('.run') ||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ const s3 = require('s3');
|
|||
const throwIfMissing = require('../../support/util').throwIfMissing;
|
||||
const fs = require('fs-extra');
|
||||
const pick = require('lodash.pick');
|
||||
const messageMaker = require('../../support/messageMaker');
|
||||
const make = messageMaker('s3').make;
|
||||
|
||||
function createS3Client(s3Options) {
|
||||
const clientOptions = pick(s3Options, [
|
||||
|
|
@ -29,6 +27,7 @@ function createS3Client(s3Options) {
|
|||
module.exports = {
|
||||
open(context, options) {
|
||||
this.s3Options = options.s3;
|
||||
this.make = context.messageMaker('s3').make;
|
||||
|
||||
throwIfMissing(this.s3Options, ['bucketname'], 's3');
|
||||
if (this.s3Options.key || this.s3Options.secret) {
|
||||
|
|
@ -38,6 +37,7 @@ module.exports = {
|
|||
},
|
||||
|
||||
processMessage(message, queue) {
|
||||
const make = this.make;
|
||||
if (message.type === 'html.finished') {
|
||||
const s3Options = this.s3Options;
|
||||
const client = createS3Client(s3Options);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const urlParser = require('url');
|
||||
const messageMaker = require('../../support/messageMaker');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const analyzer = require('./analyzer');
|
||||
const aggregator = require('./aggregator');
|
||||
|
|
@ -11,8 +10,6 @@ const get = require('lodash.get');
|
|||
const log = require('intel').getLogger('sitespeedio.plugin.webpagetest');
|
||||
const WebPageTest = require('webpagetest');
|
||||
|
||||
const make = messageMaker('webpagetest').make;
|
||||
|
||||
const DEFAULT_PAGE_SUMMARY_METRICS = [
|
||||
'data.median.*.SpeedIndex',
|
||||
'data.median.*.render',
|
||||
|
|
@ -69,6 +66,7 @@ function isPublicWptHost(address) {
|
|||
|
||||
module.exports = {
|
||||
open(context, options) {
|
||||
this.make = context.messageMaker('webpagetest').make;
|
||||
this.options = merge({}, defaultConfig, options.webpagetest);
|
||||
this.storageManager = context.storageManager;
|
||||
if (!this.options.key && isPublicWptHost(this.options.host)) {
|
||||
|
|
@ -87,6 +85,7 @@ module.exports = {
|
|||
);
|
||||
},
|
||||
processMessage(message, queue) {
|
||||
const make = this.make;
|
||||
const wptOptions = this.options;
|
||||
switch (message.type) {
|
||||
case 'url': {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ const Promise = require('bluebird'),
|
|||
union = require('lodash.union'),
|
||||
browsertimeConfig = require('./plugins/browsertime').config,
|
||||
webpagetestConfig = require('./plugins/webpagetest').config,
|
||||
messageMaker = require('./support/messageMaker'),
|
||||
packageInfo = require('../package');
|
||||
|
||||
const QueueHandler = require('./support/queueHandler'),
|
||||
|
|
@ -145,7 +146,8 @@ module.exports = {
|
|||
timestamp,
|
||||
budget: budgetResult,
|
||||
name: url,
|
||||
log
|
||||
log,
|
||||
messageMaker
|
||||
};
|
||||
return runOptionalFunction(allPlugins, 'open', context, options)
|
||||
.then(() => queueHandler.run(urlSources))
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ const aggregator = require('../lib/plugins/webpagetest/aggregator');
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const expect = require('chai').expect;
|
||||
const messageMaker = require('../lib/support/messageMaker');
|
||||
|
||||
const wptResultPath = path.resolve(
|
||||
__dirname,
|
||||
|
|
@ -16,16 +17,22 @@ const wptResult = JSON.parse(fs.readFileSync(wptResultPath, 'utf8'));
|
|||
describe('webpagetest', () => {
|
||||
describe('plugin', () => {
|
||||
it('should require key for default server', () => {
|
||||
expect(() => plugin.open({}, {})).to.throw();
|
||||
expect(() => plugin.open({ messageMaker }, {})).to.throw();
|
||||
});
|
||||
it('should require key for public server', () => {
|
||||
expect(() =>
|
||||
plugin.open({}, { webpagetest: { host: 'www.webpagetest.org' } })
|
||||
plugin.open(
|
||||
{ messageMaker },
|
||||
{ webpagetest: { host: 'www.webpagetest.org' } }
|
||||
)
|
||||
).to.throw();
|
||||
});
|
||||
it('should not require key for private server', () => {
|
||||
expect(() =>
|
||||
plugin.open({}, { webpagetest: { host: 'http://myserver.foo' } })
|
||||
plugin.open(
|
||||
{ messageMaker },
|
||||
{ webpagetest: { host: 'http://myserver.foo' } }
|
||||
)
|
||||
).to.not.throw();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue