-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Performance: add e2e tests for load and typing time #14506
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
caed861
Add reporter
ellatrix 037e608
Clean up
ellatrix b6840cd
Add neuralink
ellatrix 4b682f5
Add a CLI command to run the performance tests
youknowriad a50569a
Update packages/e2e-tests/specs/performance.test.js
aduth 453a551
Testing: Use substitute randomly-generated performance fixture
aduth caf6519
Fix performance jest config
youknowriad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { readFileSync, existsSync } = require( 'fs' ); | ||
|
||
function average( array ) { | ||
return array.reduce( ( a, b ) => a + b ) / array.length; | ||
} | ||
|
||
class PerformanceReporter { | ||
onRunComplete() { | ||
const path = __dirname + '/../specs/results.json'; | ||
|
||
if ( ! existsSync( path ) ) { | ||
return; | ||
} | ||
|
||
const results = readFileSync( path, 'utf8' ); | ||
const { load, domcontentloaded, type } = JSON.parse( results ); | ||
|
||
// eslint-disable-next-line no-console | ||
console.log( ` | ||
Average time to load: ${ average( load ) }ms | ||
Average time to DOM content load: ${ average( domcontentloaded ) }ms | ||
Average time to type character: ${ average( type ) }ms | ||
Slowest time to type character: ${ Math.max( ...type ) }ms | ||
Fastest time to type character: ${ Math.min( ...type ) }ms | ||
` ); | ||
} | ||
} | ||
|
||
module.exports = PerformanceReporter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = { | ||
...require( '@wordpress/scripts/config/jest-e2e.config' ), | ||
testMatch: [ | ||
'**/performance.test.js', | ||
], | ||
setupFiles: [ | ||
'<rootDir>/config/gutenberg-phase.js', | ||
], | ||
setupFilesAfterEnv: [ | ||
'<rootDir>/config/setup-test-framework.js', | ||
'@wordpress/jest-console', | ||
'@wordpress/jest-puppeteer-axe', | ||
'expect-puppeteer', | ||
], | ||
transformIgnorePatterns: [ | ||
'node_modules', | ||
'scripts/config/puppeteer.config.js', | ||
], | ||
reporters: [ | ||
'default', | ||
'<rootDir>/config/performance-reporter.js', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { join } from 'path'; | ||
import { existsSync, readFileSync, writeFileSync } from 'fs'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
createNewPost, | ||
saveDraft, | ||
insertBlock, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
function readFile( filePath ) { | ||
return existsSync( filePath ) ? readFileSync( filePath, 'utf8' ).trim() : ''; | ||
} | ||
|
||
describe( 'Performance', () => { | ||
it( '1000 paragraphs', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want it to be executed every time we run e2e tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, let's exclude. |
||
const html = readFile( join( __dirname, '../assets/large-post.html' ) ); | ||
|
||
await createNewPost(); | ||
await page.evaluate( ( _html ) => { | ||
const { parse } = window.wp.blocks; | ||
const { dispatch } = window.wp.data; | ||
const blocks = parse( _html ); | ||
|
||
blocks.forEach( ( block ) => { | ||
if ( block.name === 'core/image' ) { | ||
delete block.attributes.id; | ||
delete block.attributes.url; | ||
} | ||
} ); | ||
|
||
dispatch( 'core/editor' ).resetBlocks( blocks ); | ||
}, html ); | ||
await saveDraft(); | ||
|
||
const results = { | ||
load: [], | ||
domcontentloaded: [], | ||
type: [], | ||
}; | ||
|
||
let i = 1; | ||
let startTime; | ||
|
||
await page.on( 'load', () => results.load.push( new Date() - startTime ) ); | ||
await page.on( 'domcontentloaded', () => results.domcontentloaded.push( new Date() - startTime ) ); | ||
|
||
while ( i-- ) { | ||
startTime = new Date(); | ||
await page.reload( { waitUntil: [ 'domcontentloaded', 'load' ] } ); | ||
} | ||
|
||
await insertBlock( 'Paragraph' ); | ||
|
||
i = 200; | ||
|
||
while ( i-- ) { | ||
startTime = new Date(); | ||
await page.keyboard.type( 'x' ); | ||
results.type.push( new Date() - startTime ); | ||
} | ||
|
||
writeFileSync( __dirname + '/results.json', JSON.stringify( results, null, 2 ) ); | ||
|
||
expect( true ).toBe( true ); | ||
} ); | ||
} ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put it into its own folder to avoid this ignore rule?
e2e-tests/benchmark/index.js
- should do the trick