diff --git a/lib/cli/cli.js b/lib/cli/cli.js index 845efecb0..b05df1d65 100644 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -973,6 +973,14 @@ module.exports.parseCommandLine = function parseCommandLine() { describe: 'The output format of the budget.', group: 'Budget' }) + .option('budget.removeWorkingResult', { + alias: 'budget.removePassingResult', + type: 'boolean', + describe: + 'Remove the result of URLs that pass the budget. You can use this if you many URL and only care about the ones that fails your budget. All videos/HTML for the working URLs will be removed if you pass this on.', + group: 'Budget' + }) + /** Screenshot */ .option('browsertime.screenshot', { type: 'boolean', diff --git a/lib/plugins/budget/index.js b/lib/plugins/budget/index.js index f37b652c3..b3cdfa727 100644 --- a/lib/plugins/budget/index.js +++ b/lib/plugins/budget/index.js @@ -10,6 +10,7 @@ const log = require('intel').getLogger('sitespeedio.plugin.budget'); module.exports = { open(context, options) { this.options = options; + this.budgetOptions = options.budget || {}; this.storageManager = context.storageManager; this.result = context.budget; this.make = context.messageMaker('budget').make; @@ -67,6 +68,12 @@ module.exports = { queue.postMessage(this.make('budget.result', this.result)); + if (this.budgetOptions.removeWorking) { + for (const url of Object.keys(this.result.working)) { + queue.postMessage(this.make('remove.url', {}, { url })); + } + } + for (const url of Object.keys(this.result.working)) { working = working + this.result.working[url].length; } diff --git a/lib/plugins/html/dataCollector.js b/lib/plugins/html/dataCollector.js index e1ae13046..cd0734679 100644 --- a/lib/plugins/html/dataCollector.js +++ b/lib/plugins/html/dataCollector.js @@ -32,6 +32,10 @@ class DataCollector { delete this.urlPages[url]; } + getRemovedURLs() { + return Object.keys(this.removedUrls); + } + getSummary(name) { return this.summaryPages[name]; } diff --git a/lib/plugins/html/htmlBuilder.js b/lib/plugins/html/htmlBuilder.js index 34800de2a..9e148dda6 100644 --- a/lib/plugins/html/htmlBuilder.js +++ b/lib/plugins/html/htmlBuilder.js @@ -374,7 +374,10 @@ class HTMLBuilder { merge( { options, - noPages: dataCollector.getURLs().length, + noPages: + dataCollector.getURLs().length + + dataCollector.getRemovedURLs().length, + removedUrls: dataCollector.getRemovedURLs(), css, h: helpers, rootPath: '', diff --git a/lib/plugins/html/index.js b/lib/plugins/html/index.js index bbadf66a1..fbbefe9ad 100644 --- a/lib/plugins/html/index.js +++ b/lib/plugins/html/index.js @@ -106,7 +106,7 @@ module.exports = { } case 'remove.url': { - dataCollector.removeUrl(message.url); + dataCollector._removeUrl(message.url); break; } diff --git a/lib/plugins/html/templates/pages.pug b/lib/plugins/html/templates/pages.pug index 7b00e1d95..914af1c4c 100644 --- a/lib/plugins/html/templates/pages.pug +++ b/lib/plugins/html/templates/pages.pug @@ -56,7 +56,18 @@ block content .row .column include runInfo - .responsive - table(data-sortable, id='pages') - +rowHeading(headings) - +rows(pages) + if pages.length > 0 + .responsive + table(data-sortable, id='pages') + +rowHeading(headings) + +rows(pages) + + if removedUrls.length > 0 + p The following pages was removed because they passed the budget configuration. + .responsive + table(data-sortable, id='removedpages') + +rowHeading(['URL']) + each url in removedUrls + tr + td.url.pagesurl(data-title='URL') + a(href= url)= decodeURIComponent(url)