This cypress
folder is used for E2E testing.
Read more about the folder structure
_examples
: Tests created by Cypress during initial install (initially located inintegration/examples
), they've been moved to this folder so that they don't run but can still be used as learning resourceintegration
: The folder where tests must be writtenscreenshot
/videos
: Will contain assets when tests fail, useful during development. When tests are executed by Github Actions, you'll find those assets under the "Artifacts" section. (e.g: https://github.com/UnlyEd/next-right-now/runs/862302266)fixtures
: Fixtures are used as external pieces of static data that can be used by your tests. (We've kept the fixtures installed during the Cypress initial install)
The files cypress/config-*
are used for different purposes.
config-customer-ci-cd.json
: This file is a mock config file used by CI/CD GitHub Actions by the workflowsdeploy-vercel-production.yml
anddeploy-vercel-staging.yml
. ThebaseUrl
is a fake value (required by Cypress, but not used) which is replaced at runtime by the realbaseUrl
which is a dynamic Vercel deployment url.config-development.json
: This file is only used when runningyarn e2e:run
andyarn e2e:open
locally. It usesbaseUrl=http://localhost:8888
which is where our local server is running. It's only meant for local testingconfig-$CUSTOMER_REF.json
: This file is only used when runningyarn deploy:$CUSTOMER_REF
locally. It is not used by CI/CD workflows.
Sanity Checks are executed first. Then, tests are executed by their folder/file alphabetical order by default.
- [MUST WATCH!] Best Practices by the Author (2018) - 27mn
- Organize tests by type of devices (mobile/desktop)
- Run tests on multiple subdomains
- Detect if Cypress is running
- Can my tests interact with Redux / Vuex data store? (AKA "Dynamic testing")
- Check a custom property from the
window
object - Dynamic tests
- Filters and data-driven tests
- cypress-realworld-app
We see organizations starting with Cypress by placing end-to-end tests in a separate repo. This is a great practice that allows someone on the team to prototype a few tests and evaluate Cypress within minutes. As the time passes and the number of tests grows, we strongly suggest moving end-to-end tests to live right alongside your front end code.
This brings many benefits:
- engages developers in writing end-to-end tests sooner
- keeps tests and the features they test in sync
- tests can be run every time the code changes
- allows code sharing between the application code and the tests (like selectors)
Cypress releases "Real World App" (RWA) - Blog post
We use module alias path mappings, to avoid using relative paths (e.g: ../../src/common
) but absolute paths (AKA "module paths") instead (e.g: @/common
).
Although it's simpler to use, it's harder to configure because it affects several configuration files:
- The paths mapping in
tsconfig.json:compilerOptions.paths
must match those in../tsconfig.json:compilerOptions.paths
- They must also match those in
jsconfig.json
file, which is necessary for WebStorm to understand them for .js files.
If the module path mappings aren't properly set everywhere, it won't work.
You can still use relative paths.
Reference: