Source: https://everyrole.dev/blog/e2e-tests-preview-deployments

# Run E2E tests on every preview deployment

To run E2E tests on preview deployments, wait for the deploy, take its address and run your journeys there. Five traps, and what a preview can’t prove.

Nov 22, 2026  6 min read  by the EveryRole team

To run E2E tests on preview deployments you need three things: a signal that the preview is ready, its address, and tests that take their address from a variable. When the host says the deploy succeeded, a job runs your journeys against that address and reports on the pull request.

The set-up is the easy part. What takes longer is learning the five ways a preview differs from the app your users see, and remembering that a green preview says nothing about production’s settings.

![What a preview deployment can tell you (does this change break a journey, do the data-changing tests pass) and what only production can (live settings, real data, outside services)](https://everyrole.dev/s/blog/e2e-tests-preview-deployments/preview-production.webp)

A preview tests the code. Production tests the code plus everything around it.

## The set-up: run tests against the preview deployment

Hosts that build a preview per pull request usually tell your repository when it is ready, as a deployment status with the preview’s address in it. In [GitHub Actions](https://everyrole.dev/blog/e2e-tests-in-ci) that event starts a workflow:

![Four steps from a push to a result: a branch is pushed, the host says the preview is ready and gives its address, the journeys run on that address, and the result lands on the pull request](https://everyrole.dev/s/blog/e2e-tests-preview-deployments/the-loop.webp)

The tests start at step 2. Start them at step 1 and they race the build.

```
on: deployment_status

jobs:
  e2e:
    if: github.event.deployment_status.state == 'success'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run test:e2e
        env:
          BASE_URL: ${{ github.event.deployment_status.environment_url }}
```

Two details make or break this.

**The tests read `BASE_URL`.** Every address in the suite is built from it. A single hard-coded production address in one test means that test silently checks production while the others check the preview, and it passes for the wrong reason.

**Trigger on the deploy, not on the push.** If the tests start when the code is pushed, they race the build. Either they run against the previous preview or they fail because nothing is there yet. If your host gives no ready signal, poll the address until it answers before you start.

## Five things that trip preview environment testing

**1. The preview is behind a wall.** Many hosts protect previews with a password or a team sign-in. Your tests then meet the host’s login page on every address and fail, or worse, pass a “the page loads” check against the wall. Hosts that protect previews offer a way through for automation, usually a secret header or token. Use it, and add one check that the page you opened is your app.

**2. Which database?** This decides what you can test. If every preview shares one staging database, two pull requests’ tests run against the same rows, and a migration in one branch breaks the other. If each preview gets a fresh database, it is empty: no test accounts, nothing in any list. Either way, decide it on purpose. We’d take a fresh database with a small seed script that creates one account per kind of user.

**3. Test accounts.** The logins your tests use have to exist where the preview looks. On a fresh database, the seed makes them. On a shared one, they exist already and every test has to [clean up what it made](https://everyrole.dev/blog/test-data-cleanup), or the next run finds leftovers. Either way they are [accounts made for testing](https://everyrole.dev/blog/test-accounts-for-each-role), one per kind of user.

**4. Outside services only know your real address.** Sign-in through another service usually allows a fixed list of return addresses, and a preview’s address changes with every branch. Payment callbacks and email links point wherever your settings say, often production. On a preview, expect these journeys to need a workaround (a stable alias for the preview, a test mode, an email-and-password login for tests) or to be left for staging.

**5. It is ready before it is warm.** The first request to a fresh preview can be slow: cold functions, an empty cache. A test with a tight timeout fails on its first page and passes when run again. Open one page and wait for it before the first test, so that a slow start isn’t reported as a broken journey. Retrying until it passes hides this, along with [real bugs](https://everyrole.dev/blog/flaky-tests).

## Which E2E tests to run on preview deployments

All of them that touch what the pull request can break, and especially the ones you [can’t run on production](https://everyrole.dev/blog/testing-in-production).

A preview is the right place for tests that change data: [create, edit and delete](https://everyrole.dev/blog/crud-test-cases) for real, upload files, go through sign-up with a new account. On a fresh database nothing they do can hurt. It is also where you can [test the checkout](https://everyrole.dev/blog/test-checkout-without-paying) one step further than on the live site, with the provider’s test keys and a test card.

Keep the run short enough that people wait for it. If the suite takes long, run the journeys the change touches first and the rest after. A check that arrives after the merge button was pressed protects nobody.

## What a preview can’t tell you

A preview runs your new code with preview settings on preview data. Production differs in exactly the places where release-day bugs live:

- **Settings.** Environment variables, keys, product ids, feature switches. A preview can be perfect while production points at last year’s key.
- **Data.** A migration that takes a blink on a seed database and minutes on the real table. A list page that is fine with three rows and times out with years of them.
- **The outside.** The real domain, its certificate and cache, scheduled jobs, callbacks from other services.
- **The other kinds of user.** If the seed has only an admin, the preview never shows what a viewer sees.

So the preview check doesn’t replace a check after the production deploy. It moves failures earlier, to where they cost a comment on a pull request. The production run is smaller: the same journeys, without the tests that change data, on the address your users use. Each journey should still end on a real result. A production check that only confirms pages load is how you get [tests that pass while the app is broken](https://everyrole.dev/blog/hollow-passes).

## How EveryRole runs on a preview

EveryRole tests an app [from the outside](https://everyrole.dev/blog/black-box-vs-white-box-testing), so a preview is just another address. Each app can have a deploy hook: a secret link your pipeline calls when a deploy finishes. Its body can carry `base_url`, to test that address instead of the app’s own, and an `environment` (preview, staging or production). The commit and branch you send are shown with the run, so the result names the deploy it tested. The [docs on deploy hooks](https://everyrole.dev/docs#deploy-hooks) have the snippets.

The environment matters for safety. Tests that really change data are added by name and run only in the environments you allowed for them, so they can run on previews and stay off production. A never-click word is refused everywhere.

If you’d rather not hand over test logins, the same tests can run [in your own CI](https://everyrole.dev/docs#ci): the job reads `BASE_URL`, and each login stays in your pipeline’s masked variables.

One thing it does the way we’d advise anyone to: two previews are treated as two different apps. A test that fails on one branch’s preview says nothing about another’s.

## Try it on your own app

EveryRole tests your app’s real user journeys for each kind of user, from the live site, and runs them after every deploy. Paste your app’s address to see what it finds.

[Start with your app](https://everyrole.dev/signup) [How it works](https://everyrole.dev/docs#start)

## Keep reading

Deploys and CI

### [E2E tests in CI without slowing every merge](https://everyrole.dev/blog/e2e-tests-in-ci)

Run E2E tests in CI as two sets. A few journeys block the merge, the full suite reports after it. How to choose the blocking set and keep it quick.

Nov 22, 2026  6 min read

Deploys and CI

### [How to test a vibe-coded app before users do](https://everyrole.dev/blog/test-vibe-coded-app)

How to test a vibe-coded app: from the outside, as each kind of user, on the running app. The agent says what changed, and something else has to prove it works.

Nov 22, 2026  7 min read

Deploys and CI

### [Run tests after every deploy, not every night](https://everyrole.dev/blog/run-tests-after-deploy)

Post-deployment testing: the deploy starts the tests on the live address, and the result names that deploy. The set-up, and what a nightly run is still for.

Nov 22, 2026  5 min read
