Skip to content

Commit 8acf9cb

Browse files
committedMar 20, 2025·
wip: documenting end to end tests
1 parent ff8dcbc commit 8acf9cb

10 files changed

+110
-23
lines changed
 

‎docs/.vitepress/config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function getGuidesSidebar () {
5959
{ text: 'Testing your app', link: '/guides/development/test' },
6060
{ text: 'Configure your app', link: '/guides/development/configure' },
6161
{ text: 'Deploy your app', link: '/guides/development/deploy' },
62+
{ text: 'Automating tests', link: '/guides/development/automated_tests' },
6263
{ text: 'Document your app', link: '/guides/development/documentation' },
6364
{ text: 'Managing app flavors', link: '/guides/development/flavors' },
6465
{ text: 'Use our CLI', link: '/guides/development/kli' },

‎docs/.vitepress/public/images/run-tests-steps.svg

+4
Loading
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Automating tests
2+
3+
We use the CI system to automate running tests we defined in the [Testing your app](./test) section (API and client) .
4+
5+
## API (or backend) tests
6+
7+
These tests are directly run by the `run_tests` **CI job** (defined in the [CI workflow](https://github.com/kalisio/skeleton/blob/master/.github/workflows/main.yaml)). They run on the CI system after each push to the repo. The basically run the tests you defined in the [API tests](./test#api) section.
8+
9+
![Run tests steps](./../../.vitepress/public/images/run-tests-steps.svg)
10+
11+
There's also an `additional_tests` **CI job** whose purpose is to run the same set of API tests, but using different combinations of `Node.js` and `MongoDB` versions.
12+
13+
## Client (or frontend) tests
14+
15+
These tests are not directly run by the CI system. Instead we build a container image using the CI system. That container image embeds everything needed to run client test (most likely [Puppeteer](https://pptr.dev/) along with the actual tests and some reference screenshots). That container is then run *on the infrastructure hosting the app*, once a day (but it can also be run locally on a developper workstation).
16+
17+
The **CI job** responsible for building the container image is `build_e2e_tests`. It uses the `e2e-tests.Dockerfile` as recipe for the image, and embeds the `run_e2e_tests.sh` **CI script**, which is used as container command.
18+
19+
The `run_e2e_tests.sh` script is used in the container image to run the frontend tests. It's purpose is to:
20+
* run the frontend tests (as defined in the [Client tests](./tests#client) section)
21+
* upload all test artefacts on an S3 storage
22+
* generate a report from those tests (can be through a slack notification or as a Markdown file in a git repository)

‎e2e-tests.Dockerfile

+7-16
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,16 @@
44
ARG DEBIAN_VERSION=bookworm
55
ARG NODE_VERSION=20
66

7-
87
## Use a builder
98
##
109

1110
FROM node:${NODE_VERSION}-${DEBIAN_VERSION}-slim as builder
1211
LABEL maintainer="contact@kalisio.xyz"
1312

14-
COPY . /opt/kalisio
13+
COPY . /opt/kalisio
1514

1615
# Setting environment variables
1716
ARG APP
18-
ARG NODE_APP_INSTANCE
19-
ARG SUBDOMAIN
20-
ARG HEADLESS
21-
22-
ENV APP=$APP
23-
ENV NODE_APP_INSTANCE=$NODE_APP_INSTANCE
24-
ENV SUBDOMAIN=$SUBDOMAIN
25-
ENV HEADLESS=$HEADLESS
2617

2718
# Development environment setup
2819
WORKDIR /opt/kalisio/
@@ -43,18 +34,17 @@ LABEL maintainer="contact@kalisio.xyz"
4334
ARG APP
4435
ARG NODE_APP_INSTANCE
4536
ARG SUBDOMAIN
46-
ARG HEADLESS
4737

4838
ENV APP=$APP
4939
ENV NODE_APP_INSTANCE=$NODE_APP_INSTANCE
5040
ENV SUBDOMAIN=$SUBDOMAIN
51-
ENV HEADLESS=$HEADLESS
41+
ENV HEADLESS=true
5242

5343
# Setup Puppeteer & Rclone and installation of the necessary packages
5444
# https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker
5545
RUN export DEBIAN_FRONTEND=noninteractive \
5646
&& apt-get update \
57-
&& apt-get install -y wget gnupg curl zip unzip rclone \
47+
&& apt-get install -y wget gnupg curl zip rclone git \
5848
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
5949
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
6050
&& apt-get update \
@@ -93,10 +83,11 @@ RUN mkdir -p /home/node/.local/bin/ \
9383
&& touch /home/node/.local/bin/cc-test-reporter \
9484
&& chmod 755 /home/node/.local/bin/cc-test-reporter
9585

96-
# Grant execute permissions
86+
# Make sure runner is properly setup
9787
WORKDIR /opt/kalisio/$APP/scripts
98-
RUN chmod +x run_e2e_test.sh
88+
RUN ./init_runner.sh run_e2e_tests
9989

10090
# Run tests
10191
WORKDIR /opt/kalisio/$APP
102-
CMD ["bash", "-c", "/opt/kalisio/$APP/scripts/run_e2e_test.sh $APP"]
92+
ENV PATH="$PATH:/home/node/.local/bin"
93+
CMD ["bash", "-c", "/opt/kalisio/$APP/scripts/run_e2e_test.sh $APP"]

‎e2e-tests.Dockerfile.dockerignore

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
# But ignore these anyway
1+
# This is the dockerignore used by e2e-tests.Dockerfile, it filters out
2+
# everything we don't want in the 'COPY . /opt/kalisio' step where
3+
# '.' is the workspace folder.
4+
# Since we expect the workspace to be clean, we don't allowlist
5+
# specific folders, we copy everyhting but the following :
6+
7+
# Ignore all these
8+
development/*
29
**/node_modules
310
**/npm-debug.log
411
**/*Dockerfile
512
**/docker-compose*
613
**/*dockerignore
714
**/.git
815
**/.gitignore
9-
**/*.dec.*
16+
**/.quasar
17+
**/dist
18+
**/logs

‎scripts/build_docs.sh

100644100755
File mode changed.

‎scripts/build_e2e_tests.sh

+41-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
set -euo pipefail
33
# set -x
44

5+
# This script is used to build the end to end tests container and to eventually push the produced image on a remote
6+
# container repository.
7+
# It must be run in a proper 'CI workspace' to find everything it expects (cf setup_workspace.sh script).
8+
# By default it only build the image container, it won't push it, you need '-p' for that
9+
510
THIS_FILE=$(readlink -f "${BASH_SOURCE[0]}")
611
THIS_DIR=$(dirname "$THIS_FILE")
712
ROOT_DIR=$(dirname "$THIS_DIR")
@@ -13,6 +18,7 @@ WORKSPACE_DIR="$(dirname "$ROOT_DIR")"
1318
##
1419

1520
PUBLISH=false
21+
CI_STEP_NAME="Build e2e tests"
1622
while getopts "pr:" option; do
1723
case $option in
1824
p) # define to publish container to registry
@@ -31,4 +37,38 @@ done
3137
## Build e2e tests
3238
##
3339

34-
build_e2e_tests "$ROOT_DIR" "$PUBLISH"
40+
# This uses the 'name' field in the app package.json, which must be in lowercase.
41+
# TODO: you may need to adjust the second parameter to point it to the $KLI_BASE
42+
init_app_infos "$ROOT_DIR" "$WORKSPACE_DIR/development/workspace/apps"
43+
44+
APP=$(get_app_name)
45+
VERSION=$(get_app_version)
46+
FLAVOR=$(get_app_flavor)
47+
48+
# This loads credentials for the target container repository
49+
# TODO: you may adjust these files to use the ones in your associated 'development' repository
50+
load_env_files "$WORKSPACE_DIR/development/common/kalisio_harbor.enc.env"
51+
load_value_files "$WORKSPACE_DIR/development/common/KALISIO_HARBOR_PASSWORD.enc.value"
52+
53+
# TODO: you may change the path for the container image, here it'll be pushed in a 'kalisio' group
54+
IMAGE_NAME="kalisio/$APP-e2e-tests"
55+
IMAGE_TAG="$VERSION-$FLAVOR"
56+
# TODO: you may change the subdomain on which the app to be tested is hosted
57+
SUBDOMAIN="dev.kalisio.xyz"
58+
59+
case "$FLAVOR" in
60+
"prod")
61+
SUBDOMAIN="kalisio.com"
62+
;;
63+
"test")
64+
SUBDOMAIN="test.kalisio.xyz"
65+
;;
66+
*)
67+
;;
68+
esac
69+
70+
# TODO: the environment variables to use here may not be the same (container registry credentials)
71+
build_e2e_tests \
72+
"$ROOT_DIR" "$SUBDOMAIN" "$PUBLISH" \
73+
"$KALISIO_HARBOR_URL" "$KALISIO_HARBOR_USERNAME" "$KALISIO_HARBOR_PASSWORD" \
74+
"$IMAGE_NAME" "$IMAGE_TAG"

‎scripts/init_runner.sh

100644100755
File mode changed.

‎scripts/run_e2e_test.sh

100644100755
+24-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
set -uo pipefail
33
# set -x
44

5+
# This script is not directly run by the CI system. Instead it is embedded in the end to end test
6+
# container and used as the container command.
7+
# It requires the app name to be the first argument
8+
59
APP=$1
610

711
THIS_FILE=$(readlink -f "${BASH_SOURCE[0]}")
@@ -10,8 +14,24 @@ ROOT_DIR=$(dirname "$THIS_DIR")
1014

1115
. "$THIS_DIR/kash/kash.sh"
1216

13-
## Run e2e tests
14-
##
17+
# TODO: depending on where you want your end to end tests report to be published, you'll need to adjust here
18+
19+
# This is to publish the report as a slack channel message
20+
# We expect the following to be defined as environment variables:
21+
# - S3_BUCKET
22+
# - RCLONE_CONF
23+
# - SLACK_WEBHOOK
24+
run_and_publish_e2e_tests_to_slack \
25+
"$ROOT_DIR" "$APP" \
26+
"$S3_BUCKET" "$RCLONE_CONF" \
27+
"$SLACK_WEBHOOK"
1528

16-
# SLACK_WEBHOOK is set upon Kubernetes container startup
17-
run_e2e_tests "$ROOT_DIR" "$APP" "$SLACK_WEBHOOK"
29+
# This is to publish as a markdown report in a git repository
30+
# We expect the following to be defined as environment variables:
31+
# - S3_BUCKET
32+
# - RCLONE_CONF
33+
# - TARGET_GIT_REPO_URL
34+
run_and_publish_e2e_tests_to_git_repo \
35+
"$ROOT_DIR" "$APP" \
36+
"$S3_BUCKET" "$RCLONE_CONF" \
37+
"$TARGET_GIT_REPO_URL" "reports"

‎scripts/run_tests.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)
Please sign in to comment.