Skip to content

Commit 9dd5af2

Browse files
authored
docs: Add architecture documentation (#247)
1 parent 12b19ea commit 9dd5af2

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ The other packages are either internal utilities or adapters that have unstable
9696
APIs and won't necessarily follow semver. You should avoid depending on them
9797
directly.
9898

99+
## 🏰 Architecture
100+
101+
universal-test-runner is a "Test Execution Protocol-aware" runner that uses an
102+
adapter model to provide support for test frameworks. The runner itself is not
103+
aware of any frameworks, but delegates to the appropriate adapter in order to
104+
execute tests for a specific framework. For more details on the architecture,
105+
see the following documentation:
106+
* [RFC 1](./protocol/rfcs/0001/README.md) for an explanation of the Test Execution Protocol
107+
* universal-test-runner [architecture documentation](./docs/architecture.md), for a description of the runner, the adapters, and how they interact
108+
99109
## 🔋 Custom adapters
100110

101111
It's possible to write custom adapters and pass them to universal-test-runner,

docs/architecture.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
![Sequence diagram](./sequence-diagram.png)
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`.

docs/sequence-diagram.png

17.9 KB
Loading

package-lock.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)