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
Lighthouse performance downgrade since 7.6.0 #17327
Comments
Are you using this plugin? https://www.npmjs.com/package/cypress-lighthouse I've never used it before and it seems to error whenever I try to run it. And specifies requiring an older dependency of Cypress. |
Hi @jennifer-shehane no I'm using https://www.npmjs.com/package/lighthouse v8.0.0. It adds the cy.lighthouse() command. |
To add some more information We've setup a custom lighthouse plugin which is using lighthouse-ci. The way this interacts with cypress is by using the --remote-debugging-port and pointing the lighthouse test to the Cypress browser. This was working for us as expected. Until we tried to upgrade to v7.6.0 where we see some changes in how the page with intercept mocking is effected. The page renders and then the mocks are applied. Here are two different versions showing how the same page is loaded V7 You can see in V7 that the No users is shown briefly before the mock finishes and then re-renders, causing the performance degradation. Our assumption is that something has impacted how our mocking is done. This is our mocking being set before the test
This is the mock being setup
Anything which might help us would be greatly appreciated. |
Hi @jennifer-shehane Just wanted to check if this enough detail? Or any ideas why the mocking would be applied late in the render process? |
Hi @metalix2, i'm experiencing lower performance using Lighthouse inside Cypress, i'm using this package https://www.npmjs.com/package/cypress-audit. Unfortunately i don't have previous results to campare, but i tried in multiple machines and enviroments, when i run Lighthouse in Chrome everything it's ok but when i run Lighthouse in Cypress the performance is worse. I tried with this repo https://github.com/dapinto8/cypress-test, it's just a next default app and has worse performance when runniung Lighthouse in Cypress. Do you think this could be related with this issue? |
Hi @jennifer-shehane, I tried downgrading to 7.5.0 and Lighthouse performance result was the same as running Lighthouse with chrome (outside Cypress). I'm using a different package than @Sybsw, so it seems there's something that interfiers with Lighthouse since 7.6.0 You could try using this repository and changing the Cypress version. There is an spec with a command that runs Lighthouse. |
Hey @dapinto8 , |
I spent some more time on this again. Thought I'd share my learnings. Assumption:Cypress browser launcher is what is hindering lighthouse tests. You can run lighthouse directly against the chrome browser that cypress will launch to run the tests (same debug-port defined in cypress) and the tests work as expected. CYPRESS_REMOTE_DEBUGGING_PORT=33333 cypress open If taking this approach and you run multiple lighthouse tests you should run the browser in incognito mode as it appears cypress browser caches the assets? e.g. first score is 85 then other scores in the high 90’s. You can specify incognito like so. on('before:browser:launch', (browser, launchOptions) => {
launchOptions.args.push('--incognito');
} You also are not able to mock or stub any network responses this way as the cypress runner controls the browsers network capabilities which we are bypassing. I believe this is what is responsible for the performance degradation. Lighthouse test via remote_debugging browser and the other using cypress-browserReviewing the code changes between Version 7.5.0 and 7.6.0 Other Alternatives for mocking in lighthouse tests (Spoiler they don't work) Puppeteer can launch browsers and manage network interceptions. See example below. const browser = await puppeteer.launch({
args: ['--disable-web-security'],
ignoreHTTPSErrors: true,
executablePath: '/Applications/Chromium.app/Contents/MacOS/Chromium',
headless: false,
});
browser.on('targetchanged', async (target) => {
const page = await target.page();
await page.setRequestInterception(true);
page.on('request', (request) => {
if (request.url().startsWith('https://reqres.in/api/users')) {
request.respond({
status: 200,
contentType: 'application/json',
body: JSON.stringify(mockResponseObject),
});
} else request.continue();
});
}); This would open a new browser and then on targetChanged event it would watch for requests and intercept the external request and stub it with the local fixture. Though sadly this does not work due to lighthouse taking priority of the window/page. It needs to be intercepted at a browser level as Cypress does. Outcomes
@ Cypress if there is anything else you need please don't hesitate to reach out. |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
Current behavior
Cypress 7.6.0 and 7.7.0 have severely reduced performance when using cy.lighthouse(),
demonstrated here between 7.5.0 and 7.6.0:
✘ categories.performance failure for minScore assertion
all values 7.5.0: 0.97, 0.98, 0.98, 0.98, 0.97
all values 7.6.0: 0.82, 0.83, 0.72, 0.83, 0.83
all values 7.5.0: 0.88, 0.94, 0.94, 0.94, 0.88
all values 7.6.0: 0.49, 0.51, 0.07, 0.5, 0.49
✅ cumulative-layout-shift passing for minScore assertion
all values 7.5.0: 1, 1, 1, 1, 1
all values 7.6.0: 1, 1, 1, 1, 1
all values 7.5.0: 0.98, 0.98, 0.98, 0.98, 0.98
all values 7.6.0: 0.63, 0.65, 0.66, 0.64, 0.65
all values 7.5.0: 1, 1, 1, 1, 1
all values 7.6.0: 0.98, 0.98, 0.98, 0.98, 0.98
all values 7.5.0: 1, 1, 1, 1, 1
all values 7.6.0: 0.91, 0.92, 0.9, 0.92, 0.92
✅ total-blocking-time passing for minScore assertion
all values 7.5.0: 1, 1, 1, 1, 1
all values 7.6.0: 1, 1, 1, 1, 1
Desired behavior
lighthouse tests should perform at the same speed they did before (7.5.0)
Test code to reproduce
Cypress Version
7.7.0
Other
No response
The text was updated successfully, but these errors were encountered: