Cypress tests
Cypress is MIT-licensed (repo). Ground each step in the docs page it cites; Cypress changes between releases.
- Check it is there. Look for
cypress.config.ts(or.js) and acypressentry inpackage.json. If it is missing, show the userbossku tools install cypressand run it only after a clear yes. Read the installed version frompackage.jsonand the lockfile;npx cypress versionprints the package and binary versions. Check the latest withnpm view cypress version, and read its changelog before any upgrade. - Learn the app first. Read the components or open the page for the real text, roles and test attributes. A selector must match what the app renders.
- Select by test attribute.
cy.get('[data-cy="submit"]')is the docs' "always best" choice because the attribute does not change with CSS or JS behaviour. Use the project's own attribute if it has one (best practices). - No fixed waits. Wait on an aliased request (
cy.wait('@getOrders')) or on an assertion that retries (best practices, cy.intercept). - Stub the network with
cy.interceptwhen the test should not depend on a live API (cy.intercept). Stubs return the types and nulls production sends (money as the string production uses). At least one spec runs against a staging API with production-shaped data. - Log in with code.
cy.sessioncaches cookies, localStorage and sessionStorage. Ifvalidatefails on a restored session,setupruns again; if it fails right aftersetup, the test fails. Sessions are not kept across spec files by default (cy.session). - Keep tests independent. Each test sets up its own state and does not rely on an earlier test (best practices).
- Keep secrets out of specs. Read sensitive values with
cy.env()(best practices). Do not pass--recordor setCYPRESS_RECORD_KEYunless the user asks: it sends results to Cypress Cloud and needs a project set up for recording (command line). - Run the spec you changed.
npx cypress run --spec "cypress/e2e/<file>.cy.ts". Add--componentfor component specs and--browser chrome(or another installed browser), because Electron is deprecated as a test browser (command line, install). Leavenpx cypress opento the user: it launches the Cypress App so a person can choose tests (install). Run the changed spec once. Retries are off by default. Ifretriesincypress.configis above 0, a spec that passes only on a retry is flaky: report it as flaky (test retries). - Say what you ran. List the commands, what passed, what failed, and what you could not run. For a visual change, attach the
cy.screenshot()images at each size the repo asks for, checked against the change.
Windows notes
CYPRESS_CACHE_FOLDERmust exist every time Cypress launches (advanced installation).- In PowerShell, quote comma-separated values:
--env "host=api.dev.local,port=4222"(command line). - Cypress sends crash reports (exception data) to
api.cypress.ioby default.CYPRESS_CRASH_REPORTS=0in the environment turns that off; set it before installing, and tell the user before an install if they care about privacy (advanced installation). - The npm install downloads the Cypress binary by default.
CYPRESS_INSTALL_BINARY=0skips that download, andnpx cypress installfetches it later (advanced installation).
References
../../references/checklists/engineering-quality-bar.md: the shared bar.