From e9b4e69331ce64212273a702c8f6944a97f4701c Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Fri, 7 Apr 2023 15:10:51 +0300 Subject: [PATCH 1/6] Adds to gitignore a playwright.config.override.ts entry (#49329) * adds to gitignore playwright.config.override.ts * adds docs about the override file usage --- .gitignore | 2 ++ docs/contributors/code/e2e/README.md | 42 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/.gitignore b/.gitignore index 3605aca9a61088..4a7f4708ce399a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ coverage .phpunit.result.cache .reassure + # Directories/files that may appear in your environment *.log yarn.lock @@ -37,6 +38,7 @@ test/native/junit.xml # Local overrides .wp-env.override.json +playwright.config.override.ts phpcs.xml phpunit.xml phpunit-watcher.yml diff --git a/docs/contributors/code/e2e/README.md b/docs/contributors/code/e2e/README.md index e5c4cbb534102c..ad03255cf36db9 100644 --- a/docs/contributors/code/e2e/README.md +++ b/docs/contributors/code/e2e/README.md @@ -114,3 +114,45 @@ test.describe( 'Grouping tests (@webkit, -chromium)', () => { } ); } ); ``` + +## Local configuration of Playwright + +Sometimes the deafults that Gutenberg offers for Playwright configuration need to be changed. While most configuration can be overriden by passing arguments to the test runner command line, we may want to make permanent confguration changes, such as setting the test to always run with `headless` mode set to `false` and you own custom slow motion value. + +To do this one can create a file named `playwright.config.override.ts` file in the `/test/e2e/` folder. In this new file we need to import the exiting configuration, then use the new values on top to override the defaults. + +For example: + +```ts +/** + * External dependencies + */ +import { defineConfig } from '@playwright/test'; +/** + * Internal dependencies + */ +import base from './playwright.config.ts'; + +const config = defineConfig( { + ...base, + use: { + ...base.use, + headless: true, + launchOptions: { + //slowMo: 500, + }, + trace: 'off', + screenshot: 'off', + video: 'off', + }, +} ); + +export default config; + +``` + +After making this file you can now run your tests passing the new configuration file with the `--config` argument: + +```bash +npm run test:e2e:playwright -- --config=test/e2e/playwright.override.config.ts +``` From 9cd6cc97be01beda88ad46774cfc5d3cd82a2807 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Fri, 7 Apr 2023 12:03:03 -0400 Subject: [PATCH 2/6] fix: Avoid empty Gallery block error (#49557) * fix: Avoid empty Gallery block error Setting a default function parameter avoids an error when `innerBlockImages` is `undefined`. This default function parameter may be unnecessary and masking a underlying issue. * docs: Add change log entry --- .../src/gallery/test/use-get-media.native.js | 24 +++++++++++++++++++ .../src/gallery/use-get-media.native.js | 2 +- packages/react-native-editor/CHANGELOG.md | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 packages/block-library/src/gallery/test/use-get-media.native.js diff --git a/packages/block-library/src/gallery/test/use-get-media.native.js b/packages/block-library/src/gallery/test/use-get-media.native.js new file mode 100644 index 00000000000000..67c7a8d0b5df2f --- /dev/null +++ b/packages/block-library/src/gallery/test/use-get-media.native.js @@ -0,0 +1,24 @@ +/** + * External dependencies + */ +import { render } from 'test/helpers'; + +/** + * Internal dependencies + */ +import useGetMedia from '../use-get-media'; + +describe( 'useGetMedia', () => { + // TODO: Explore why a Gallery block would ever be without inner blocks. + // This test and the associated default function parameter might be unnecessary. + it( 'should not error when receiving zero images', () => { + // Arrange + const TestSubject = () => { + useGetMedia( undefined ); + return null; + }; + + // Assert + expect( () => render( ) ).not.toThrow(); + } ); +} ); diff --git a/packages/block-library/src/gallery/use-get-media.native.js b/packages/block-library/src/gallery/use-get-media.native.js index b03defbdb49d53..6adb9d0c63ffd0 100644 --- a/packages/block-library/src/gallery/use-get-media.native.js +++ b/packages/block-library/src/gallery/use-get-media.native.js @@ -14,7 +14,7 @@ const EMPTY_IMAGE_MEDIA = []; * * @return {Array} An array of media info options for each gallery image. */ -export default function useGetMedia( innerBlockImages ) { +export default function useGetMedia( innerBlockImages = [] ) { return useSelect( ( select ) => { const imagesUploading = innerBlockImages.some( diff --git a/packages/react-native-editor/CHANGELOG.md b/packages/react-native-editor/CHANGELOG.md index e81537a8c06098..e425af19ec0890 100644 --- a/packages/react-native-editor/CHANGELOG.md +++ b/packages/react-native-editor/CHANGELOG.md @@ -10,7 +10,8 @@ For each user feature we should also add a importance categorization label to i --> ## Unreleased -- [*] Support POST requests [#49371] +- [*] Support POST requests [#49371] +- [*] Avoid empty Gallery block error [#49557] ## 1.92.0 * No User facing changes * From bdedc58483cc1116b3ceaf3bb92e5d4215aebd8e Mon Sep 17 00:00:00 2001 From: Edu Wass Date: Sat, 8 Apr 2023 02:56:05 +0200 Subject: [PATCH 3/6] Fix e2e command typos (#49669) Some typos on the commands on the ### `test-e2e` section (replace `npm run test-e2e` with `npm run test:e2e` ) --- packages/scripts/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index 1e56a3b8a96e22..96a65787c0d8b8 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -416,8 +416,8 @@ This is how you execute those scripts using the presented setup: - `npm run test:e2e` - runs all e2e tests. - `npm run test:e2e:help` - prints all available options to configure e2e test runner. -- `npm run test-e2e -- --puppeteer-interactive` - runs all e2e tests interactively. -- `npm run test-e2e FILE_NAME -- --puppeteer-interactive` - runs one test file interactively. +- `npm run test:e2e -- --puppeteer-interactive` - runs all e2e tests interactively. +- `npm run test:e2e FILE_NAME -- --puppeteer-interactive` - runs one test file interactively. - `npm run test:e2e:watch -- --puppeteer-interactive` - runs all tests interactively and watch for changes. - `npm run test:e2e:debug` - runs all tests interactively and enables [debugging tests](#debugging-e2e-tests). From 99d837a82246c94deaaa6c443015b238c2ab8fc4 Mon Sep 17 00:00:00 2001 From: Patricia Hillebrandt Date: Sat, 8 Apr 2023 03:56:06 -0300 Subject: [PATCH 4/6] Post excerpt > Ensure the postId from the block context is used to get_the_excerpt (#49495) * ensure the postId from the block context to get_the_excerpt instead of relying on the global post object. * Restructure the code for get_the_excerpt * phpcs: Align equal sign --- packages/block-library/src/post-excerpt/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/post-excerpt/index.php b/packages/block-library/src/post-excerpt/index.php index cd6d5746a239e0..24f6777b4121de 100644 --- a/packages/block-library/src/post-excerpt/index.php +++ b/packages/block-library/src/post-excerpt/index.php @@ -25,11 +25,11 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) { * wp_trim_words is used instead. */ $excerpt_length = $attributes['excerptLength']; + $excerpt = get_the_excerpt( $block->context['postId'] ); if ( isset( $excerpt_length ) ) { - $excerpt = wp_trim_words( get_the_excerpt(), $excerpt_length ); - } else { - $excerpt = get_the_excerpt(); + $excerpt = wp_trim_words( $excerpt, $excerpt_length ); } + $more_text = ! empty( $attributes['moreText'] ) ? '' . wp_kses_post( $attributes['moreText'] ) . '' : ''; $filter_excerpt_more = function( $more ) use ( $more_text ) { return empty( $more_text ) ? $more : ''; From 4fa2a874fe9c61a4609ea273425d1302ecc18bd0 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Sat, 8 Apr 2023 14:59:21 +0300 Subject: [PATCH 5/6] removes docs for test configuration override (#49660) --- docs/contributors/code/e2e/README.md | 42 ---------------------------- 1 file changed, 42 deletions(-) diff --git a/docs/contributors/code/e2e/README.md b/docs/contributors/code/e2e/README.md index ad03255cf36db9..e5c4cbb534102c 100644 --- a/docs/contributors/code/e2e/README.md +++ b/docs/contributors/code/e2e/README.md @@ -114,45 +114,3 @@ test.describe( 'Grouping tests (@webkit, -chromium)', () => { } ); } ); ``` - -## Local configuration of Playwright - -Sometimes the deafults that Gutenberg offers for Playwright configuration need to be changed. While most configuration can be overriden by passing arguments to the test runner command line, we may want to make permanent confguration changes, such as setting the test to always run with `headless` mode set to `false` and you own custom slow motion value. - -To do this one can create a file named `playwright.config.override.ts` file in the `/test/e2e/` folder. In this new file we need to import the exiting configuration, then use the new values on top to override the defaults. - -For example: - -```ts -/** - * External dependencies - */ -import { defineConfig } from '@playwright/test'; -/** - * Internal dependencies - */ -import base from './playwright.config.ts'; - -const config = defineConfig( { - ...base, - use: { - ...base.use, - headless: true, - launchOptions: { - //slowMo: 500, - }, - trace: 'off', - screenshot: 'off', - video: 'off', - }, -} ); - -export default config; - -``` - -After making this file you can now run your tests passing the new configuration file with the `--config` argument: - -```bash -npm run test:e2e:playwright -- --config=test/e2e/playwright.override.config.ts -``` From 7810f7bdc29f3ba798aee28e5c70c97d8825fda0 Mon Sep 17 00:00:00 2001 From: Aurooba Ahmed Date: Sun, 9 Apr 2023 01:39:32 -0600 Subject: [PATCH 6/6] Update documentation for setGroupingBlockName (#49670) * Update documentation for setGroupingBlockName * Add explainer text for setGroupingBlockName Add extra explainer text on what setGroupingBlockName does and that it needs to be executed once the DOM is fully loaded. * generate updated docs --- packages/blocks/README.md | 6 +++++- packages/blocks/src/api/registration.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/blocks/README.md b/packages/blocks/README.md index a7c7ba9e0d6beb..aec255ce79fee4 100644 --- a/packages/blocks/README.md +++ b/packages/blocks/README.md @@ -911,6 +911,10 @@ _Parameters_ Assigns name of block for handling block grouping interactions. +This function lets you select a different block to group other blocks in instead of the +default `core/group` block. This function must be used in a component or when the DOM is fully +loaded. See + _Usage_ ```js @@ -919,7 +923,7 @@ import { setGroupingBlockName } from '@wordpress/blocks'; const ExampleComponent = () => { return ( ); }; diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index a2d5a34d79fdf7..2c86850dc42527 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -523,6 +523,10 @@ export function setDefaultBlockName( name ) { /** * Assigns name of block for handling block grouping interactions. * + * This function lets you select a different block to group other blocks in instead of the + * default `core/group` block. This function must be used in a component or when the DOM is fully + * loaded. See https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dom-ready/ + * * @param {string} name Block name. * * @example @@ -533,7 +537,7 @@ export function setDefaultBlockName( name ) { * * return ( * * ); * };