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

RichText: add faster, separate e2e tests #17303

Closed
wants to merge 5 commits into from
Closed
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
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ jobs:
- $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
- $( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 3' < ~/.jest-e2e-tests )

- name: E2E tests (packages)
env: FORCE_REDUCED_MOTION=true PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=
install:
- npm ci
script:
- npm run test-package-e2e packages/rich-text

allow_failures:
- name: JavaScript native mobile tests

Expand Down
8 changes: 8 additions & 0 deletions bin/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
...require( '@wordpress/scripts/config/jest-e2e.config' ),
setupFilesAfterEnv: [
'@wordpress/jest-console',
'@wordpress/jest-puppeteer-axe',
'expect-puppeteer',
],
};
43 changes: 43 additions & 0 deletions bin/setup-packages-e2e-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'test';
process.env.NODE_ENV = 'test';
process.env.JEST_PUPPETEER_CONFIG = 'packages/scripts/config/puppeteer.config.js';

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on( 'unhandledRejection', ( err ) => {
throw err;
} );

/**
* External dependencies
*/
const Bundler = require( 'parcel-bundler' );
const { join, resolve } = require( 'path' );
// eslint-disable-next-line jest/no-jest-import
const jest = require( 'jest' );

const bundler = new Bundler(
join( __dirname, '../packages/rich-text/setup/index.html' ),
{
outDir: '../packages/rich-text/setup-dist',
}
);

bundler.on( 'buildEnd', () => {
Copy link
Member

Choose a reason for hiding this comment

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

You can also start a server using jest-puppeteer which might easier with parcel:
https://github.com/smooth-code/jest-puppeteer#start-a-server

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not immediately obvious to me how this would work. We'd still need parcel, right?

Copy link
Member

Choose a reason for hiding this comment

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

yes, but it's less work to do it through config

jest.run( [
'--config',
'bin/jest.config.js',
'--rootDir',
resolve( __dirname, '..' ),
'--runInBand',
...process.argv.slice( 2 ),
] ).then( () => {
process.exit( 0 );
} ).catch( () => {
process.exit( 1 );
} );
} );

