Skip to content

Latest commit

 

History

History
 
 

server-communication__server-timing

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Server Timing

Show server timing results from Cypress visit

Imagine the server collects its performance timings while preparing and serving the / page. The server can send these timings using Server-Timing header (see index.js), and we can inspect these numbers from the Cypress test. See cypress/e2e/spec.cy.js file.

We can intercept the / load using cy.intercept and inspect the response's headers. We have to find the server-timing header and parse it ourselves.

Print server timings

Printing to the DevTools console hides the numbers, so instead we can print them to the Command Log using cy.log

Log server timings

We can also go about server timings the other way. Instead of spying on the / resource, we can let the page load and then access the performance object collected by the browser automatically. For example, we can get all server timings already parsed by the browser by accessing them:

window.performance.getEntriesByType('navigation')[0]serverTiming

Which in Cypress test can be done

cy.window().its('performance')
  .invoke('getEntriesByType', 'navigation')
  .its('0.serverTiming')

We can then find the desired duration and assert it is below certain limit

Checking performance