-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add E2E test to test checkout performance #4344
Merged
Merged
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
dac8544
Add a new performance test suite inside e2e folder
harriswong 51936c0
Use page.evaulate() via puppeteer to output performance metrics
harriswong 60767d1
Run the test 3 times and then calculate average.
harriswong d474d08
Merge branch 'develop' into add/1021-performance-measure
harriswong 9a85b29
Add performance test when UPE is enabled
harriswong 3198b96
Merge branch 'develop' into add/1021-performance-measure
harriswong d9b113c
Add performance test for WooPay without UPE
harriswong 338ce18
Save performance metrics to a local file
harriswong 7bc32db
Move logic out from the test spec
harriswong 746274d
Merge branch 'develop' into add/1021-performance-measure
harriswong 56cda30
Update woopay selector name from the dev tool
harriswong 6d2c2ae
Add changelog
harriswong e8ae1ee
Merge branch 'develop' into add/1021-performance-measure
harriswong a326f98
Make performance its own npm command
harriswong a79bc45
Merge branch 'develop' into add/1021-performance-measure
harriswong 51a10df
Update the selector used for enable/disable woopay
harriswong 332c72f
Update element selector
harriswong 6357f5a
Fix typo on "without"
harriswong a6474f0
Merge branch 'develop' into add/1021-performance-measure
harriswong 4e5e2d0
Revert "Make performance its own npm command"
harriswong b4ca77c
Add a local env variable allowing us to skip performance tests
harriswong ac4b2ad
Merge branch 'develop' into add/1021-performance-measure
harriswong f71615a
Merge branch 'develop' into add/1021-performance-measure
harriswong 5ef16e4
Revert "Add a local env variable allowing us to skip performance tests"
harriswong 6240c57
Revert "Revert "Make performance its own npm command""
harriswong 504274b
Merge branch 'develop' into add/1021-performance-measure
harriswong e93354d
Merge branch 'develop' into add/1021-performance-measure
harriswong 4dbd8ed
Ignore performance tests via .gitignore
harriswong 88e0e9a
Merge branch 'develop' into add/1021-performance-measure
harriswong 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
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,47 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import config from 'config'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { setupProductCheckout } from '../../utils/payments'; | ||
import { shopperWCP } from '../../utils'; | ||
import { getLoadingDurations } from '../../utils/performance'; | ||
|
||
describe( 'Checkout page performance', () => { | ||
beforeEach( async () => { | ||
await setupProductCheckout( | ||
config.get( 'addresses.customer.billing' ) | ||
); | ||
} ); | ||
|
||
afterAll( async () => { | ||
// Clear the cart at the end so it's ready for another test | ||
await shopperWCP.emptyCart(); | ||
} ); | ||
|
||
it( 'measures on page load', async () => { | ||
await page.waitForSelector( '#payment_method_woocommerce_payments' ); | ||
const { | ||
serverResponse, | ||
firstPaint, | ||
domContentLoaded, | ||
loaded, | ||
firstContentfulPaint, | ||
firstBlock, | ||
} = await getLoadingDurations(); | ||
|
||
await expect( page ).toMatch( 'Checkout' ); | ||
console.log( | ||
'result', | ||
serverResponse, | ||
firstPaint, | ||
domContentLoaded, | ||
loaded, | ||
firstContentfulPaint, | ||
firstBlock | ||
); | ||
} ); | ||
} ); |
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,37 @@ | ||
export async function getLoadingDurations() { | ||
return await page.evaluate( () => { | ||
const { | ||
requestStart, | ||
responseStart, | ||
responseEnd, | ||
domContentLoadedEventEnd, | ||
loadEventEnd, | ||
} = performance.getEntriesByType( 'navigation' )[ 0 ]; | ||
const paintTimings = performance.getEntriesByType( 'paint' ); | ||
|
||
let firstPaintTimings, firstContentfulPaintTimings; | ||
|
||
paintTimings.forEach( ( item ) => { | ||
if ( 'first-paint' === item.name ) { | ||
firstPaintTimings = item; | ||
} | ||
if ( 'first-contentful-paint' === item.name ) { | ||
firstContentfulPaintTimings = item; | ||
} | ||
} ); | ||
|
||
return { | ||
// Server side metric. | ||
serverResponse: responseStart - requestStart, | ||
// For client side metrics, consider the end of the response (the | ||
// browser receives the HTML) as the start time (0). | ||
firstPaint: firstPaintTimings.startTime - responseEnd, | ||
domContentLoaded: domContentLoadedEventEnd - responseEnd, | ||
loaded: loadEventEnd - responseEnd, | ||
firstContentfulPaint: | ||
firstContentfulPaintTimings.startTime - responseEnd, | ||
// This is evaluated right after Puppeteer found the block selector. | ||
firstBlock: performance.now() - responseEnd, | ||
}; | ||
} ); | ||
} |
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.
Similar to the function from woocommerce-blocks https://github.com/woocommerce/woocommerce-blocks/blob/trunk/tests/utils/performance.ts. The differences are that I can't destruct the
performance.getEntriesByType(..)
assignment or use array prototype.find. I get the following errors:ReferenceError: _slicedToArray2
ReferenceError: _find
It could be a puppeteer problem since these are used within
page.evaulate()
. Our puppeteer version is 2 and it relies on puppeteer-utils. Blocks uses jest-environment-puppeteer where its puppeteer is at 14. It doesn't seem to have these issues. I think it would be good to upgrade it to the newer puppeteer version.In any case, I worked around the
ReferenceError
and this function works in this branch.