test(e2e): fail tests when ZodError appears in browser console#1894
Draft
jeffredodd wants to merge 1 commit into
Draft
test(e2e): fail tests when ZodError appears in browser console#1894jeffredodd wants to merge 1 commit into
jeffredodd wants to merge 1 commit into
Conversation
Watch the browser console and pageerror events in the shared page fixture for 'ZodError' strings. @gusto/embedded-api validates every response with Zod, so when the backend ships a shape that disagrees with the published schema the request rejects and surfaces in the console — either as an uncaught page error or via React's error-boundary console.error. Previously tests could pass while the SDK was silently crashing into an error boundary mid-flow because the harness never asserted on console output. Now the fixture collects any ZodError text observed during the test, attaches it as zod-errors.txt for the HTML report, and fails the test (only when it would otherwise pass — existing failures are preserved).
29406e9 to
2f4a319
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Today an e2e shard can pass green while the SDK is silently crashing into an error boundary mid-flow. The most common cause is a
ZodErrorthrown out of@gusto/embedded-api's response parsing — the API client validates every response against the published Zod schema, and when the backend ships a shape the schema disagrees with, the parse throws and React catches it at the nearest error boundary. Example of what this looks like in the browser console:When this happens the SDK renders an error boundary instead of the expected screen, but unless the test happens to assert on something that's now missing it passes anyway. We want the shard to fail loudly so we catch schema drift between
zenpayroll/gws-flowsand the published@gusto/embedded-apiZod schemas.Changes
pagefixture (e2e/utils/localTestFixture.ts), subscribe to theconsoleandpageerrorevents for every test.ZodError(covers both uncaught throws and React's error-boundaryconsole.errorlogs).zod-errors.txton the Playwright report so the HTML report / artifacts show exactly what was logged.This fixture wraps every test in every config (
playwright.config.ts,playwright.demo.config.ts,playwright.local.config.ts), so the check is on by default for MSW-mode runs, demo runs, and local-backend runs.Testing
npm run test:scenarios— passes (scenario module tests).npx tsc --noEmit ... e2e/utils/localTestFixture.ts— passes.npx prettier --check e2e/utils/localTestFixture.ts— passes.await use(page)returns, so it sees console output for the entire test lifetime, including renders triggered bypage.gotoand any subsequent interactions. If aZodErrorshows up at any point the test fails with a message that includes the full captured text plus azod-errors.txtattachment.Related