Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GUI tests #1698

Merged
merged 7 commits into from Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -130,6 +130,35 @@ jobs:
- name: Clean up the database
run: docker-compose down --volumes

GUI_test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- id: install
run: |
rustup override set stable
rustup update stable

- name: restore build & cargo cache
uses: Swatinem/rust-cache@v2

- name: Launch postgres and min.io
run: |
cp .env.sample .env
mkdir -p ${DOCSRS_PREFIX}/public-html
docker-compose up -d db s3
# Give the database enough time to start up
sleep 5
# Make sure the database is actually working
psql "${DOCSRS_DATABASE_URL}"

- name: Run GUI tests
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
run: ./dockerfiles/run-gui-tests.sh

- name: Clean up the database
run: docker-compose down --volumes

build_tests:
runs-on: ubuntu-latest
needs: build
Expand Down
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -100,6 +100,15 @@ Note that you will need docker installed no matter what, since it's used for Rus
cargo test
```

To run GUI tests:

```
./dockerfiles/run-gui-tests.sh
```

They use the [browser-ui-test](https://github.com/GuillaumeGomez/browser-UI-test/) framework. You
can take a look at its documentation [here](https://github.com/GuillaumeGomez/browser-UI-test/blob/master/goml-script.md).

### Pure docker-compose

If you have trouble with the above commands, consider using `docker-compose up --build`,
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Expand Up @@ -90,6 +90,16 @@ services:
timeout: 5s
retries: 10

gui_tests:
build:
context: .
dockerfile: ./dockerfiles/Dockerfile-gui-tests
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- "${PWD}:/build/out"

volumes:
postgres-data: {}
minio-data: {}
Expand Down
81 changes: 81 additions & 0 deletions dockerfiles/Dockerfile-gui-tests
@@ -0,0 +1,81 @@
FROM ubuntu:22.04 AS build

# Install packaged dependencies
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential git curl cmake gcc g++ pkg-config libmagic-dev \
libssl-dev zlib1g-dev ca-certificates

RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
docker.io \
gcc \
git \
libssl-dev \
pkg-config \
xz-utils

# Install dependencies for chromium browser
RUN apt-get install -y \
gconf-service \
libasound2 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgbm-dev \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
fonts-liberation \
libappindicator1 \
libnss3 \
lsb-release \
xdg-utils \
wget

# Install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y --default-toolchain nightly --no-modify-path --profile minimal
ENV PATH="/root/.cargo/bin:${PATH}"

RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | tar -xJ
ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
ENV NODE_PATH="/node-v14.4.0-linux-x64/lib/node_modules/"

WORKDIR /build

RUN mkdir out

# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
# to create a new folder. For reference:
# https://github.com/puppeteer/puppeteer/issues/375
#
# We also specify the version in case we need to update it to go around cache limitations.
RUN npm install -g browser-ui-test@0.16.10 --unsafe-perm=true

EXPOSE 3000

CMD ["node", "/build/out/gui-tests/tester.js"]
40 changes: 40 additions & 0 deletions dockerfiles/run-gui-tests.sh
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -e

# Just in case it's running, we stop the web server.
docker-compose stop web

docker-compose up -d db s3

# If we have a .env file, we need to temporarily move it so
# it doesn't make sqlx fail compilation.
if [ -f .env ]; then
mv .env .tmp.env
fi

# We add the information we need.
cargo run -- database migrate
cargo run -- build update-toolchain
cargo run -- build crate sysinfo 0.23.4
syphar marked this conversation as resolved.
Show resolved Hide resolved
cargo run -- build crate sysinfo 0.23.5
cargo run -- build add-essential-files

if [ -f .tmp.env ]; then
mv .tmp.env .env
fi

# In case we don't have a `.env`, we create one.
if [ ! -f .env ]; then
cp .env.sample .env
fi

. .env

cargo run -- start-web-server &
SERVER_PID=$!

# status="docker run . -v `pwd`:/build/out:ro gui_tests"
docker-compose run gui_tests
syphar marked this conversation as resolved.
Show resolved Hide resolved
status=$?
exit $status
3 changes: 3 additions & 0 deletions gui-tests/404.goml
@@ -0,0 +1,3 @@
// Checks the content of the 404 page.
go-to: |DOC_PATH| + "/non-existing-crate"
assert-text: ("#crate-title", "The requested crate does not exist")
14 changes: 14 additions & 0 deletions gui-tests/basic.goml
@@ -0,0 +1,14 @@
// Checks that the "latest" URL leads us to the last version of the `sysinfo` crate.
go-to: |DOC_PATH| + "/sysinfo"
// We first check if the redirection worked as expected:
assert-document-property: ({"URL": "/sysinfo/latest/sysinfo/"}, ENDS_WITH)
// Now we go to the actual version we're interested into.
go-to: |DOC_PATH| + "/sysinfo/0.23.5/sysinfo/index.html"
assert: "//*[@class='title' and text()='sysinfo-0.23.5']"
// And we also confirm we're on a rustdoc page.
assert: "#rustdoc_body_wrapper"

// Let's go to the docs.rs page of the crate.
go-to: |DOC_PATH| + "/crate/sysinfo/0.23.5"
assert-false: "#rustdoc_body_wrapper"
assert-text: ("#crate-title", "sysinfo 0.23.5", CONTAINS)