The tests expects to find the below env variables. Either define it in your shell, or add it to the .env.local
file in the repository root.
SANITY_E2E_SESSION_TOKEN
: Before you get started with writing and running tests, you need to get hold of a token - either using your own Sanity user token (sanity debug --secrets
will give you the CLI token provided you are logged insanity login
), or by creating a project API token using https://sanity.io/manage.SANITY_E2E_PROJECT_ID
: Project ID of the studioSANITY_E2E_DATASET
: Dataset name of the studio
To run E2E tests run the following commands from the root of the project
-
Run all the tests
pnpm test:e2e
-
Run all tests in specific directory, it runs relative to the
test/e2e/tests
pnpm test:e2e tests/default-layout
-
Run files that have my-spec or my-spec-2 in the file name
pnpm test:e2e my-spec my-spec-2
-
For help, run
pnpm test:e2e --help
Other useful helper commands
- "e2e:dev": Starts the E2E studio using
sanity dev
- "e2e:build": Runs
sanity build
on E2E studio - "e2e:codegen": Runs playwright codegen. Note: Requires the studio to be running. Run
pnpm e2e:dev
in another terminal first - "e2e:start": Runs
sanity preview
on E2E studio (preview server, requires a build) - "e2e:preview": Runs
sanity build
, thensanity preview
on E2E studio
For more useful commands, see the Playwright Command Line documentation.
You can run your tests in your editor with the help of some useful editor plugins/extensions. For example, you can download Playwright Test for VSCode
from Microsoft to show and run your tests in VSCode.