bundler.serve();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@
"playground:build": "npm run build:packages && parcel build playground/src/index.html -d playground/dist",
"playground:start": "concurrently \"npm run dev:packages\" \"parcel playground/src/index.html -d playground/dist\"",
"preenv": "npm run check-engines",
"env": "wp-scripts env"
"env": "wp-scripts env",
"test-package-e2e": "node ./bin/setup-packages-e2e-tests.js"
},
"lint-staged": {
"packages/*/package.json": [
Expand Down
36 changes: 0 additions & 36 deletions packages/e2e-tests/specs/__snapshots__/rich-text.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RichText should apply formatting when selection is collapsed 1`] = `
"<!-- wp:paragraph -->
<p>Some <strong>bold</strong>.</p>
<!-- /wp:paragraph -->"
`;

exports[`RichText should apply formatting with primary shortcut 1`] = `
"<!-- wp:paragraph -->
<p><strong>test</strong></p>
<!-- /wp:paragraph -->"
`;

exports[`RichText should apply multiple formats when selection is collapsed 1`] = `
"<!-- wp:paragraph -->
<p><strong><em>1</em></strong>.</p>
<!-- /wp:paragraph -->"
`;

exports[`RichText should handle Home and End keys 1`] = `
"<!-- wp:paragraph -->
<p>-<strong>12</strong>+</p>
<!-- /wp:paragraph -->"
`;

exports[`RichText should handle change in tag name gracefully 1`] = `
"<!-- wp:heading {\\"level\\":3} -->
<h3></h3>
Expand All @@ -42,28 +24,10 @@ exports[`RichText should not format text after code backtick 1`] = `
<!-- /wp:paragraph -->"
`;

exports[`RichText should not lose selection direction 1`] = `
"<!-- wp:paragraph -->
<p><strong>1</strong>2-3</p>
<!-- /wp:paragraph -->"
`;

exports[`RichText should not undo backtick transform with backspace after selection change 1`] = `""`;

exports[`RichText should not undo backtick transform with backspace after typing 1`] = `""`;

exports[`RichText should only mutate text data on input 1`] = `
"<!-- wp:paragraph -->
<p>1<strong>2</strong>34</p>
<!-- /wp:paragraph -->"
`;

exports[`RichText should return focus when pressing formatting button 1`] = `
"<!-- wp:paragraph -->
<p>Some <strong>bold</strong>.</p>
<!-- /wp:paragraph -->"
`;

exports[`RichText should transform backtick to code 1`] = `
"<!-- wp:paragraph -->
<p>A <code>backtick</code></p>
Expand Down
30 changes: 0 additions & 30 deletions packages/e2e-tests/specs/__snapshots__/rtl.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RTL should arrow navigate 1`] = `
"<!-- wp:paragraph -->
<p>٠١٢</p>
<!-- /wp:paragraph -->"
`;

exports[`RTL should arrow navigate between blocks 1`] = `
"<!-- wp:paragraph -->
<p>٠<br>١</p>
Expand All @@ -28,30 +22,6 @@ exports[`RTL should merge forward 1`] = `
<!-- /wp:paragraph -->"
`;

exports[`RTL should navigate inline boundaries 1`] = `
"<!-- wp:paragraph -->
<p><strong>١</strong>٠٢</p>
<!-- /wp:paragraph -->"
`;

exports[`RTL should navigate inline boundaries 2`] = `
"<!-- wp:paragraph -->
<p><strong>١٠</strong>٢</p>
<!-- /wp:paragraph -->"
`;

exports[`RTL should navigate inline boundaries 3`] = `
"<!-- wp:paragraph -->
<p><strong>٠١</strong>٢</p>
<!-- /wp:paragraph -->"
`;

exports[`RTL should navigate inline boundaries 4`] = `
"<!-- wp:paragraph -->
<p>٠<strong>١</strong>٢</p>
<!-- /wp:paragraph -->"
`;

exports[`RTL should split 1`] = `
"<!-- wp:paragraph -->
<p>٠</p>
Expand Down
78 changes: 0 additions & 78 deletions packages/e2e-tests/specs/__snapshots__/writing-flow.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,6 @@ exports[`Writing Flow should create valid paragraph blocks when rapidly pressing
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should insert line break at end 1`] = `
"<!-- wp:paragraph -->
<p>a<br></p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should insert line break at end and continue writing 1`] = `
"<!-- wp:paragraph -->
<p>a<br>b</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should insert line break at start 1`] = `
"<!-- wp:paragraph -->
<p><br>a</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should insert line break in empty container 1`] = `
"<!-- wp:paragraph -->
<p><br></p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should insert line break mid text 1`] = `
"<!-- wp:paragraph -->
<p>a<br>b</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should merge forwards 1`] = `
"<!-- wp:paragraph -->
<p>123</p>
Expand All @@ -120,18 +90,6 @@ exports[`Writing Flow should navigate around inline boundaries 1`] = `
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should navigate around nested inline boundaries 1`] = `
"<!-- wp:paragraph -->
<p><strong><em>1</em> <em>2</em></strong></p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should navigate around nested inline boundaries 2`] = `
"<!-- wp:paragraph -->
<p>a<strong>b<em>c1d</em>e f<em>g2h</em>i</strong>j</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should navigate contenteditable with padding 1`] = `
"<!-- wp:paragraph -->
<p>1</p>
Expand Down Expand Up @@ -186,42 +144,6 @@ exports[`Writing Flow should not create extra line breaks in multiline value 1`]
<!-- /wp:quote -->"
`;

exports[`Writing Flow should not delete surrounding space when deleting a selected word 1`] = `
"<!-- wp:paragraph -->
<p>alpha gamma</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should not delete surrounding space when deleting a selected word 2`] = `
"<!-- wp:paragraph -->
<p>alpha beta gamma</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should not delete surrounding space when deleting a word with Alt+Backspace 1`] = `
"<!-- wp:paragraph -->
<p>alpha gamma</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should not delete surrounding space when deleting a word with Alt+Backspace 2`] = `
"<!-- wp:paragraph -->
<p>alpha beta gamma</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should not delete surrounding space when deleting a word with Backspace 1`] = `
"<!-- wp:paragraph -->
<p>1 3</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should not delete surrounding space when deleting a word with Backspace 2`] = `
"<!-- wp:paragraph -->
<p>1 2 3</p>
<!-- /wp:paragraph -->"
`;

exports[`Writing Flow should not prematurely multi-select 1`] = `
"<!-- wp:paragraph -->
<p>1</p>
Expand Down
Loading