Skip to content

Commit

Permalink
Fixed parameters of browser.lighthouse() function
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei_Dzeichyk authored and Andrei_Dzeichyk committed Sep 8, 2020
1 parent 852d8bf commit a85be13
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/har.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class HarHelper {
* @return {Promise<void>}
*/
stop(reportName = 'chrome_browser_har_log') {
const harFromMessages = har.harFromMessages(events);

if (typeof reportName !== 'string' || reportName.length > 200) {
const currentName = {
Expand All @@ -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));
Expand Down
19 changes: 12 additions & 7 deletions src/lighthouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,25 @@ 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<LH.RunnerResult>}
*/
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');

let result;

try {
logger.debug(url);
logger.debug({flags, config, connection});
logger.debug({flags, config, connection, reportName});

result = await lighthouseLib(url, flags, config, connection);
} catch (e) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a85be13

Please sign in to comment.