fix(astro): run the e2e dev server in the foreground - #814
Open
maoberlehner wants to merge 3 commits into
Open
maoberlehner wants to merge 3 commits into
maoberlehner wants to merge 3 commits into
Conversation
`astro dev` daemonizes when it detects an agentic environment: it forks the server, prints the pid and exits. `start-server-and-test` reads its child exiting as the server dying and aborts with "server closed unexpectedly", so the suite failed for anyone running it from a coding agent while passing in CI. Setting `ASTRO_DEV_BACKGROUND` suppresses the auto-detection, which is what the new `playground:test:foreground` script exists to do. Reaching Cypress at all then exposed a second failure. The Astro dev toolbar is loaded through a dynamic import, and when Vite re-optimizes dependencies the already-served module still points at the previous optimized file name, so the import rejects and Cypress fails the run on the unhandled rejection. It is a race, so clearing the dependency cache between runs does not settle it. The toolbar is dev-only and no spec covers it, so the test playground turns it off. Five consecutive runs pass and leave no dev server behind; before this the suite never got past starting the server. Fixes DX-582
Gating the toolbar on `STORYBLOK_E2E` rather than switching it off outright, so running the test playground by hand still gets it.
@storyblok/angular
@storyblok/astro
@storyblok/api-client
storyblok
@storyblok/experiments
@storyblok/js
storyblok-js-client
@storyblok/lint-config
@storyblok/live-preview
@storyblok/management-api-client
@storyblok/migrations
@storyblok/nuxt
@storyblok/react
@storyblok/region-helper
@storyblok/richtext
@storyblok/schema
@storyblok/svelte
@storyblok/vue
commit: |
maoberlehner
requested review from
alexjoverm and
dipankarmaikap
and removed request for
alexjoverm
September 17, 2026 11:28
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.
The Astro end-to-end suite has been failing locally while passing in CI. It is
not a flake in the usual sense: there are two separate defects, and the first
one hid the second.
The dev server was never actually running
astro devdaemonizes when it detects an agentic environment — it forks theserver, prints
Dev server running at http://localhost:4321 (pid N), and theforeground process exits 0.
start-server-and-testtreats its child exiting asthe server dying and aborts with
server closed unexpectedlybefore Cypressever starts.
That is why the failure looked environmental: CI runs no agent, so there the
server stays in the foreground and the suite passes. Anyone driving the repo
from a coding agent gets a deterministic failure instead, which is how this got
recorded as a pre-existing failure on
mainin #807.ASTRO_DEV_BACKGROUNDsuppresses the auto-detection, so the e2e target nowstarts the playground through a
playground:test:foregroundscript. The namereads backwards on purpose: any non-empty value tells Astro the background
decision has already been made, so it skips detection and stays in the
foreground.
docs/testing-patterns.mdrecords this, because the next person tohit it will be looking at
server closed unexpectedlywith no obvious link tothe dev server forking.
The plain
playground:testscript is untouched, so running the playground byhand from an agent still gets the background server and
astro dev logs.The dev toolbar loses a race against dependency optimization
With the server actually up, Cypress ran and the first spec failed:
The dev toolbar is pulled in through a dynamic import. When Vite re-optimizes
dependencies, the module that was already served still points at the previous
optimized file name, so the import rejects and Cypress fails the test on the
unhandled rejection. Clearing the dependency cache between runs does not settle
it — three consecutive clean-cache runs went pass, pass, fail — because it is a
race, not a stale-cache artifact.
In a browser this is invisible: Vite reloads the page. It is only fatal under
Cypress, which fails a test on any unhandled rejection from the application. So
this is a harness artifact rather than a product defect, and the fix is to take
the toolbar out of a suite that never tested it. The test playground gates it on
STORYBLOK_E2E, which only the e2e script sets, so running the playground byhand still gets the toolbar. No spec covers it before or after this change.
Verification
Five consecutive
test:e2eruns pass with all five specs, and leave no devserver behind on ports 4321-4325.
pnpm nx test @storyblok/astropasses twicein a row with the cache skipped. Before this, the suite never got past starting
the server.
Fixes DX-582