Use puppeteer to navigate around Bibbz looking for errors.
This suite is to demonstrate using puppeteer to functionally test a website. I have used Ava as the test runner because it fast(parallel execution out of the box), easy to use, and forward thinking.
Using docker makes setup more repeatable and portable than a local machine setup. We are using a dev container setup, mounting in the source repository and putting the yarn cache into a docker volume. Please see the Puppeteer repository for this discussion. I have removed the un-privileged user from their suggestion as it did not fix the issue of needing --no-sandbox on puppeteer in the container.
Do I ever need to run locally?
The only reason to run locally is to debug difficult problems. If you do, make the browser HEADLESS=false to see what is happening.
What the Dockerfile and build.sh are accomplishing:
- Create a volume for the Docker yarn cache if it does not already exist.
- Create and configure a base container that can run node, yarn, and puppeteer
- Run the container in interactive mode, mounting the source repository and the yarn cache.
- Install Docker
- Clone this repository with git
- Use the build script
chmod +x build.sh
./build.sh
Now you are in the container. Run the tests.
ENVIRONMENT=PROD NO_SANDBOX=true yarn test
Local changes to our repository show up in the container. This is the purpose of mounting the repository, so we can use a local text editor and then run the code in the container.
We use the test phase pointed at Ava for our tests. To set options for the test we use environment variables. These can be set through export or on the command line. A testContext object is created in the beforeTest step. Read the code in test-context.js to understand the possibilities for environment variables. ENVIRONMENT is currently the only required variable. ENVIRONMENT=PROD is the only valid setting, the other values are examples.
Here are some valid options. See Ava doc for test running options. NO_SANDBOX=true must be set when running in Docker :sadface:
ENVIRONMENT=PROD NO_SANDBOX=true yarn test
// run all the testsENVIRONMENT=PROD NO_SANDBOX=true yarn test -m unit:*
// just the unit - test (filtering on name)ENVIRONMENT=PROD NO_SANDBOX=true yarn test -m input*
// just run the input test (filtering on name)ENVIRONMENT=PROD NO_SANDBOX=true yarn test -m navigate*
// just run the navigate tests (filtering on name)
use if you watch to watch locally
HEADLESS=false
- use homebrew or nvm to install node
brew install node
- use homebrew or yarn's instructions to install yarn
brew install yarn
- clone this repo with git
- locally install the project dependencies in the base directory
yarn install