* remove experimentalSkipDomainInjection, add and deprecate injectDocumentDomain * remove experimentalSkipDomainInjection, add injectDocumentDomain * begin rethreading domain injection * complete document domain transition * move some cookie specs to separate test run * origin and privileged commands with default docdom inject * fix privileged channel when injecting document domain * rm unnecessary .getOrigin abstraction in cors lib * move remote-states in prep for refactor Replace Conditional with Polymorphism * refactor remote states to strategy pattern * cookie commands work as expected w cross origin bridge on different origins * some origin tests updated * run tests with document domain enabled * run tests actually * use correct config, swap conditional * check-ts * inject documetn domain for webkit tests * do not exec injectDocumetnDomain in parallel * fix ServerBase construction in tests to include cfg now * pass cfg to ServerBase * improved integration tests * remove document domain checks for all server integration specs - will add injectDocumentDomain cases * tests for injecting document domain when configured to * square away server integration tests * ensure cookies are set correctly, potentially * errors pkg snapshots * fix config tests * fixing config tests * somewhat improves tests for cors policies in packages/network * fix ts err in server-base * enable injectDocumentDomain for cy in cy tests * fix Policy type ref * refactor cypress-schematic ct spec to be less prone to timeouts * run vite-dev-server tests with injectDocumentDomain * rm document domain assertion from page_loading system test * add system tests that test with injectDocumentDomain and others that test with cy.origin * fix results_spec snapshot * update experimentalSkipDomainInjection system test * different behavior for certain net_stubbing tests based on injectDocumentDomain or not * fix ts * extract origin key logic from remote states, for now * move server-base and response-middleware over to new pattern * WIP - reentry * fix build, remove console.log * check-ts * fix spec frame injection * remove injection for localhost * mostly fix vite-dev-server app integration tests * fix codeframe in certain cases in chrome * drop internal stack frames from stacks intended for determining code frame data * some improvements to vite ct error codeframes * fix proxy unit tests to use document domain injection util class * rm .only * fix all vite ct error specs * rm console.log * slight refactor to util class to make easier to test * fix refactor - missing rename in files.js * several tests do not set testingtype in config, so just check against component instead of checking for e2e * revert changes to getInvocationDetails to see if that breaks tests * re-enable stack stripping in invocation details for chrome * new snapshots with more accurate invocation details * test for same-site cross-origin cookie behavior * ignore window.top ts errors * revert forcing injectDocumentDomain in vite-dev-server cy config * fix normalized whitespace for firefox "loading_failed" error * always trim trailing wsp from stack before appending additional content * force normalization of whitespace to three \n when adding additional stack details * normalize wsp between stack and additional stack to "\n \n" in firefox * remove stack_utils attempt at normalizing wsp * various cleanup: remove commented console logs, add more detailed comments * add on links to error messages * remove experimentalSkipDomainInjection from exported type defs * Update system-tests/test/experimental_skip_domain_injection_spec.ts Co-authored-by: Bill Glesias <bglesias@gmail.com> * Update packages/driver/cypress/e2e/e2e/origin/cookie_misc.cy.ts Co-authored-by: Bill Glesias <bglesias@gmail.com> * no need to coerce a boolean value to a booleanc * export base config from primary cypress config in driver for use in inject-document-domain test subset * lift experimentalSkipDomainInjection breaking option to root * rollback config/options changes * rm invalid comment * use hostname instead of origin to create cookie from automation cookie * clarify stack regex in results_spec * lint * take a stab at the changelog entries for this * Update cli/CHANGELOG.md Co-authored-by: Ryan Manuel <ryanm@cypress.io> * Update cli/CHANGELOG.md Co-authored-by: Ryan Manuel <ryanm@cypress.io> * reenable locally-failing test * changelog * snapshot updatesfor experimental skip domain injection err msg * remove packageManager declaration in package.json --------- Co-authored-by: Bill Glesias <bglesias@gmail.com> Co-authored-by: Jennifer Shehane <jennifer@cypress.io> Co-authored-by: Ryan Manuel <ryanm@cypress.io>
CLI
The CLI is used to build the cypress npm module to be run within a terminal.
The CLI has the following responsibilities:
- Allow users to print CLI commands
- Allow users to install the Cypress executable
- Allow users to print their current Cypress version
- Allow users to run Cypress tests from the terminal
- Allow users to open Cypress in the interactive Test Runner.
- Allow users to verify that Cypress is installed correctly and executable
- Allow users to manages the Cypress binary cache
- Allow users to pass in options that change way tests are ran or recorded (browsers used, specfiles ran, grouping, parallelization)
Building
See scripts/build.js. Note that the built npm package will include NPM_README.md as its public README file.
Testing
Automated
From the repo's root, you can run unit tests with:
yarn test-unit --scope cypress
yarn test-watch --scope cypress
yarn test-debug --scope cypress
Updating snapshots
Prepend SNAPSHOT_UPDATE=1 to any test command. See snap-shot-it instructions for more info.
SNAPSHOT_UPDATE=1 yarn test-unit --scope cypress
Type Linting
When testing with dtslint, you may need to remove existing typescript installations before running the type linter (for instance, on OS X, you might rm -rf ~/.dts/typescript-installs) in order to reproduce issues with new versions of typescript (i.e., @next).
Manual
To build and test an npm package, execute the following from the repo's root directory:
yarn
yarn build
This creates the cli/build folder.
cd cli/build
yarn pack
This creates an archive, usually named cypress-v<version>.tgz. You can install this archive from other projects, but because there is no corresponding binary yet (probably), skip binary download. For example from inside cypress-example-kitchensink folder
yarn add ~/{your-dirs}/cypress/cli/build/cypress-v13.13.2.tgz --ignore-scripts
Sub-package API
How do deep imports from cypress/* get resolved?
The cypress npm package comes pre-assembled with mounting libraries for major front-end frameworks. These mounting libraries are the first examples of Cypress providing re-exported sub-packages. These sub-packages follow the same naming convention they do when they're published on npm, but without a leading @ sign. For example:
An example of a sub-package: @cypress/vue, @cypress/react, @cypress/mount-utils
Let's discuss the Vue mounting library that Cypress ships.
If you'd installed the @cypress/vue package from NPM, you could write the following code.
This would be necessary when trying to use a version of Vue, React, or other library that may be newer or older than the current version of cypress itself.
import { mount } from '@cypress/vue'
Now, with the sub-package API, you're able to import the latest APIs directly from Cypress without needing to install a separate dependency.
import { mount } from 'cypress/vue'
The only difference is the import name, and if you still need to use a specific version of one of our external sub-packages, you may install it and import it directly.
Adding a new sub-package
There are a few steps when adding a new sub-package.
- Make sure the sub-package's rollup build is self-contained or that any dependencies are also declared in the CLI's
package.json. - Now, in the
postbuildscript for the sub-package you'd like to embed, invokenode ./scripts/sync-exported-npm-with-cli.js(relative to the sub-package, seenpm/vuefor an example). - Add the sub-package's name to the following locations:
cli/.gitignorecli/scripts/post-build.js.eslintignore(under cli/sub-package)
- DO NOT manually update the package.json file. Running
yarn buildwill automate this process. - Commit the changed files.
Here is an example Pull Request
Module API
The module API can be tested locally using something like:
/* @ts-ignore */
import cypress from '../../cli/lib/cypress'
const run = cypress.run as (options?: Partial<CypressCommandLine.CypressRunOptions>) => Promise<CypressCommandLine.CypressRunResult | CypressCommandLine.CypressFailedRunResult>
run({
spec: './cypress/component/advanced/framer-motion/Motion.spec.tsx',
testingType: 'component',
/* @ts-ignore */
dev: true,
}).then(results => {
console.log(results)
})
Note that the dev flag is required for local testing, as otherwise the command will fail with a binary error.