Skip to content
Open
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
47 changes: 47 additions & 0 deletions tests/cypress/integration/performance/test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// <reference types="Cypress" />

describe('WordPress', () => {

before(() => {
cy.login(Cypress.env('WP_USERNAME'), Cypress.env('WP_PASSWORD'));
});

it('measures page load', () => {

cy.fixture('performance')
.then(
(entries) => {
entries
.forEach(

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Consider using cy.wrap(entries).each(...) instead of forEach. Cypress recommends each for command sequencing; forEach can make command ordering and failures harder to reason about when iterating.

({url, description, duration: loadTimeInMilliseconds }) => {

cy.visit(
url,
{
onBeforeLoad: (win) => {
win.performance.mark('start-loading');
},
onLoad: (win) => {
win.performance.mark('end-loading');
}
}
)
.its('performance')
.then((performance) => {
performance.measure('pageLoad', 'start-loading', 'end-loading');
const measure = performance.getEntriesByName('pageLoad')[0];

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Since this runs multiple cy.visit calls, the performance entries will accumulate. Either clear marks/measures before each visit (performance.clearMarks()/clearMeasures()), use unique mark names per URL, or grab the last entry from getEntriesByName instead of [0] to avoid stale measurements.

const duration = measure.duration;
assert.isAtMost(duration, loadTimeInMilliseconds);

cy.log(
`[PERFORMANCE] Page load duration for ${ description }: ${ duration / 1000 } seconds`
);
});
});

}
);
}
);

});