Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E testing: Use JSON serialization for getAllBlocks #31199

Merged
merged 3 commits into from
Apr 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/e2e-test-utils/src/get-all-blocks.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
/**
* Internal dependencies
*/
import { wpDataSelect } from './wp-data-select';

/**
* Returns an array with all blocks; Equivalent to calling wp.data.select( 'core/block-editor' ).getBlocks();
*
* @return {Promise} Promise resolving with an array containing all blocks in the document.
*/
export async function getAllBlocks() {
return wpDataSelect( 'core/block-editor', 'getBlocks' );
return page.evaluate( () => {
const blocks = window.wp.data.select( 'core/block-editor' ).getBlocks();
/**
* We are turning the result into a JSON object and back, to turn all the non-serializable
* values into `null`.
*
* `page.evaluate` returns `undefined` if it encounters a non-serializable value.
* To avoid returning `undefined`, we turn the result into a JSON string and back,
* which results in a serializable value every time.
*
* For more information see: https://github.com/WordPress/gutenberg/pull/31199
*/
return JSON.parse( JSON.stringify( blocks ) );
} );
}