guides/app-lifecycle.md
This documents the lifecycle of the application, specifically related to managing the current project, and the various states & inputs that can feed into state changes, and how they are managed
cypress open | run --flagscli/lib/cli.js for normalizationserver/lib/modes/index.tsDataContext class receives the testing mode (run | open), and the modeOptions (CLI Flags)ctx.initialize, which based on the mode returns a promise for series of steps neededDataContext should act as the global source of truth for all state in the application. It should be passed along where possible. In the server package, we can import/use getCtx so we don't need to pass it down the chain.coreData
1. TODO: rename to appState?open mode, if the --global flag is passed, we start in "global" mode, which allows us to select multiple projects--project flag, we launch into project modecypress.config.js, or wherever the config is specified via the --configFile CLI flag:globalBrowsersconfigFile in a child process & reply back with the config, and the require.cache files in the child processcurrentProject in the root statecypress.env.json and validate (if it exists)it('should do the thing', { retries: { run: 3 } }port from spawned serversetupNodeEvents (as these get the options from the CLI)cypress.env.jsoncypress.config.{js|ts}Config options are deeply merged:
# CLI:
cypress run --env FOO=bar
# cypress.config.js
env: {
FOO: 'test'
},
e2e: {
setupNodeEvents (on, config) {
return require('@cypress/code-coverage')(on, config)
},
env: {
e2eRunner: true
}
}
# Would Result in
{
env: { FOO: 'bar', e2eRunner: true }
}
--config baseUrl=http://example.com, --env are gathered for merging later
cypress.config.{js|ts}, and read the cypress.env.json - this will be persisted on the state object, so we can compare the diff as we detect/watch changes to these files
setupNodeEventstestingType, we execute the setupNodeEvents, passing an "allowed" list of options as the second argument to the function. At this point, we have merged in any CLI options, env vars,
resolved property which includes the origin of where the config property was resolved from