-
Notifications
You must be signed in to change notification settings - Fork 491
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
feat: E2E test suite with puppeteer+ipfsd-ctl #1353
Conversation
This is initial version that uses jest-puppeteer for end to end integration/regression tests against real HTTP API. For now it runs headless chromium against go-ipfs, but can be extended to run test matrix against js-ipfs as well. Single file upload acts as a POC test case.
(we don't want to use go-ipfs-dep from ipfsd-ctl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor changes, but LGTM otherwise!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far looks good! Please let me know when you want a deep review of this!
Ok, I've split tests into separate files but kept them small to test as much they can while still easy to maintain. Updated README with details about E2E. @hugomrdias I used new ipfsd-ctl in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you @lidel for taking over this. This is awesome!
test/e2e/peers.test.js
Outdated
beforeAll(async () => { | ||
// spawn an ephemeral local node for manual swarm connect test | ||
const factory = Ctl.createFactory({ type: 'proc', test: true, disposable: true }) | ||
ipfsd = await factory.spawn() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you dont need to handle multiple nodes you can use createController
test/e2e/setup/global-init.js
Outdated
if (endpoint) { | ||
// create http client for endpoint passed via E2E_API_URL= | ||
ipfs = ipfsClient({ apiAddr: endpoint }) | ||
} else { | ||
// use ipfds-ctl to spawn daemon to expose http api used for e2e tests | ||
const type = process.env.E2E_IPFSD_TYPE || 'go' | ||
const factory = Ctl.createFactory({ | ||
type, | ||
test: true, // sets up all CORS headers required for accessing HTTP API port of ipfsd node | ||
overrides: { // call findBin here to ensure we use version from devDependencies, and not from ipfsd-ctl | ||
js: { ipfsBin: findBin('js') }, | ||
go: { ipfsBin: findBin('go') } | ||
} | ||
}) | ||
ipfsd = await factory.spawn() | ||
ipfs = ipfsd.api | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn this is totally wrong we need to talk so i can improve the ctl docs :)
- you only need to control one node type per test run ? if yes just use
createController()
- overrides are the in the second param https://github.com/ipfs/js-ipfsd-ctl#createfactoryoptions-overrides
- you can do the endpoint === true with ctl also using
createController({remote: true, endpoint: endpoint})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hugomrdias: thanks for the tips, I fixed first two points in bac8428 and opened PR to improve ipfsd-ctl docs in ipfs/js-ipfsd-ctl#421
As for the third point about remote endpoint, I don't think the createController({remote: true, endpoint: process.env.E2E_API_URL })
will work, because E2E_API_URL
is the IPFS API, not the one provided by Ctl.createServer
.
Running createController({remote: true, endpoint: 'http://127.0.0.1:5001' })
produces error (probably due to 404 for /api/v0/..
):
HTTPError: Not Found
at fn (/home/lidel/project/ipfs-webui/node_modules/ky/umd.js:337:12)
at process._tickCallback (internal/process/next_tick.js:68:7)
Let me know if I got this wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if aren't using createServer you shouldn't need ctl only http-client right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. We don't use createServer
in e2e tests.
If E2E_API_URL
is defined it means HTTP API got spawned by a third party, and we just use regular client for connecting to it.
@hugomrdias applied your suggestions (details in #1353 (comment)). Should be good enough. |
This PR adds E2E tests for WebUI that run against HTTP API from real IPFS node
Try with:
$ npm run test:e2e # headless against go-ipfs
Implementation details
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.
The purpose of those tests is not being comprehensible, but act as a quick regression and integration suite.
Make sure
npm run build
is run before starting E2E tests:Customizing E2E Tests
Default behavior can be tweaked via env variables below.
E2E_IPFSD_TYPE
Variable named
E2E_IPFSD_TYPE
defines which IPFS backend should be used for end-to-end tests.CI setup of ipfs-webui repo runs tests against both JS and GO implementations:
It is possible to test against arbitrary versions by tweaking
ipfs
(js-ipfs)and
go-ipfs-dep
(go-ipfs) indevDependencies
section ofpackage.json
and applying the change vianpm i
E2E_API_URL
Instead of spawning a disposable node and repo for tests, one can point the E2E test suite at arbitrary HTTP API running on localhost:
$ E2E_API_URL=http://127.0.0.1:5001 npm run test:e2e
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)Caveat 2: CORS requests from
http://localhost:3001
(static server hosting dev version of webui) need to be added toAccess-Control-Allow-Origin
whitelist array in node's config:Can be done ad-hoc via command line:
Debugging E2E tests
Show the browser
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.
To disable headless mode and see the browser, set the environment variable
DEBUG=true
:$ DEBUG=true npm run test:e2e # e2e in slowed down mode in a browser window
Breakpoints
It is possible to set a "breakpoint" via
await jestPuppeteer.debug()
to stop tests at a specific line: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:
TODO
npm run test:e2e
should run headless e2e tests against real go-ipfsDEBUG=true npm run test:e2e
should show browser windowipfs
(API interface for real node) should be in scope of testsE2E_IPFSD_TYPE
)node_modules
test/e2e
E2E_API_URL
)