Skip to content

Commit

Permalink
Add stopAsFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore committed Feb 11, 2024
1 parent 54d8788 commit b71eca0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
19 changes: 17 additions & 2 deletions lib/core/engine/command/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,21 @@ export class Measure {
}
}

/**
* Stop the current measurement and mark it as a failure. This stop function will not measure anything on a page. This is useful if you need to stop a measurement in a (try) catch and you
* know something has failed.
*
* @async
* @param {string} failureMessage - The message about the failure. This will end up on the HTML report for sitespeed.io so give it a good message so you know what's gone wrong.
* @param {string} optionalURL - The URL of the page that you wanted to test. If you don't know the URL (you clicked on a link etc) skip it.
* @returns {Promise} A promise that resolves when the stop process has completed.
* @since 21.2.0
*/
async stopAsFailure(failureMessage, optionalURL) {
this.areWeMeasuring = false;
this._failure(failureMessage);
return this.stop(optionalURL, false);
}
/**
* Stops the measurement process, collects metrics, and handles any post-measurement tasks.
* It finalizes the URL being tested, manages any URL-specific metadata, stops any ongoing video recordings,
Expand All @@ -382,7 +397,7 @@ export class Measure {
* @throws {Error} Throws an error if there are issues in stopping the measurement or collecting data.
* @returns {Promise} A promise that resolves with the collected metrics data.
*/
async stop(testedStartUrl) {
async stop(testedStartUrl, collectMeasurements = true) {
log.debug('Stop measuring');
// If we don't have a URL (tested using clicking on link etc) get the URL from the browser
let url =
Expand Down Expand Up @@ -448,7 +463,7 @@ export class Measure {
await this.tcpDump.stop();
}

return this.collect(url);
return collectMeasurements === false ? undefined : this.collect(url);
}

/**
Expand Down
13 changes: 12 additions & 1 deletion types/core/engine/command/measure.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ export class Measure {
* @returns {Promise<void>} A promise that resolves when the start process is complete, or rejects if there are errors.
*/
start(urlOrAlias: string, optionalAlias?: string): Promise<void>;
/**
* Stop the current measurement and mark it as a failure. This stop function will not measure anything on a page. This is useful if you need to stop a measurement in a (try) catch and you
* know something has failed.
*
* @async
* @param {string} failureMessage - The message about the failure. This will end up on the HTML report for sitespeed.io so give it a good message so you know what's gone wrong.
* @param {string} optionalURL - The URL of the page that you wanted to test. If you don't know the URL (you clicked on a link etc) skip it.
* @returns {Promise} A promise that resolves when the stop process has completed.
* @since 21.2.0
*/
stopAsFailure(failureMessage: string, optionalURL: string): Promise<any>;
/**
* Stops the measurement process, collects metrics, and handles any post-measurement tasks.
* It finalizes the URL being tested, manages any URL-specific metadata, stops any ongoing video recordings,
Expand All @@ -165,7 +176,7 @@ export class Measure {
* @throws {Error} Throws an error if there are issues in stopping the measurement or collecting data.
* @returns {Promise} A promise that resolves with the collected metrics data.
*/
stop(testedStartUrl: string): Promise<any>;
stop(testedStartUrl: string, collectMeasurements?: boolean): Promise<any>;
/**
* Adds a custom metric to the current measurement result.
* This method should be called after a measurement has started and before it has stopped.
Expand Down
2 changes: 1 addition & 1 deletion types/core/engine/command/measure.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b71eca0

Please sign in to comment.