Skip to content

Commit

Permalink
test: Improve mobile editor performance tests (#48101)
Browse files Browse the repository at this point in the history
* test: Linter considers measurePerfomrance an assertion

Performance tests often only assert the performance of a component via
`measurePerformance`. This change adds `measurePerformance` to the list
of functions that are considered assertions to avoid erroneous lint
warnings.

* test: Fix errors in Rich Text performance test

- Remove unnecessary lint warning disable line caused by erroneous
  placement of `screen` argument.
- Query UI components via user-facing attributes, e.g. a11y label.
- Pass mock function to required `onChange` prop to `RichText`
  component.

* test: Rename native editor performance test files

To avoid web test scripts from including the performance files for the
native mobile editor, we must include the term "native" in the file
name. This renames the test files to follow the existing pattern of not
including "test" in the file name.
  • Loading branch information
dcalhoun authored Feb 16, 2023
1 parent 2eafbf3 commit df136ad
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
changeTextOfRichText,
fireEvent,
measurePerformance,
screen,
} from 'test/helpers';

/**
Expand All @@ -13,23 +14,19 @@ import {
import { RichText } from '@wordpress/block-editor';

describe( 'RichText Performance', () => {
// eslint-disable-next-line jest/no-done-callback
it( 'performance is stable', async ( screen ) => {
it( 'performance is stable', async () => {
const scenario = async () => {
const richTextInput = screen.getByTestId( 'performance' );
const richTextInput = screen.getByLabelText( 'Text input. Empty' );

fireEvent( richTextInput, 'focus' );

changeTextOfRichText(
richTextInput,
'<strong>Bold</strong> <em>italic</em> <s>strikethrough</s> text'
);

// Check if the onChange is called and the state is updated.
expect( changeTextOfRichText ).toHaveBeenCalledTimes( 1 );
};

await measurePerformance( <RichText testID="performance" />, {
await measurePerformance( <RichText onChange={ jest.fn() } />, {
scenario,
} );
} );
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-plugin/configs/test-unit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module.exports = {
extends: [ 'plugin:jest/recommended' ],
rules: {
'jest/expect-expect': [
'error',
{ assertFunctionNames: [ 'expect', 'measurePerformance' ] },
],
},
};
2 changes: 1 addition & 1 deletion packages/react-native-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"test": "cross-env NODE_ENV=test jest --verbose --config ../../test/native/jest.config.js",
"test:debug": "cross-env NODE_ENV=test node --inspect-brk ../../node_modules/.bin/jest --runInBand --verbose --config ../../test/native/jest.config.js",
"test:update": "npm run test -- --updateSnapshot",
"test:perf": "cross-env NODE_ENV=test TEST_RUNNER_PATH=../../node_modules/.bin/jest TEST_RUNNER_ARGS='--runInBand --testMatch \"<rootDir>/**/*.perf-test.[jt]s?(x)\" --verbose --config ../../test/native/jest.config.js' reassure",
"test:perf": "cross-env NODE_ENV=test TEST_RUNNER_PATH=../../node_modules/.bin/jest TEST_RUNNER_ARGS='--runInBand --testMatch \"<rootDir>/**/*.perf-native.[jt]s?(x)\" --verbose --config ../../test/native/jest.config.js' reassure",
"device-tests": "cross-env NODE_ENV=test jest --forceExit --detectOpenHandles --no-cache --maxWorkers=3 --testPathIgnorePatterns=@canary --verbose --config ./jest_ui.config.js",
"device-tests-canary": "cross-env NODE_ENV=test jest --forceExit --detectOpenHandles --no-cache --maxWorkers=2 --testPathPattern=@canary --verbose --config ./jest_ui.config.js",
"device-tests:local": "cross-env NODE_ENV=test jest --runInBand --detectOpenHandles --verbose --forceExit --config ./jest_ui.config.js",
Expand Down

0 comments on commit df136ad

Please sign in to comment.