Files
Elisha Nuchi 89c12fa161 Set up end to end tests (#121)
* initial e2e test setup with jest and puppeteer

* Update package-lock.json

* WIP e2e setup

* finish setting up end to end tests

* extend open addon time

* build local version and change background color

* update pink image snapshot

* hide no "done" callback jest lint error

* first draft of integration test CI automation

* add .env file during CI

* add puppeteer and update .env

* try mac-os

* try separate build step

* add local deploy step

* extend time

* print body text

* set user agent

* rearrange console logs

* remove console logs

* console page

* try loading in own window

* install mkcert in CI

* fix indentation

* test local body text

* bump time

* revert to loading in add on

* bump time

* print page body

* add stealth plugin and update puppeteer

* update jest and jest-puppeteer versions to latest

* use custom jest-puppeteer environment

allows connecting to Google account using stealth plugin

* update threshold

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* test console

* switch to clasp 2.3.1

* increase timeout

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update package.json

* try mac os 10.15

* Update integration-tests.yaml

* run node 12,14

* Update global-teardown.js

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* sudo mkcert

* Update integration-tests.yaml

* try running not in bash

* try windows 2016

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update open-addon.js

* Update open-addon.js

* Update open-addon.js

* Update open-addon.js

* Update open-addon.js

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* add timeout

* test recovery email

* bypass account recovery page

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* test New-SelfSignedCertificate

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* add powershell script

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* Update integration-tests.yaml

* test script

* Update integration-tests.yaml

* add generate-cert.ps1

* restructure test files

* Update generate-cert.ps1

* bump failure threshold

* fix install mkcert

* remove consoles

* Update package.json

* Update integration-tests.yaml

* try forceExit flag

* test exec in global setup

* restructure

* Update integration-tests.yaml

* remove ?. null check

* add 4 OSs: macos-10.15, macos-latest, windows-2019, windows-latest

* test mac 10.15

* Update integration-tests.yaml

* use all OSs

* -Keyexportpolicy Exportable

* Update generate-cert.ps1

* Update integration-tests.yaml

* update os

* -KeyExportPolicy 'Exportable'

* Update integration-tests.yaml

* update test readme

* Update integration-tests.yaml

* add non-extended integration test

* add non-extended snapshots

* update snapshot names

* change name

* add basic integration tests pipeline file

* Update local-development.test.js

* update os's

* test s3 image reporter

* allowSizeMismatch: true

* update test local url to localhost:3000/dialog-demo-bootstrap.html

* try medium font render hinting

* Update jest-puppeteer.config.js

* update screenshots

* check resolution

* open page when wds is ready

* change screen resolution

* change to 2560 1440 resolution

* test 790 width

* change back to 800

* test all mac versions

* rename container

* skip s3 image reporting if missing env variables

* try windows

* add OS specific tests

* fix image names

* Update image-reporter.js

* Update package.json

* upload windows

* Update image-reporter.js

* test new font

* try all OSs

* remove OS-specific test setup

* update extended snapshots

* rename tests

* Update integration-tests-extended.yaml

* Update integration-tests-basic.yaml

* extend timeout

* Update jest.config.js

* Update README.md

* Update local-development.test.js

* revert to 0.04 threshold

* add comment

* remove push trigger for basic test

* extend timeout
2022-03-12 22:51:30 -05:00

4.3 KiB

Running tests

Integration tests here are used to ensure the existing local development setup works across different platforms, and that new features do not break the functionality of the local development environment.

The "extended" local development integration test builds and deploys the local development setup needed to use hot reload functionality. It deploys the local setup to a spreadsheet inside a test Google account, runs a local development server, and checks that changes to the local files are reflected inside the spreadsheet's add-on, similar to how local development is intended to be used.

Jest is used to run the tests and compare images of the changes, and Puppeteer is used to control the browser. A test account and test spreadsheet need to be created and credentials need to be passed in through environment variables in order for this "extended" version to work. Example .env file variables are listed below. Since secret values cannot be used in PRs opened from forks, a "basic" integration test just loads the local development setup locally, instead of deploying to Google Sheets.

Extended integration test

In order to test the extended integration test locally you will need to create or use a test Google account. It's recommended you create an account solely for this purpose rather than using an existing account. You'll need to create a new project and include the following variables in the .env file in the root:

SHEET_URL = https://docs.google.com/spreadsheets/d/****************/edit#gid=0
EMAIL = myisolatedtestaccount@gmail.com
PASSWORD = testaccountpassword
TEST_RECOVERY_EMAIL = myisolatedtestaccountsrecoveryemail@gmail.com

# For image reporting only
S3_BUCKET_NAME = my-bucket-name
AWS_ACCESS_KEY_ID = A35D************
AWS_SECRET_ACCESS_KEY = slkf***********/234jdh**********

Make sure that you have followed the instructions to install local certs (see main README). The test will use Puppeteer to open the spreadsheet URL and log in to your account using your email and password provided. In case it doesn't recognize you it will ask for this account's recovery email -- you'll need to include this in the .env file as well.

Running the extended tests in the pipeline

To run the extended integration test in a pipeline using Github Actions, reference the .github/workflows directory. You'll need to add some additional environment variables through the repo secrets settings in order to get the full flow working:

DOT_CLASPRC - the .clasprs.json file from user directory containing clasp login credentials DOT_CLASP - the .clasp.json file from this repo matching the test spreadsheet TEST_ACCOUNT_EMAIL, TEST_RECOVERY_EMAIL, TEST_ACCOUNT_PASSWORD, TEST_SPREADSHEET_URL - see above variables

Additional notes

Stealth login

puppeteer-extra and puppeteer-extra-plugin-stealth are used to help log in to a Google account in the pipeline for the "extended" integration test. They are not easily compatible with the jest-puppeteer package, so a custom integration is used that is documented on jest's site here.

Generating certs in the pipeline

There are permissions issues running mkcert -install in Windows runners, so a powershell script in ./generate-cert.ps1 is used to generate the certs and enable https.

Jest open handles

There are issues with jest keeping handles open after all tests finish on Windows runners, so jest --forceExit is used to resolve them, although this flag may not be needed on certain platforms (like Mac OS).

Jest Image Snapshots

jest-image-snapshot is used to compare browser snapshots and detect discrepancies or regressions. Thresholds have been adjusted to allow for some variation across different platforms due to differences in font rendering and color profiles.

If a snapshot fails, a diff image is created in the diff_output directory, showing the comparison. If it fails in the pipeline it may be hard to see this diff. An Image Reporter class is used to upload diff images to an S3 bucket from the pipeline. This can be modified to use any image store. If used, make sure it is enabled in jest.config.js and that the necessary environment variables (AWS keys, bucket name, etc.) are added to .env file (see above section).