Skip to content

Commit eeaa083

Browse files
galarghSgtPooki
andauthored
feat: add E2E tests for chromium and firefox (#1121)
* feat: add E2E tests for chromium and firefox * fix: do not use arrow functions in mocha * feat: create a workflow for running e2e tests * chore: apply review comments * chore: support override of firefox image * fix(test): await async destroy operation * chore: address review comments - replace fixed delays with exponential backoff - make download-release-artifacts.sh work even if build dir already exists - document how to run e2e tests locally - delete user/group if it already exists during release build in docker - make it easier to add new e2e test cases in the future * chore: allow overriding access control settings through env * Update docs/DEVELOPER-NOTES.md Co-authored-by: Russell Dempsey <[email protected]> Co-authored-by: Russell Dempsey <[email protected]>
1 parent 49ad8d0 commit eeaa083

11 files changed

+491
-10
lines changed

.github/workflows/e2e.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: e2e
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
firefox-version:
6+
description: The version of selenium/standalone-firefox image to use
7+
default: latest
8+
required: true
9+
chromium-version:
10+
description: The version of selenium/standalone-chrome image to use
11+
default: latest
12+
required: true
13+
kubo-version:
14+
description: The version of ipfs/kubo image to use
15+
default: latest
16+
required: true
17+
ipfs-companion-version:
18+
description: The version of ipfs-companion extension to use (defaults to building the extension from source)
19+
default: ''
20+
required: false
21+
22+
jobs:
23+
test:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Check out repo
27+
uses: actions/checkout@v3
28+
- name: Set up node
29+
uses: actions/setup-node@v3
30+
with:
31+
node-version: 18
32+
- name: Download ipfs-companion
33+
if: inputs.ipfs-companion-version != ''
34+
run: ./ci/download-release-artifacts.sh
35+
env:
36+
IPFS_COMPANION_VERSION: ${{ inputs.ipfs-companion-version }}
37+
- name: Build ipfs-companion
38+
if: inputs.ipfs-companion-version == ''
39+
run: npm run release-build
40+
- name: Prepare E2E env
41+
run: npm run compose:e2e:prepare
42+
env:
43+
FIREFOX_VERSION: ${{ inputs.firefox-version }}
44+
CHROMIUM_VERSION: ${{ inputs.chromium-version }}
45+
KUBO_VERSION: ${{ inputs.kubo-version }}
46+
- name: Start E2E env
47+
run: npm run compose:e2e:up
48+
env:
49+
FIREFOX_VERSION: ${{ inputs.firefox-version }}
50+
CHROMIUM_VERSION: ${{ inputs.chromium-version }}
51+
KUBO_VERSION: ${{ inputs.kubo-version }}
52+
- name: Wait for E2E env set up to complete
53+
run: sleep 60
54+
- name: Run E2E tests
55+
run: npm run compose:e2e:test
56+
env:
57+
IPFS_COMPANION_VERSION: ${{ inputs.ipfs-companion-version }}
58+
- name: Stop E2E env
59+
run: npm run compose:e2e:down

Dockerfile

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@ ARG GROUP_ID
66
RUN curl -s https://ipfs.io/ipfs/QmbukYcmtyU6ZEKt6fepnvrTNa9F6VqsUPMUgNxQjEmphH > /usr/local/bin/jq && chmod +x /usr/local/bin/jq
77

88
RUN mkdir -p /home/node/app
9-
WORKDIR /home/node/app
10-
119
RUN if [ ${USER_ID:-0} -ne 0 ] && [ ${GROUP_ID:-0} -ne 0 ]; then \
1210
userdel -f node && \
1311
if getent group node ; then groupdel node; fi && \
12+
if getent passwd ${USER_ID} ; then userdel -f $(getent passwd ${USER_ID} | cut -d: -f1); fi && \
13+
if getent group ${GROUP_ID} ; then groupdel $(getent group ${GROUP_ID} | cut -d: -f1); fi && \
1414
groupadd -g ${GROUP_ID} node && \
15-
useradd -l -u ${USER_ID} -g node node && \
16-
chown -fhR ${USER_ID}:${GROUP_ID} /home/node; fi
15+
useradd -l -u ${USER_ID} -g node node; fi
16+
RUN chown -fhR node:node /home/node
1717

18-
COPY --chown=${USER_ID}:${GROUP_ID} . /home/node/app
18+
WORKDIR /home/node/app
19+
20+
COPY --chown=node:node ./package.json ./package-lock.json /home/node/app/
1921

2022
USER node
2123

2224
RUN npm run ci:install
2325

26+
COPY --chown=node:node . /home/node/app
27+
2428
ENV PATH="/home/node/app/node_modules/.bin:${PATH}"

ci/access-control-allow-all.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
set -ex
3+
4+
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "${ACCESS_CONTROL_ALLOW_ORIGIN:-[\"*\"]}"
5+
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods "${ACCESS_CONTROL_ALLOW_METHODS:-[\"*\"]}"

ci/download-release-artifacts.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
set -ex
3+
4+
IPFS_COMPANION_VERSION=${IPFS_COMPANION_VERSION:-$(jq -r '.version' ./add-on/manifest.common.json)}
5+
6+
id="$(curl --retry 5 --no-progress-meter "https://api.github.com/repos/ipfs/ipfs-companion/releases/tags/v$IPFS_COMPANION_VERSION" | jq '.id')"
7+
assets="$(curl --retry 5 --no-progress-meter --location "https://api.github.com/repos/ipfs/ipfs-companion/releases/$id/assets" | jq -r '.[].name')"
8+
9+
if [[ ! -d build ]]; then
10+
mkdir build
11+
fi
12+
13+
for asset in $assets; do
14+
curl --retry 5 --no-progress-meter --location --output "build/$asset" "https://github.com/ipfs/ipfs-companion/releases/download/v$IPFS_COMPANION_VERSION/$asset"
15+
done

docker-compose.e2e.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: "3.9"
2+
services:
3+
firefox:
4+
image: ${FIREFOX_IMAGE:-selenium/standalone-firefox}:${FIREFOX_VERSION:-latest}
5+
shm_size: 2g
6+
ports:
7+
- 4444
8+
- 7900
9+
chromium:
10+
# WARN: `standalone-chrome` does NOT work on ARM-based machines;
11+
# see https://github.com/SeleniumHQ/docker-selenium#experimental-mult-arch-aarch64armhfamd64-images;
12+
# try using `seleniarm/standalone-chromium` instead
13+
# export CHROMIUM_IMAGE=seleniarm/standalone-chromium
14+
image: ${CHROMIUM_IMAGE:-selenium/standalone-chrome}:${CHROMIUM_VERSION:-latest}
15+
shm_size: 2g
16+
ports:
17+
- 4444
18+
- 7900
19+
kubo:
20+
image: ipfs/kubo:${KUBO_VERSION:-latest}
21+
ports:
22+
- 4001
23+
- 5001
24+
- 8080
25+
volumes:
26+
- ./ci/access-control-allow-all.sh:/container-init.d/001-access-control-allow-all.sh
27+
e2e:
28+
build:
29+
dockerfile: ./Dockerfile
30+
environment:
31+
- SELENIUM_REMOTE_CHROMIUM_URL=http://chromium:4444
32+
- SELENIUM_REMOTE_FIREFOX_URL=http://firefox:4444
33+
- IPFS_API_URL=http://kubo:5001
34+
- CUSTOM_GATEWAY_URL=http://kubo:8080
35+
- TEST_E2E=true
36+
- TEST_HEADLESS=${TEST_HEADLESS:-false}
37+
- IPFS_COMPANION_VERSION=${IPFS_COMPANION_VERSION}
38+
volumes:
39+
- ./build:/home/node/app/build

docs/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ If you want to download translations from Transifex and run them locally, make s
3232

3333
## Writing Code
3434

35-
**If you plan to write code make sure to read [Developer Notes](./docs/DEVELOPER-NOTES.md) to get familiar with tools and commands that will make your work easier.**
35+
**If you plan to write code make sure to read [Developer Notes](DEVELOPER-NOTES.md) to get familiar with tools and commands that will make your work easier.**
3636

3737
## How to Help with Things Beyond Browser Extension?
3838

docs/DEVELOPER-NOTES.md

+88
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,94 @@ Release build shortcuts:
137137
- `npm run dev-build`: All-in-one: fast dependency install, build with yarn (updates `yarn.lock` if needed)
138138
- `npm run release-build`: Reproducible release build in docker with frozen `yarn.lock`
139139

140+
E2E tests:
141+
142+
- `npm run compose:e2e:prepare`: Pull and build docker images for e2e tests
143+
- `npm run compose:e2e:up`: Start e2e test docker environment
144+
- `npm run compose:e2e:test`: Run e2e tests in the docker environment
145+
- `npm run compose:e2e:down`: Stop e2e test docker environment
146+
147+
## Running E2E tests
148+
149+
E2E tests are run in a docker environment, so you need to have docker installed.
150+
151+
### Preparing extension builds
152+
153+
You can run the tests against either release or dev builds of the extension.
154+
155+
To download release builds of the extension, run:
156+
157+
```sh
158+
./ci/e2e/download-release-builds.sh
159+
```
160+
161+
_NOTE_: When using release builds, you can control the version of the extension by setting the `IPFS_COMPANION_VERSION` environment variable:
162+
163+
```sh
164+
export IPFS_COMPANION_VERSION=x.y.z
165+
```
166+
167+
To build dev versions of the extension, run:
168+
169+
```sh
170+
npm run build
171+
```
172+
173+
or (to perform the build inside a docker container):
174+
175+
```sh
176+
npm run release-build
177+
```
178+
179+
### Preparing the docker environment
180+
181+
You need to pull docker images for [Kubo](https://github.com/ipfs/kubo), [Chromium](https://hub.docker.com/r/selenium/standalone-chrome/) and [Firefox](https://hub.docker.com/r/selenium/standalone-firefox/) before running the tests.
182+
183+
You also need to build the docker image containing the e2e tests.
184+
185+
To do all of this, run:
186+
187+
```sh
188+
npm run compose:e2e:prepare
189+
```
190+
191+
_NOTE_: You can control the versions of Kubo, Chromium and Firefox by setting the following environment variables:
192+
193+
```sh
194+
export KUBO_VERSION=x.y.z
195+
export CHROMIUM_VERSION=x.y.z
196+
export FIREFOX_VERSION=x.y.z
197+
```
198+
199+
**IMPORTANT**: If you are running the tests on a ARM machine, you need to use a different Chromium image. To do this, run:
200+
201+
```sh
202+
export CHROMIUM_IMAGE=seleniarm/standalone-chromium
203+
export FIREFOX_IMAGE=seleniarm/standalone-firefox
204+
```
205+
206+
### Running the tests
207+
208+
To run the tests, run:
209+
210+
```sh
211+
npm run compose:e2e:test
212+
```
213+
214+
_NOTE_: You can control whether the browsers operate in headless mode as follows:
215+
216+
```sh
217+
export TEST_HEADLESS=true
218+
```
219+
220+
### Stopping the docker environment
221+
222+
To stop the docker environment, run:
223+
224+
```sh
225+
npm run compose:e2e:down
226+
```
227+
140228
## Other tips
141229

142230
- You can switch to an alternative Firefox version by overriding your `PATH`:

package-lock.json

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

0 commit comments

Comments
 (0)