Skip to content

Commit

Permalink
Async parse in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Jul 5, 2023
1 parent 408abe2 commit 283e25a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function gutenberg_menu() {
// disable loading and enqueuing block editor scripts and styles
add_filter( 'should_load_block_editor_scripts_and_styles', '__return_false', 11 );

add_filter( 'should_load_separate_core_block_assets', '__return_true' );
// add_filter( 'should_load_separate_core_block_assets', '__return_true' );

// Add `editorScript` to Gutenberg block.json data if it's missing
function add_core_editor_script( $metadata ) {
Expand Down
1 change: 1 addition & 0 deletions packages/blocks/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export {
setGroupingBlockName,
getGroupingBlockName,
getBlockType,
loadBlockType,
getBlockTypes,
getBlockSupport,
hasBlockSupport,
Expand Down
5 changes: 0 additions & 5 deletions packages/blocks/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ export function getBlockType( state, name ) {
return state.blockTypes[ name ];
}

// export function loadBlockType( state, name ) {
// const blockType = state.blockTypes[ name ];
// return blockType;
// }

/**
* Returns block styles by block name.
*
Expand Down
9 changes: 5 additions & 4 deletions packages/e2e-tests/specs/performance/post-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ import {
jest.setTimeout( 1000000 );

async function loadHtmlIntoTheBlockEditor( html ) {
await page.evaluate( ( _html ) => {
await page.evaluate( async ( _html ) => {
const { parse } = window.wp.blocks;
const { dispatch } = window.wp.data;
const blocks = parse( _html );
const blocks = await parse( _html );

blocks.forEach( ( block ) => {
if ( block.name === 'core/image' ) {
Expand All @@ -54,9 +54,10 @@ async function loadHtmlIntoTheBlockEditor( html ) {
}

async function load1000Paragraphs() {
await page.evaluate( () => {
const { createBlock } = window.wp.blocks;
await page.evaluate( async () => {
const { loadBlockType, createBlock } = window.wp.blocks;
const { dispatch } = window.wp.data;
await loadBlockType( 'core/paragraph' );
const blocks = Array.from( { length: 1000 } ).map( () =>
createBlock( 'core/paragraph' )
);
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/specs/performance/site-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ describe( 'Site Editor Performance', () => {

await createNewPost( { postType: 'page' } );

await page.evaluate( ( _html ) => {
await page.evaluate( async ( _html ) => {
const { parse } = window.wp.blocks;
const { dispatch } = window.wp.data;
const blocks = parse( _html );
const blocks = await parse( _html );

blocks.forEach( ( block ) => {
if ( block.name === 'core/image' ) {
Expand Down
9 changes: 5 additions & 4 deletions test/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ export async function loadBlocksFromHtml( page, filepath ) {
throw new Error( `File not found (${ filepath })` );
}

return await page.evaluate( ( html ) => {
return await page.evaluate( async ( html ) => {
const { parse } = window.wp.blocks;
const { dispatch } = window.wp.data;
const blocks = parse( html );
const blocks = await parse( html );

blocks.forEach( ( block ) => {
if ( block.name === 'core/image' ) {
Expand All @@ -172,9 +172,10 @@ export async function loadBlocksFromHtml( page, filepath ) {
}

export async function load1000Paragraphs( page ) {
await page.evaluate( () => {
const { createBlock } = window.wp.blocks;
await page.evaluate( async () => {
const { loadBlockType, createBlock } = window.wp.blocks;
const { dispatch } = window.wp.data;
await loadBlockType( 'core/paragraph' );
const blocks = Array.from( { length: 1000 } ).map( () =>
createBlock( 'core/paragraph' )
);
Expand Down

0 comments on commit 283e25a

Please sign in to comment.