Skip to content

Testing

Erin Hoops edited this page Jul 24, 2024 · 5 revisions

E2E tests

We are using playwright for end to end testing.

To run all e2e tests

cd packages/data-portal
pnpm run e2e

To run e2e tests in a specific file

$ cd packages/data-portal
$ npx playwright test e2e/metadataDrawer.test.ts

Test file structure

- newFeature.test.ts
- pageObjects
  - newFeature
    - newFeaturePage.ts
    - newFeatureActor.ts (optional)
    - types.ts
    - utils.ts

newFeature.test.ts - this is where the test cases live. Each test should be easy to read.

pageObjects - this directory contains all of the helpers related to each set of tests.

newFeaturePage.ts - this is a page object that contains all of the steps of a test that interact with the page.

newFeatureActor.ts (optional) - this file contains helper functions that have multiple steps. These steps can include both interactions with the page, using methods from newFeaturePage.ts, and data fetching, using functions from utils.ts. Adding this layer allows the tests to stay readable. It removes duplication that is not relevant for someone reading the test file.

types.ts - test-specific types

utils.ts - contains helpers that are not specific to interacting with the page. For example, for fetching data.

Using hygen to create a new test suite

We have a template defined with hygen. Templates live in any _templates directory. Feel free to add more templates.

To use

$ brew tap jondot/tap
$ brew install hygen

To generate a new test suite in our project:

$ hygen e2e new testSuiteName
Clone this wiki locally