|
| 1 | +# Architecture of universal-test-runner |
| 2 | + |
| 3 | +universal-test-runner is made up of two main components: |
| 4 | +* A CLI, a.k.a the "runner" |
| 5 | +* Built-in "adapters" (for jest, pytest, dotnet, maven, and gradle) |
| 6 | + |
| 7 | +The project is organized as a monorepo using npm workspaces to manage multiple packages: |
| 8 | +* The runner is its own package |
| 9 | +* Each built-in adapter is its own package |
| 10 | +* The remaining packages are utilities shared across the runner and adapter packages |
| 11 | + |
| 12 | +The monorepo setup is not strictly necessary, but does provide a clear |
| 13 | +separation between adapters, and necessitates that we structure the built-in |
| 14 | +adapters in an identical way to third-party adapters or custom adapters. This |
| 15 | +means that all adapters are loading using the same code path, regardless of |
| 16 | +what kind of adapters they are. |
| 17 | + |
| 18 | +## Sequence diagram |
| 19 | + |
| 20 | +The following diagram describes at a high-level what happens when a user |
| 21 | +invokes universal-test-runner via the CLI with an adapter, e.g. `run-tests |
| 22 | +jest` or `run-tests ./my-adapter.js`. The steps are described in more detail |
| 23 | +below, along with an outline of the separation between the runner and the |
| 24 | +adapters and what their responsibilities are. |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +## The runner |
| 29 | + |
| 30 | +The runner is responsible for the following: |
| 31 | +* Reading the Test Execution Protocol variables from the environment (in this case, from process.env) |
| 32 | +* Loading the correct adapter |
| 33 | +* Transforming the protocol variables to and AdapterInput object |
| 34 | +* Invoking the adapter with the correct AdapterInput |
| 35 | +* Reporting results back to the user of the CLI |
| 36 | + |
| 37 | +The runner has no specific knowledge of any test frameworks -- it should always |
| 38 | +delegate any framework-specific behaviour to an adapter. |
| 39 | + |
| 40 | +## Adapters |
| 41 | + |
| 42 | +An adapter is responsible for invoking a single test framework in order to |
| 43 | +execute tests. An adapter should be associated with exactly one test |
| 44 | +framework. Adapters must report the results of a test run by returning an |
| 45 | +AdapterOutput object. Adapters should not expose any framework details to the |
| 46 | +runner. |
| 47 | + |
| 48 | +As of writing, all of the built-in adapters are using Node.js |
| 49 | +`child_process.spawn` to invoke their frameworks as if they were being run on |
| 50 | +the command line, but this is not required -- adapters can run the tests |
| 51 | +however they so please, as long as the tests are run and execution status can |
| 52 | +be reported back to the runner. For example, the jest adapter could conceivably |
| 53 | +use jest-editor-support (https://www.npmjs.com/package/jest-editor-support) to |
| 54 | +run the tests, instead of `spawn`. |
0 commit comments