-
Notifications
You must be signed in to change notification settings - Fork 48
Writing and running tests
Excluding linters and other small tests, there are three categories of tests:
- node unit tests
- browser unit tests
- tests using mocked Google apis
- tests using live Google apis, login, and mail.google.com (You need a
test-secrets.json
file that you may get after signing an NDA which goes in the flowcrypt-browser/test directory)
When a change to a class was made that is very specific, a unit test may be appropriate. When behavior of the extension was changed that involves the UI, then use mock test.
Before you run any tests, add this in your hosts file:
127.0.0.1 fes.google.mock.flowcryptlocal.test
127.0.0.1 google.mock.flowcryptlocal.test
127.0.0.1 fes.standardsubdomainfes.test
127.0.0.1 standardsubdomainfes.test
Don't try to run all tests at once locally. Instead choose a particular test: find the test that you're interested in, and switch ava.default(
to ava.default.only(
on that test. Then only that test will run with the command below. Just don't commit the "only" into git.
To run test, you press F2 in vscode and choose "npm: test_local_chrome_consumer_mock". (or run npm run-script test_local_chrome_consumer_mock
)
Resources: https://github.com/avajs/ava https://github.com/puppeteer/puppeteer
In the html code you'll see data-test="action-something"
type of tags. These are identifiers for testing, so that tests keep working even if we change markup or ids/classes. Basically all test ids should start with "action", "container" or "input" (convention).
Tags identified this way are then used from test code with a @. Like:
await composePage.click('@input-body');
Don't forget your awaits in the tests (everything involving the browser is async). If you find yourself using puppeteer API directly, you are almost certainly doing something that we already have a convenience method for somewhere, probably in ControllableBase
, ControllablePage
, or BrowserHandle
.