HP9010 (unexpected-redirect) means the route ended on a different URL than
the one requested, or than its expectRedirect. The page that was tested is
the one it landed on. When a signed-in scenario lands on the login page, its
login did not work. Otherwise, set expectRedirect or limit the route to the
scenarios that can open it.
| Code | HP9010 |
|---|---|
| Name | unexpected-redirect |
| Default severity | Warning |
| Group | Test run problems |
| What it means | The route ended on a different URL than requested (or than expectRedirect). A signed-in scenario that lands on a login page usually means its login did not work. |
What the HP9010 unexpected redirect finding means
hydration-proof compares the path it requested with the path the page ended on, after every redirect:
/account redirected to /login; the page that was tested is /login.
/old-pricing should redirect to /pricing but ended on /.Without expectRedirect, any redirect is a warning. With expectRedirect, a
redirect to another path is an error, because the route is known to go
somewhere else.
Likely causes
- A signed-in page tested in a scenario that is not signed in, or whose sign-in did not leave a working session.
- A route that redirects on purpose: an old URL, a locale prefix, a trailing slash rule.
- Middleware that redirects the test browser, for example by locale or country.
How to fix it
If the redirect is intended, set expectRedirect on the route, or limit the
route to the scenarios that can open it (scenario include/exclude). For
signed-in scenarios, check the login step or the storage state file.
A redirect that is intended
import { defineConfig } from "hydration-proof";
export default defineConfig({
routes: {
paths: ["/", { path: "/old-pricing", expectRedirect: "/pricing" }],
},
scenarios: [
{ name: "guest", exclude: ["/account/**"] },
{
name: "customer",
include: ["/account/**"],
storageState: "auth/customer.json",
},
],
});A login that did not work
- Watch the login with the browser visible and one worker (the command is below).
- Make the
loginfunction wait for the page after signing in, for example withpage.waitForURL("**/account"), so the session cookie is set before the pages are tested. - Check that the session cookie is not limited to another domain than the tested app.
- With
storageState, record the file again: sessions in it expire.
npx hydration-proof test --scenario customer --headed --workers 1A login that throws stops the run with exit code 2; HP9010 means it finished
but left no working session. Scenarios and sign-in has a
full example.