From 855571c6ba83dd91b21e49a61449c3b07f7674c7 Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Sun, 3 Nov 2019 19:04:11 +0100 Subject: [PATCH] Run without cli (#2746) * Make sure we fail on errors * Fix failing code --- lib/plugins/browsertime/filmstrip.js | 3 ++- .../html/templates/url/iteration/index.pug | 2 +- .../html/templates/url/iteration/tabs.pug | 2 +- .../html/templates/url/summary/index.pug | 2 +- .../html/templates/url/summary/tabs.pug | 2 +- test/runWithoutCli.js | 26 ++++++++++--------- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/plugins/browsertime/filmstrip.js b/lib/plugins/browsertime/filmstrip.js index f9bf57456..3725561c0 100644 --- a/lib/plugins/browsertime/filmstrip.js +++ b/lib/plugins/browsertime/filmstrip.js @@ -125,7 +125,8 @@ function findTimings(timings, start, end) { module.exports = { async getFilmstrip(browsertimeData, run, dir, options, fullPath) { let doWeHaveFilmstrip = - options.browsertime.chrome.enableTraceScreenshots === true || + (options.browsertime.chrome && + options.browsertime.chrome.enableTraceScreenshots === true) || (options.browsertime.visualMetrics === true && options.browsertime.videoParams.createFilmstrip === true); diff --git a/lib/plugins/html/templates/url/iteration/index.pug b/lib/plugins/html/templates/url/iteration/index.pug index 3b2ac1d47..925ab7e7b 100644 --- a/lib/plugins/html/templates/url/iteration/index.pug +++ b/lib/plugins/html/templates/url/iteration/index.pug @@ -131,7 +131,7 @@ block content section#video-panel include ../video/index.pug - if (options.browsertime.video || options.browsertime.visualMetrics) && options.videoParams.createFilmstrip || options.browsertime.chrome.enableTraceScreenshots + if (options.browsertime.video || options.browsertime.visualMetrics) && options.videoParams.createFilmstrip || options.browsertime.chrome && options.browsertime.chrome.enableTraceScreenshots section#filmstrip-panel include ../filmstrip/index.pug diff --git a/lib/plugins/html/templates/url/iteration/tabs.pug b/lib/plugins/html/templates/url/iteration/tabs.pug index 9523e734b..bd08c79c0 100644 --- a/lib/plugins/html/templates/url/iteration/tabs.pug +++ b/lib/plugins/html/templates/url/iteration/tabs.pug @@ -10,7 +10,7 @@ if options.browsertime.video a(id='video', href='#video', onclick='return selectTab(this, true);') | Video - if (options.browsertime.visualMetrics && options.videoParams.createFilmstrip) || options.browsertime.chrome.enableTraceScreenshots + if (options.browsertime.visualMetrics && options.videoParams.createFilmstrip) || options.browsertime.chrome && options.browsertime.chrome.enableTraceScreenshots a(id='filmstrip', href='#filmstrip', onclick='return selectTab(this, true);') | Filmstrip if d.coach && d.coach.run diff --git a/lib/plugins/html/templates/url/summary/index.pug b/lib/plugins/html/templates/url/summary/index.pug index e40dea847..ff3cf3fc1 100644 --- a/lib/plugins/html/templates/url/summary/index.pug +++ b/lib/plugins/html/templates/url/summary/index.pug @@ -136,7 +136,7 @@ block content section#video-panel include ../video/index.pug - if (options.browsertime.video || options.browsertime.visualMetrics) && options.videoParams.createFilmstrip || options.browsertime.chrome.enableTraceScreenshots + if (options.browsertime.video || options.browsertime.visualMetrics) && options.videoParams.createFilmstrip || options.browsertime.chrome && options.browsertime.chrome.enableTraceScreenshots section#filmstrip-panel include ../filmstrip/index.pug diff --git a/lib/plugins/html/templates/url/summary/tabs.pug b/lib/plugins/html/templates/url/summary/tabs.pug index 755052e07..6686e491c 100644 --- a/lib/plugins/html/templates/url/summary/tabs.pug +++ b/lib/plugins/html/templates/url/summary/tabs.pug @@ -10,7 +10,7 @@ if options.browsertime.video a(id='video', href='#video', onclick='return selectTab(this, true);') | Video - if (options.browsertime.visualMetrics && options.videoParams.createFilmstrip) || options.browsertime.chrome.enableTraceScreenshots + if (options.browsertime.visualMetrics && options.videoParams.createFilmstrip) || options.browsertime.chrome && options.browsertime.chrome.enableTraceScreenshots a(id='filmstrip', href='#filmstrip', onclick='return selectTab(this, true);') | Filmstrip if d.coach && d.coach.pageSummary diff --git a/test/runWithoutCli.js b/test/runWithoutCli.js index 287de3f3e..1b6514aa2 100644 --- a/test/runWithoutCli.js +++ b/test/runWithoutCli.js @@ -1,9 +1,9 @@ const sitespeed = require('../lib/sitespeed'); const urls = ['https://www.sitespeed.io/']; -function run() { - sitespeed - .run({ +async function run() { + try { + let result = await sitespeed.run({ urls, browsertime: { iterations: 1, @@ -12,18 +12,20 @@ function run() { profile: 'native' } } - }) - .then(results => { - if (results.error) { - throw new Error(results.error); - } - }) - .catch(err => { + }); + + if (result.errors.length > 0) { /* eslint-disable no-console */ - console.error(err); + console.error(result.errors); /* eslint-enable no-console */ process.exit(1); - }); + } + } catch (e) { + /* eslint-disable no-console */ + console.error(e); + /* eslint-enable no-console */ + process.exit(1); + } } run();