-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Detox 20] JS: migrate to jest globalSetup, globalTeardown configuration #3354
Closed
37 of 38 tasks
Tracked by
#3348
Comments
d4vidi
changed the title
JS: migrate to and configuration (to make it easier to land Device Allocation server)
JS: migrate to jest globalSetup, globalTeardown configuration
Apr 25, 2022
Status: Requires discussion over what the best way to make progress here would be @noomorph discuss over a meeting? |
@noomorph following the last comment + today's planning: Are we cool regarding the next steps here? |
d4vidi
changed the title
JS: migrate to jest globalSetup, globalTeardown configuration
[Detox 20] JS: migrate to jest globalSetup, globalTeardown configuration
Aug 30, 2022
Just went over this again. Excellent write up, @noomorph. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Implement the new entity, Detox primary context:
.detoxrc
files);jest
) as many times as needed;Remove old hacks we applied in absence of the centralized communication between the workers:
detox_<pid>.log
) instead of a single one that combines all the messages;DETOX_REPORT_SPECS
,DETOX_START_TIMESTAMP
) to the spawned test runner to make up for the absence of a shared global state;Introduce the features that immediately make sense upon the refactor:
logger
config – since Detox will be possessing only one global instance of the logger, we can easily enough create one using the config, and all the workers will be using inter-process communication to forward the messages to that instance. That simplifies artifacts' collection and human inspection a lot.testRunner
config – after removing knowledge about workers, Detox CLI becomes truly runner-agnostic – it can act as a simple passthrough mechanism. Now there's a lot of sense to add a universaltestRunner
config which can be useful for any test runner.*.jsonl
to Chrome trace format by default and be able to visualize them nicely, since all the PIDs are in the same place.In the long run:
--cleanup
flag behavior.Scope
top
realm and the underlying ones so to:top
realm only;reportSpecs
logic from CLI – get workers count via IPC and set the default value accordinglyread properties of undefined (reading 'jest')` - think how to initialize secondary context in a guaranteed way;
process.env.DETOX_CONFIG_SNAPSHOT_PATH
to the child environments[permanent]
boolean option to be able to report failed tests that should not be retried-w, --maxWorkers
still remains as a passthrough;-c, --config
still remains as passthrough;testRunner
config section where the user can add extra CLI arguments to pass by default to the test runner via Detox CLI;keepLockFile
and global lifecycle handers logic from CLItestRunner
section extendable by other third-party users (less hardcoded Object.assign's, more _.merge, please)runnerConfig/testRunner/runner-config/test-runner
strings with deprecation warningsrequire('detox')
globalSetup
,globalTeardown
;MissingDetox
double class which mitigatedjest-jasmine2
test execution quirks;bunyan-debug-stream
-processed.log
version aside the merged JSONLtrace
andtraceCall
: implement it back via logging mechanism;CI=1 npx detox test -c stub e2e/01.sanity.test.js e2e/02.matchers.test.js -w 2 --jest-report-specs=false
:DetoxInternalError: the tester is already connected to the session 4f6bdfd1-c6a2-7383-0451-e54d4b4e719a
npx detox test -c stub e2e/01.sanity.test.js e2e/02.matchers.test.js -w 2
: `TypeError: Cannotjest --runInBand
withoutdetox test
CLIsame as above, no local-cli, but with Jest config where Detox init happens (!)nope, we useresolveConfig
now.local-cli
scriptsRealms
A realm object abstracts the notion of a distinct global environment, with its own global object. For each stateful module and singleton in our codebase, now it is high time to make it crystally clear in which realm[^1] it runs, because we historally had, still have and will have quite a few realms, 🤯 :
root
realm: usually Detox CLI, whereyargs
run, but see the caveats section below. It is the first and the only place which receives all the possible means (environment variables, CLI arguments) to synthesize a working Detox config to use throughout the whole test session. It controls the test runner process and might spawn it a few times if the retry mechanism is enabled.runner
realm: this is the global context of the test runner which is responsible for spawning and controlling the test workers, reporting the tests' status after the entire session. In the case of Jest, it runs in a separate process.worker
realm: this is likely to be running as the bottom-most OS process, but in the case of Jest, this is not the lowest tier yet – its goal is to create sandboxes for every next test suite file, each of which is running inside a special test environment class.sandbox
realm: this is where the user test itself is executed, the most short-living realm which cannot persist any re-usable state in the context of the entire test session. In the case of Jest, its global variables are controlled by the test environment class.Important caveats:
runner
realm can be also atop
realm – for example, when Detox is started without the help of its own CLI and just by using test runner command.worker
realm can be also arunner
realm – for example, if the test runner does not support parallelism and runs everything in one thread.sandbox
realm can be also aworker
realm – in theory, a runner might not use any kind of sandboxing.Hence, the entire distinction is conceptual above all. In practice, though, if we speak about the most common combination of
detox-cli > jest-cli > ..worker.. > ..sandbox..
, they indeed will be running as separate realms and processes in the operating system.Resolving Detox config only once
This is very important because it eliminates the problem of multiple sources of truth, and reduces the time window "when Detox config is not resolved yet" – that reduces the number of assumptions in the code because the Detox state is almost never ambiguous.
The text was updated successfully, but these errors were encountered: