Skip to content

Commit

Permalink
docs(build-env): add motivation section
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Sep 13, 2024
1 parent 3be835b commit 105e67a
Showing 1 changed file with 138 additions and 0 deletions.
138 changes: 138 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,142 @@

This workspace maintains a scalable and maintainable E2E setup for Vite tests and Verdaccio.

## Motivation

### Flaws in the current setup

One of the biggest flaws of e2e setups you find in the wild is one shared environment for all projects.

This leads to a lot of problems:

- flaky tests
- long setup times
- hard to debug
- hard to maintain
- impossible to scale

#### Changes files during e2e

The changed files during testing, as they interfere with configurations on your system.

```sh
User/
└── <user-name>/
β”œβ”€β”€ .npmrc # πŸ”“ added registry and token entry to OS user specific npm config
└──Root/ # πŸ‘ˆ this is your CWD
β”œβ”€β”€ node_modules/
β”‚ └── <org>
β”‚ └── <package-name>/... # πŸ”“ npm install installs into repository folder
β”œβ”€β”€ dist/
β”‚ └── packages/
β”‚ └── <project-name>/...
β”œβ”€β”€ tmp/
β”‚ └── local-registry/ # πŸ˜“ hard to debug a dynamic port
β”‚ β”œβ”€β”€ storage/...
β”‚ β”‚ └── <org>
β”‚ β”‚ └── <package-name>/... # nx nx-release-publish saves the package's tarball here
β”‚ └── <test-name>/...
β”‚ └── <test-case>/...
β”œβ”€β”€ package-lock.json # πŸ”“ npm install/uninstall installs into workspace root
└── package.json # πŸ”“ npm install/uninstall installs into workspace root
```

#### Performance

To elaborate on the performance issues, we show the different cases while writing tests.

##### Changes in source

```mermaid
flowchart TB
project-e2e-and-environment:::project-e2e-.implicit.->project:::project;
classDef project-e2e-and-environment stroke:#f00
classDef project stroke:#f00
```

##### Changes in the test environments

```mermaid
flowchart TB
project-e2e-and-environment:::project-e2e-.implicit.->project:::project;
classDef project-e2e-and-environment stroke:#f00
classDef project stroke:#f00
```

##### Changes in tests

```mermaid
flowchart TB
project-e2e-and-environment:::project-e2e-.implicit.->project:::project;
classDef project-e2e-and-environment stroke:#f00
```

### Solution

This workspace provides a scalable and maintainable E2E setup for Vite tests and Verdaccio.
It isolates all involved files into an isolated environment for each e2e project.

#### Changes files during e2e

The changed files during testing, are all in one isolated folder.

```sh
Root/ # πŸ‘ˆ this is your CWD
β”œβ”€β”€ dist/
β”‚ └── packages/
β”‚ └── <project-name>/...
└── tmp/
└── e2e/
└── <project-name>/ # e2e setup
β”œβ”€β”€ storage/... # npm publish/unpublish
β”œβ”€β”€ node_modules/
β”‚ └── <org>
β”‚ └── <package-name>/... # npm install/uninstall
β”œβ”€β”€ __test__/...
β”‚ └── <file-name>/... # e2e beforeEach
β”‚ └── <it-block-setup>/...
β”œβ”€β”€ .npmrc # local npm config configured for project specific verdaccio registry
β”œβ”€β”€ package-lock.json # npm install/uninstall
└── package.json # npm install/uninstall
```

#### Performance

To elaborate on the performance improvements, we show the different cases while writing tests.

##### Changes in source

```mermaid
flowchart TB
project-e2e:::project-e2e-.implicit.->e2e-environment:::e2e-environment;
e2e-environment-.implicit.->project:::project;
classDef project-e2e stroke:#f00
classDef e2e-environment stroke:#f00
classDef project stroke:#f00
```

##### Changes in the test environments

```mermaid
flowchart TB
project-e2e:::project-e2e-.implicit.->e2e-environment:::e2e-environment;
e2e-environment-.implicit.->project:::project;
classDef project-e2e stroke:#f00
classDef e2e-environment stroke:#f00
```

##### Changes in tests

```mermaid
flowchart TB
project-e2e:::project-e2e-.implicit.->e2e-environment:::e2e-environment;
e2e-environment-.implicit.->project:::project;
classDef project-e2e stroke:#f00
```

## Test it

Publishable project have a `publishable` tag.
Expand All @@ -15,6 +151,8 @@ Targets that need an environment set up before running depend on `{ "projects":
Production usage:

- `nx run cli-e2e:e2e` - setup environment and then run E2E tests for `cli-e2e`
@TODO figure out why we can't set the environmentRoot in the target options in `project.json`
- `nx run cli-static-e2e:e2e --environmentRoot static-environments/user-lists` - setup NPM stuff in existing environment and then run E2E tests for `cli-static-e2e`

Debug full environment in 1 setup:

Expand Down

0 comments on commit 105e67a

Please sign in to comment.