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

test: Improve mobile editor performance tests #48101

Merged
Merged
Show file tree
Hide file tree
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
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' ] },
],
},
Comment on lines +3 to +8
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As referenced in the Reassure docs, this has the linter consider measurePerformance an assertion.

It is possible there may be a better location to place this new configuration, but the test-unit file did seem appropriate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good call. I agree this is better than forcing the other assertions.

};
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