Closed MuckT closed 3 years ago
Submitted a PR that I believe solves this issue #59
Hi @MuckT,
I'm facing an issue in spite of the same configuration.
I have the following error message: cy.lighthouse is not a function
while running my tests with ng e2e --watch
My IDE spots an issue on cy.lighthouse()
, saying TS2339: Property 'lighthouse' does not exist on type 'cy & EventEmitter'
Am I missing some configuration?
The only difference is that I'm using https://github.com/TheBrainFamily/cypress-cucumber-preprocessor
@RoRoche Can you try and use (cy as any).lighthouse()
as recommended here: #36
Alternatively you could try my branch #59 with this in your package.json
"cypress-audit": "MuckT/cypress-audit#master",
Hello @MuckT
I have similar configuration:
export const performanceReport = () => { cy.lighthouse( { performance: 5, accessibility: 95, }, { formFactor: 'desktop', screenEmulation: { mobile: false, width: 1920, height: 1080, deviceScaleFactor: 1, disabled: false, }, }); }
and this package.json
"cypress": "^6.3.0", "cypress-audit": "MuckT/cypress-audit#master", "cypress-cucumber-preprocessor": "^4.0.0", "cypress-react-unit-test": "^4.11.2", "cypress-screenplay": "^0.1.0", "eslint-plugin-cypress": "^2.10.3", "lighthouse": "^7.0.1",
And I have this issue:
I think it is related.
@FannyBarco do you have the commands from step four added? I've also noticed that sometimes other plugins can have issues running along side cypress-audit; can you try with just the cypress-audit plugin in Chrome?
I've managed to make nx work using the "index.d.ts" at the root of cypress-audit 🤔 . In this specific PR: https://github.com/mfrachet/cypress-audit/pull/60 .
Here are the files that I've modified in order to make it work:
Then I had to restart my visual studio code typescript plugin since it crashes all the time. And finally:
Also, I've added this folder example https://github.com/mfrachet/cypress-audit/tree/master/examples/nx and make the NX build part of the CI. It means that we'll know in the future if something breaks for this particular tool 😊
I'll let this one open for some times to get your feedbacks.
Thanks for your help folks, for your help and feedbacks 🙏🏻
Hello @MuckT
I have similar configuration:
export const performanceReport = () => { cy.lighthouse( { performance: 5, accessibility: 95, }, { formFactor: 'desktop', screenEmulation: { mobile: false, width: 1920, height: 1080, deviceScaleFactor: 1, disabled: false, }, }); }
and this package.json
"cypress": "^6.3.0", "cypress-audit": "MuckT/cypress-audit#master", "cypress-cucumber-preprocessor": "^4.0.0", "cypress-react-unit-test": "^4.11.2", "cypress-screenplay": "^0.1.0", "eslint-plugin-cypress": "^2.10.3", "lighthouse": "^7.0.1",
And I have this issue:
I think it is related.
I have the same issue, I did all the steps from readme, any ideas? I have plain JS.
probably not the same issue then. would you mind creating another one with steps to repro please ? 🙏🏻
My case if fixed now by including, at the top of the test, the cypress-audit commands such as: https://github.com/mfrachet/cypress-audit/blob/master/examples/nx/apps/nx-e2e/src/integration/app.spec.ts#L1
😃
Using "cypress-audit": "MuckT/cypress-audit#master"
is also OK! 👍
Thanks a lot for your help.
Good to hear. I'm closing this for now. Feel free to reopen or comment if something is not okay 👍🏻
We solved this issue by explicitly setting the browser to chrome
project.json
{
"targets": {
"e2e": {
"executor": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "apps/web-e2e/cypress.json",
"devServerTarget": "web:serve",
"browser": "chrome"
}
}
}
}
or on the cli
nx e2e --browser=chrome
@mfrachet thought this might be useful to those hoping to use cypress-audit with an nx repo. Also I am having some issues with headless mode.
Steps
module.exports = (on, config) => { on("before:browser:launch", (browser = {}, launchOptions) => { prepareAudit(launchOptions); });
on("task", { lighthouse: lighthouse(), // calling the function is important pa11y: pa11y(), // calling the function is important }); on('file:preprocessor', preprocessTypescript(config)); };
// Import commands.js using ES2015 syntax: import './commands'; import 'cypress-audit/commands';
declare namespace Cypress { interface Chainable {
login(email: string, password: string): void;
lighthouse(...arg: any): any;
pa11y(...arg: any): any;
}
}
describe('todos', () => { beforeEach(() => cy.visit('/'));
it('should use cypress audit', () => { cy.lighthouse( { performance: 75, accessibility: 95, 'best-practices': 93, seo: 90 }, { formFactor: 'desktop', screenEmulation: { mobile: false, width: 1920, height: 1080, deviceScaleFactor: 1, disabled: false, }, }); });
it('should use pa11y audit', () => { cy.pa11y(); }) });
ng e2e --watch
ng e2e