cypress-audit
cypress-audit copied to clipboard
CypressError: `cy.task('lighthouse')` failed with the following error: > connect ECONNREFUSED ::1:60387
What does not work? Trying to run examples/external-url locally I am getting a connection error.
How to reproduce? Execute test in examples/external-url
Screenshots / Animated Gifs
Environment (please complete the following information):
- OS: MacOS 12.2
- Chrome version: 99
- Cypress version: 9.5.2
Any other information that may help fixing the issue? Read the comment here https://github.com/mfrachet/cypress-audit/issues/62 but could not find a solution.
Same issue for me
Have you manage to do something on this one?
What's is interesting to me is that the port displayed is not valid 🤔 Like econnrefused on :1::60387
(which is not a valid port for the browser)
Same issue for me from cypress versions 9.1.0+ Working for me for 8.7.0 version and below.
Does this still occurs?
Yes it is still occurring in cypress 9.7.0 version.
Any possibility to share an open source repo reproducing the error ?
I'm also getting this same error:
I'm using a higher version of Cypress:
"cypress": "^10.1.0",
"cypress-audit": "^1.1.0",
To get cypress-audit working with cypress 10 I followed the changes in this open PR
@MichaelRobsonSliide , the library is now @cypress-audit/lighthouse
and is in version 1.3.1. The doc website has been updated accordingly. Do you mind checking it and see if it solves your problem or not?
@MichaelRobsonSliide , the library is now
@cypress-audit/lighthouse
and is in version 1.3.1. The doc website has been updated accordingly. Do you mind checking it and see if it solves your problem or not?
Thanks that works fine, one thing it might be worth making clear or updating is this part
on("task", { lighthouse: lighthouse(), pa11y: pa11y(console.log.bind(console)), });
From https://mfrachet.github.io/cypress-audit/guides/lighthouse/installation.html#the-server-configuration this will fail until you also follow the pa11y install part of the doc to add @cypress-audit/pa11y.
The Pa11y part of the guide does not assume lighthouse is installed so none of the examples make reference to it but the lighthouse part assumes you have the pa11y dependency.
UPDATE: When I try to run cy.pa11y() I'm getting
Failed to fetch browser webSocket URL from http://localhost:59894/json/version: request to http://localhost:59894/json/version failed, reason: connect ECONNREFUSED ::1:59894
Have you tried with the instructions here https://mfrachet.github.io/cypress-audit/guides/pa11y/installation.html#the-server-configuration ? (and you're right, I forgot to add the import in the documentation 😓 )
Yes, I followed the instructions for pa11y and lighthouse, I get the same webSocket error if I try to run pa11y against my test domain or google.
This is my cypress config file
const { defineConfig } = require('cypress')
const { lighthouse, prepareAudit } = require('@cypress-audit/lighthouse')
const { pa11y } = require('@cypress-audit/pa11y')
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
require('cypress-mochawesome-reporter/plugin')(on)
on('before:browser:launch', (browser = {}, launchOptions) => {
prepareAudit(launchOptions)
})
on('task', {
lighthouse: lighthouse(),
pa11y: pa11y(),
})
},
// Global Cypress configuration settings
baseUrl: '*MYSITE*',
video: true,
chromeWebSecurity: false,
retries: {
runMode: 3,
openMode: 0,
},
// Report config
reporter: 'cypress-mochawesome-reporter',
reporterOptions: {
reportDir: 'cypress/reports',
charts: true,
embeddedScreenshots: true,
inlineAssets: true,
},
},
})
Getting the same task failure in Cypress 10.2.0. I run: `import "@cypress-audit/lighthouse/commands";
describe('CA Lighthouse Test', () => { before(() => { cy.loginAlt('ca') })
it('Compare first paint', () => {
const customThresholds = {
performance: 50,
accessibility: 50,
seo: 70,
'first-contentful-paint': 2000,
'largest-contentful-paint': 3000,
'cumulative-layout-shift': 0.1,
'total-blocking-time': 500,
};
const desktopConfig = {
formFactor: 'desktop',
screenEmulation: {
mobile: false,
disable: false,
width: Cypress.config('viewportWidth'),
height: Cypress.config('viewportHeight'),
deviceScaleRatio: 1,
}
};
cy.visit('/', {timeout: 20000}).then(() => {
//cy.lighthouse(customThresholds, desktopConfig)
cy.lighthouse()
})
})
})`
and get index.fd56be2f.js:65032 CypressError: cy.task('lighthouse')
timed out after waiting 60000ms
. I followed the instructions as well:
`const { defineConfig } = require('cypress') const { lighthouse, prepareAudit } = require("@cypress-audit/lighthouse"); const { pa11y } = require("@cypress-audit/pa11y");
module.exports = defineConfig({ retries: { runMode: 2, openMode: 0, }, e2e: { experimentalSessionAndOrigin: true, // We've imported your old cypress plugins here. // You may want to clean this up later by importing these. setupNodeEvents(on, config) { on("before:browser:launch", (browser = {}, launchOptions) => { prepareAudit(launchOptions); }); on("task", { lighthouse: lighthouse(), pa11y: pa11y(console.log.bind(console)), }); return (on, config) }, defaultCommandTimeout: 8000, execTimeout: 60000, taskTimeout: 60000, pageLoadTimeout: 60000, requestTimeout: 8000, responseTimeout: 30000, }, })`
I have the same issue @cypress-audit/lighthouse = 1.3.1 cypress version 9.7.0
The difference for me is that I can run locally (external url) the plugin, but when I launch the automated scenarios on Browser Stack, appear the error connect ECONNREFUSED ::1:60387 I was wondering if the plugin has support to run on Browser Stack. Thank you for your answer
I ran into the same thing running on Windows locally. According to this StackOverflow article, starting in Node 17,
Node.js no longer re-sorts results of IP address lookups and returns them as-is (i.e. it no longer ignores how your OS has been configured)
On my Windows laptop, localhost is resolving to it's IPV6 address of ::1. You can see that in @juanduarte1927's comment above as well. I wasn't able to figure out a way to pass the --dns-result-order option to Node when I launch Cypress but was looking at the code for @cypress-audit/pa11y. In the task.js, I changed localhost to 127.0.0.1 and my tests worked. I'm not sure if this is a practical solution or not. Would it be the same on Macs? Here's what the task.js looks like with my change:
const pa11yLib = require("pa11y");
const puppeteer = require("puppeteer");
const pa11y = (callback) => async ({ url, opts }) => {
const browser = await puppeteer.connect({
browserURL: `http://127.0.0.1:${global.cypress_audit_port}`,
});
const results = await pa11yLib(url, { browser, runners: ["axe"], ...opts });
if (callback) {
callback(results);
}
return results.issues || [];
};
module.exports = { pa11y };
Versions: Cypress: 11.0.0 │ Browser: Chrome 106 (headless) │ Node Version: v19.0.0 (C:\Program Files\nodejs\node.exe) │ @cypress-audit: 1.3.1
I was able to find a workaround that's not too bad. I set NODE_OPTIONS="--dns-result-order=ipv4first". This appears to be backwards compatible. I ran this with Node 16 (Linux) as well as Node 19 (Windows). To simplify things, I added a script in my package.json to look like this:
"cypress:open": "cross-env NODE_OPTIONS=--dns-result-order=ipv4first && cypress open",
"cypress:e2e-chrome-reports": "cross-env NODE_OPTIONS=--dns-result-order=ipv4first cypress run --headless --browser=chrome && npx mochawesome-merge 'cypress/results/*.json' > mochawesome.json && npx marge mochawesome.json"
I used the cross-env package to make it work across platforms, Mac, Windows and Linux. I'll have a buddy try it out on his Mac tomorrow with Node 19 just to make sure it works.
Thanks for the work you do to support and improve cypress-audit!
I NEED HELP!!! I've integrated lighthouse to Cypress but I'm getting cy.task('lighthouse') failed. it works when I use headless mode with this implementation
module.exports = async (on, config) => {
on('before:browser:launch', (browser = {}, launchOptions) => {
prepareAudit(launchOptions);
allureWriter(on, config);
});
on('task', {
lighthouse: lighthouse(), // calling the function is important
pa11y: pa11y(console.log.bind(console)),
});
if (config.testingType === 'component') {
config.viewportHeight = allSizes[4][0];
config.viewportWidth = allSizes[4][1];
require('@cypress/react/plugins/next')(on, config);
}
return config;
};
But I am giving tags to my test cases so it's like
const tagify = require("cypress-tags");
`module.exports = async (on, config) => {
on('file:preprocessor', **tagify(config)**, (browser = {}, launchOptions) => {
prepareAudit(launchOptions);
allureWriter(on, config);
});
on('task', {
lighthouse: lighthouse(), // calling the function is important
pa11y: pa11y(console.log.bind(console)),
});
if (config.testingType === 'component') {
config.viewportHeight = allSizes[4][0];
config.viewportWidth = allSizes[4][1];
require('@cypress/react/plugins/next')(on, config);
}
return config;
};`
So My Question is HOW CAN I IMPLEMENT TAG WITH LIGHHOUSE?
This is my cypress.config.ts folder
e2e: { setupNodeEvents(on, config) { return require('./cypress/plugins/index.js')(on, config); }, baseUrl: 'http://www.amazon.com/', specPattern: 'cypress/tests/e2e/**/*.spec.{js,jsx,ts,tsx}', },
@KadirAtug07 please create a new question thread, not relevant to the question at hand.
https://github.com/mfrachet/cypress-audit/issues/136#issuecomment-1311236777 by forcing ipv4 in nodejs instead of ipv6
Seems to be a valid fix for this one. I m closing. Feel free to reopen if needed