Skip to content

Commit 59b2d67

Browse files
authored
feat: E2E test suite with puppeteer+ipfsd-ctl (#1353)
This adds end to end tests against real HTTP API. Uses jest-puppeteer and ipfsd-ctl for orchestration. By default it runs headless chromium against go-ipfs, but can be made to run test matrix against js-ipfs with E2E_IPFSD_TYPE=js or arbitrary HTTP API via E2E_API_URL
1 parent 32d336b commit 59b2d67

20 files changed

+30788
-3144
lines changed

.circleci/config.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ jobs:
1616
- run:
1717
command: npm run build
1818
- run:
19-
command: npm run test:e2e:ci
19+
command: E2E_IPFSD_TYPE=go npm run test:e2e
20+
- run:
21+
command: E2E_IPFSD_TYPE=js npm run test:e2e
2022
- run:
2123
command: npm run bundlesize
2224
- persist_to_workspace:

README.md

+70-9
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,90 @@ The WebUI uses Jest to run the isolated unit tests. Unit test files are located
105105

106106
## End-to-end tests
107107

108-
The end-to-end tests (e2e) test the full app in a headless Chromium browser. They require an http server to be running to serve the app.
108+
The end-to-end tests (e2e) test the full app in a headless Chromium browser. They spawn real IPFS node for HTTP API and a static HTTP server to serve the app.
109+
The purpose of those tests is not being comprehensible, but act as a quick regression and integration suite.
109110

110-
In dev, run `npm start` in another shell before starting the tests
111+
Make sure `npm run build` is run before starting E2E tests:
111112

113+
```console
114+
$ npm run build
115+
$ npm run test:e2e # end-to-end smoke tests (fast, headless, use go-ipfs)
112116
```
113-
# Run the end-to-end tests
114-
> npm run test:e2e
117+
118+
### Customizing E2E Tests
119+
120+
Default behavior can be tweaked via env variables below.
121+
122+
#### `E2E_IPFSD_TYPE`
123+
124+
Variable named `E2E_IPFSD_TYPE` defines which IPFS backend should be used for end-to-end tests.
125+
126+
CI setup of ipfs-webui repo runs tests against both JS and GO implementations:
127+
128+
```console
129+
$ E2E_IPFSD_TYPE=go npm run test:e2e # 'go' is the default if missing
130+
$ E2E_IPFSD_TYPE=js npm run test:e2e
131+
```
132+
133+
It is possible to test against arbitrary versions by tweaking `ipfs` (js-ipfs)
134+
and `go-ipfs-dep` (go-ipfs) in `devDependencies` section of `package.json` and applying the change via `npm i`
135+
136+
#### `E2E_API_URL`
137+
138+
Instead of spawning a disposable node and repo for tests, one can point the E2E test suite at arbitrary HTTP API running on localhost:
139+
140+
```console
141+
$ E2E_API_URL=http://127.0.0.1:5001 npm run test:e2e
115142
```
116143

117-
By default the test run headless, so you won't see the the browser. To debug test errors, it can be helpful to see the robot clicking around the site. To disable headless mode and see the browser, set the environment variable `DEBUG=true`
144+
**Caveat 1:** HTTP API used in tests needs to run on the local machine for Peers screen to pass (they test manual swarm connect to ephemeral `/ip4/120.0.0.1/..` multiaddr)
118145

146+
**Caveat 2:** CORS requests from `http://localhost:3001` (static server hosting dev version of webui) need to be added to `Access-Control-Allow-Origin` whitelist array in node's config:
147+
148+
```json
149+
"API": {
150+
"HTTPHeaders": {
151+
"Access-Control-Allow-Origin": [
152+
"http://localhost:3001"
153+
]
154+
}
155+
}
119156
```
120-
# See the end-to-end tests in a browser
121-
> DEBUG=true npm run test:e2e
157+
158+
Can be done ad-hoc via command line:
159+
160+
```console
161+
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://localhost:3001"]'
162+
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
122163
```
123164

124-
In a **continuous integration** environment we lint the code, run the unit tests, build the app, start an http server and run the unit e2e tests.
165+
### Debugging E2E tests
166+
167+
#### Show the browser
168+
169+
By default, the test run headless, so you won't see the browser. To debug test errors, it can be helpful to see the robot clicking around the site.
170+
To disable headless mode and see the browser, set the environment variable `DEBUG=true`:
171+
172+
```console
173+
$ DEBUG=true npm run test:e2e # e2e in slowed down mode in a browser window
174+
```
175+
176+
#### Breakpoints
177+
178+
It is possible to set a "breakpoint" via `await jestPuppeteer.debug()` to stop tests at a specific line:
179+
180+
```js
181+
jest.setTimeout(600000) // increase test suite timeout
182+
await jestPuppeteer.debug() // puppeteer will pause here
183+
```
184+
185+
In a **continuous integration** environment we lint the code, run the unit tests, build the app, start an http server and run the unit e2e tests:
125186

126187
```sh
127188
> npm run lint
128189
> npm test
129190
> npm run build
130-
> npm run test:ci:e2e
191+
> npm run test:e2e
131192
```
132193

133194
## Coverage

0 commit comments

Comments
 (0)