// Test for long taskstest('should capture long tasks on the page',async({ page })=>{// Function to capture long tasksasyncfunctioncaptureLongTasks(durationThreshold){return page.evaluate((threshold)=>{returnnewPromise((resolve)=>{const longTasks =[];const observer =newPerformanceObserver((list)=>{for(const entry of list.getEntries()){if(entry.duration > threshold){
longTasks.push(entry);}}});
observer.observe({entryTypes:['longtask']});// Assuming the long tasks will be captured within a certain time framesetTimeout(()=>{
observer.disconnect();resolve(longTasks);},5000);// Adjust the timeout as needed});}, durationThreshold);}// Capture long tasks// 50ms as the threshold for long tasksconst longTasks =awaitcaptureLongTasks(50);// Assertions with expectexpect(longTasks).toBeInstanceOf(Array);// Expect no more than 5 long tasksexpect(longTasks.length).toBeLessThanOrEqual(5);});
Does the page generate errors if external resources don't load? #
test("Tests if page will work when 3rd party resources are blocked",async({ page })=>{
page.route("**",(route)=>{const requestURL = route.request().url()if(requestURL.match(/http:\/\/localhost:8080/)){
route.continue()}else{
route.abort()}})// monitor emitted page errorsconst errors =[]
page.on("pageerror",(error)=>{
errors.push(error)})await page.goto("http://localhost:8080")
console.log(errors)expect(errors.length).toBe(0)})
The impact of service workers on performance measurement #