From a85be135b9d893ae0103c38ba6a0f4516644c408 Mon Sep 17 00:00:00 2001 From: Andrei_Dzeichyk Date: Wed, 9 Sep 2020 00:33:38 +0300 Subject: [PATCH] Fixed parameters of `browser.lighthouse()` function --- README.md | 4 ++-- RELEASENOTES.md | 6 ++++++ package.json | 2 +- src/har.js | 3 ++- src/lighthouse.js | 19 ++++++++++++------- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 203c6b2..e290cde 100644 --- a/README.md +++ b/README.md @@ -212,8 +212,8 @@ The `cdp` property provides to use all features of Puppeteer after merging with [Types](https://github.com/GoogleChrome/lighthouse/blob/master/types/config.d.ts#L16). * `connection` - Custom connection if it's not ChromeProtocol. If not present, the `host` and `port` are used; > [Source code](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/gather/connections/cri.js) - * `reportName` - If the 'reportName' parameter is passed, the report name will be: '%timestamp%_PID_%pid%_%reportName%.%format%'. - If not, will be the default: '%timestamp%_PID_%pid%_lighthouse_report.%format%' + * `reportName` - If the 'reportName' parameter is passed, the report name will be: '%timestamp%\_PID\_%pid%_%reportName%.%format%'. + If not, will be the default: '%timestamp%\_PID\_%pid%_lighthouse_report.%format%' During the execution Lighthouse opens a new tab, performs necessary actions, closes the tab and generates a report. More information about this class you can find here: diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 00b5536..4eaf20c 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,5 +1,11 @@ # Release notes +## 5.1.1 - 2020-09-09 + +### Added + +* Fixed parameters of `browser.lighthouse()` function + ## 5.1.0 - 2020-09-09 ### Added diff --git a/package.json b/package.json index 6286382..dc8f452 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "protractor-puppeteer-plugin", - "version": "5.1.0", + "version": "5.1.1", "description": "Plugin for merging puppeteer with protractor", "main": "index.js", "types": "index.d.ts", diff --git a/src/har.js b/src/har.js index d92ee03..6a03693 100644 --- a/src/har.js +++ b/src/har.js @@ -59,7 +59,6 @@ class HarHelper { * @return {Promise} */ stop(reportName = 'chrome_browser_har_log') { - const harFromMessages = har.harFromMessages(events); if (typeof reportName !== 'string' || reportName.length > 200) { const currentName = { @@ -70,6 +69,8 @@ class HarHelper { throw new Error(`The type of 'HAR' report prefix must be 'string' and contain no more than 200 symbols. Current ${JSON.stringify(currentName)}`); } + const harFromMessages = har.harFromMessages(events); + const name = `${new Date().valueOf()}_PID_${process.pid}_${reportName.replace(/ /gm, '_')}.har`; observe.forEach(method => this.client.removeAllListeners(method)); diff --git a/src/lighthouse.js b/src/lighthouse.js index 5d46f77..94eee14 100644 --- a/src/lighthouse.js +++ b/src/lighthouse.js @@ -40,13 +40,17 @@ class Lighthouse { /** * @param url {string} - * @param flags {LH.Flags=} - * @param config {LH.Config.Json=} - * @param connection {LH.Connection=} - * @param reportName {string=} + * @param params {{ + * flags: LH.Flags=, + * config: LH.Config.Json=, + * connection: LH.Connection=, + * reportName: string= + * }} * @return {Promise} */ - async lighthouse(url, {flags, config, connection, reportName} = defaultParams) { + async lighthouse(url, params) { + + const {flags, config, connection, reportName} = Object.assign({}, defaultParams, params); logger.info('Audit is started'); @@ -54,7 +58,7 @@ class Lighthouse { try { logger.debug(url); - logger.debug({flags, config, connection}); + logger.debug({flags, config, connection, reportName}); result = await lighthouseLib(url, flags, config, connection); } catch (e) { @@ -107,8 +111,9 @@ class Lighthouse { throw new Error(`The type of 'Lighthouse' report prefix must be 'string' and contain no more than 200 symbols. Current ${JSON.stringify(currentName)}`); } - const name = `${new Date().valueOf()}_PID_${process.pid}_${reportName}.${extension}`; + const name = `${new Date().valueOf()}_PID_${process.pid}_${reportName.replace(/ /gm, '_')}.${extension}`; + logger.debug(`Report name: '${name}'`); logger.info(`The '${extension}' report is generated'`); fileSystem.writeFileStream(data, name);