tree: 716cca0d4ea6d6a791296e8888356a793061ad46 [path history] [tgz]
  1. README.md
  2. __image_snapshots__/
  3. __snapshots__/
  4. basic.test.ts
  5. docker/
  6. errors.desktop.test.ts
  7. global-types.ts
  8. helpers/
  9. pkgsite.desktop.test.ts
  10. pkgsite.mobile.test.ts
  11. search.test.ts
  12. setup.ts
  13. test-environment.js
  14. unit.desktop.test.ts
  15. unit.mobile.test.ts
  16. unit.testcases.ts
e2e/README.md

End-to-End (E2E) Tests

This directory contains end-to-end tests for pages on pkg.go.dev.

Running E2E Tests

In order to run the tests, run this command from the root of the repository:

$ ./e2e/docker/run.sh

./e2e/docker/run.sh sets up a series of docker containers that run a postgres database, frontend, and headless chrome, and runs the e2e tests using headless chrome.

Alternatively, you can run the tests against a website that is already running.

First run headless chrome:

docker run --rm -e "CONNECTION_TIMEOUT=-1" -p 3000:3000 browserless/chrome:1.46-chrome-stable

Then run the tests from the root of pkgsite:

./all.bash npx jest [files]

PKGSITE_URL can https://pkg.go.dev, or http://localhost:8080 if you have a local instance for the frontend running.

Understanding Test Failures

If the tests failure, diffs will be created that show the cause of the failure. Timeouts and diff thresholds are configurable for image snapshots if adjustments are needed to prevent test flakiness. See the API for jest image snapshots for more information.

Writing E2E Tests

Tests are written in the Jest framework using Puppeteer to drive a headless instance of Chrome.

Familiarize yourself with the Page class from the Puppeteer documenation. You'll find methods on this class that let you to interact with the page.

Most tests will follow a similar structure but for details on the Jest framework and the various hooks and assertions see the API.