Skip to content

Commit

Permalink
Add some failsafes to perf utils
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Oct 18, 2023
1 parent e84537e commit 2d265b1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions test/performance/fixtures/perf-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class PerfUtils {
* Disables the editor autosave function.
*/
async disableAutosave() {
await this.page.waitForFunction( () => window?.wp?.data );

await this.page.evaluate( () => {
return window.wp.data
.dispatch( 'core/editor' )
Expand All @@ -76,12 +78,6 @@ export class PerfUtils {
localAutosaveInterval: 100000000000,
} );
} );

const { autosaveInterval } = await this.page.evaluate( () => {
return window.wp.data.select( 'core/editor' ).getEditorSettings();
} );

expect( autosaveInterval ).toBe( 100000000000 );
}

/**
Expand Down Expand Up @@ -132,6 +128,10 @@ export class PerfUtils {
throw new Error( `File not found: ${ filepath }` );
}

await this.page.waitForFunction(
() => window?.wp?.blocks && window?.wp?.data
);

return await this.page.evaluate( ( html: string ) => {
const { parse } = window.wp.blocks;
const { dispatch } = window.wp.data;
Expand All @@ -152,6 +152,10 @@ export class PerfUtils {
* Generates and loads a 1000 empty paragraphs into the editor canvas.
*/
async load1000Paragraphs() {
await this.page.waitForFunction(
() => window?.wp?.blocks && window?.wp?.data
);

await this.page.evaluate( () => {
const { createBlock } = window.wp.blocks;
const { dispatch } = window.wp.data;
Expand Down

0 comments on commit 2d265b1

Please sign in to comment.