From 1d6f0624cfbbf1e117882d85f1b68d9a09020a9c Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Wed, 13 Nov 2024 14:39:19 -0500 Subject: [PATCH] Create test.spec.js --- .../integration/performance/test.spec.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/cypress/integration/performance/test.spec.js diff --git a/tests/cypress/integration/performance/test.spec.js b/tests/cypress/integration/performance/test.spec.js new file mode 100644 index 0000000..73413d6 --- /dev/null +++ b/tests/cypress/integration/performance/test.spec.js @@ -0,0 +1,47 @@ +// + +describe('WordPress', () => { + + before(() => { + cy.login(Cypress.env('WP_USERNAME'), Cypress.env('WP_PASSWORD')); + }); + + it('measures page load', () => { + + cy.fixture('performance') + .then( + (entries) => { + entries + .forEach( + ({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]; + const duration = measure.duration; + assert.isAtMost(duration, loadTimeInMilliseconds); + + cy.log( + `[PERFORMANCE] Page load duration for ${ description }: ${ duration / 1000 } seconds` + ); + }); + }); + + } + ); + } + ); + +});