Skip to content

Commit 2cda2bb

Browse files
author
Luca Forstner
authored
test(e2e): Add E2E Test recipe framework (#5836)
1 parent 09a70cb commit 2cda2bb

File tree

14 files changed

+438
-37
lines changed

14 files changed

+438
-37
lines changed

packages/e2e-tests/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
node: true,
44
},
55
extends: ['../../.eslintrc.js'],
6-
ignorePatterns: [],
6+
ignorePatterns: ['test-applications/**'],
77
parserOptions: {
88
sourceType: 'module',
99
},

packages/e2e-tests/README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# E2E Tests
2+
3+
E2E tests enable us to verify the behavior of the packages in this repository as if they were to be published in their
4+
current state.
5+
6+
## How to run
7+
8+
Prerequisites: Docker
9+
10+
```bash
11+
yarn test:e2e
12+
```
13+
14+
## How they work
15+
16+
Before running any tests we launch a fake test registry (in our case [Verdaccio](https://verdaccio.org/docs/e2e/)), we
17+
build our packages, pack them, and publish them to the fake registry. The fake registry is hosted in a Docker container,
18+
and the script to publish the packages is also run from within a container to ensure that the fake publishing happens
19+
with the same Node.js and npm versions as we're using in CI.
20+
21+
After publishing our freshly built packages to the fake registry, the E2E test script will look for `test-recipe.json`
22+
files in test applications located in the `test-applications` folder. In this folder, we keep standalone test
23+
applications, that use our SDKs and can be used to verify their behavior. The `test-recipe.json` recipe files contain
24+
information on how to build the test applications and how to run tests on these applications.
25+
26+
## How to set up a new test
27+
28+
Test applications are completely standalone applications that can be used to verify our SDKs. To set one up, follow
29+
these commands:
30+
31+
```sh
32+
cd packages/e2e-tests
33+
34+
# Create a new test application folder
35+
mkdir test-applications/my-new-test-application # Name of the new folder doesn't technically matter but choose something meaningful
36+
37+
# Create an npm configuration file that uses the fake test registry
38+
cat > test-applications/my-new-test-application/.npmrc << EOF
39+
@sentry:registry=http://localhost:4873
40+
@sentry-internal:registry=http://localhost:4873
41+
EOF
42+
43+
# Add a gitignore that ignores lockfiles
44+
cat > test-applications/my-new-test-application/.gitignore << EOF
45+
yarn.lock
46+
package-lock.json
47+
EOF
48+
49+
# Add a test recipe file to the test application
50+
touch test-applications/my-new-test-application/test-recipe.json
51+
```
52+
53+
To get you started with the recipe, you can copy the following into `test-recipe.json`:
54+
55+
```json
56+
{
57+
"$schema": "../../test-recipe-schema.json",
58+
"testApplicationName": "My New Test Application",
59+
"buildCommand": "yarn install --no-lockfile",
60+
"tests": [
61+
{
62+
"testName": "My new test",
63+
"testCommand": "yarn test",
64+
"timeoutSeconds": 60
65+
}
66+
]
67+
}
68+
```
69+
70+
The `test-recipe.json` files follow a schema (`e2e-tests/test-recipe-schema.json`). Here is a basic explanation of the
71+
fields:
72+
73+
- The `buildCommand` command runs only once before any of the tests and is supposed to build the test application. If
74+
this command returns a non-zero exit code, it counts as a failed test and the test application's tests are not run.
75+
- The `testCommand` command is supposed to run tests on the test application. If the configured command returns a
76+
non-zero exit code, it counts as a failed test.
77+
- A test timeout can be configured via `timeoutSeconds`, it defaults to `60`.
78+
79+
**An important thing to note:** In the context of the `buildCommand` the fake test registry is available at
80+
`http://localhost:4873`. It hosts all of our packages as if they were to be published with the state of the current
81+
branch. This means we can install the packages from this registry via the `.npmrc` configuration as seen above. If you
82+
add Sentry dependencies to your test application, you should set the dependency versions set to `*`:
83+
84+
```jsonc
85+
// package.json
86+
{
87+
"name": "my-new-test-application",
88+
"version": "1.0.0",
89+
"private": true,
90+
"scripts": {
91+
"test": "echo \"Hello world!\""
92+
},
93+
"dependencies": {
94+
"@sentry/node": "*"
95+
}
96+
}
97+
```
98+
99+
All that is left for you to do now is to create a test app and run `yarn test:e2e`.

0 commit comments

Comments
 (0)