hydrogen / e2e
CLAUDE.md2.1k starsChanged 8 months agoMITView on GitHub
❌ page.waitForTimeout(1000) - Arbitrary waits (flaky) ❌ page.waitForLoadState('networkidle') - Unreliable ❌ page.waitForResponse(...) - Implementation detail ❌ page.locator('.css-class') - Fragile selectors ❌ Adding test IDs when accessibility markup would work ❌ Hardcoding dynamic store data names (e.g., collection titles from sortKey: UPDATED_AT queries) When testing homepage sections that query dynamic store data (e.g., "most recently updated collection"), assert structure rather than specific names: Only assert specific entity names when navigating to a known entity by handle (a stable identifier), e.g., /products/${KNOWN_PRODUCT.handle}.
Trending
Quiet since June.about the whole repository
Who's talking about Shopify/hydrogen
- Shopify/hydrogen-demo-store“Remix to react-router and other dep upgrades”GitHub · Nov 24, 2025 · 8 reactions
- Shopify/hydrogen-v1“CartProvider V2 ”GitHub · Aug 5, 2022 · 6 reactions
- BuilderIO/builder-shopify-hydrogen“Cannot use the builder/react sdk in the new version of shopify-hydrogen using Remix”GitHub · Feb 14, 2023 · 5 reactions
- vitejs/vite“Use ESM for SSR builds”GitHub · May 12, 2022 · 4 reactions
- Shopify/hydrogen-v1“Move cart queries to an API endpoint”GitHub · Apr 5, 2022 · 4 reactions
The biggest 5 of 29 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 29
Talked about on GitHub and Bluesky (29 times).
On GitHub · 28
- Nov 24, 2025Remix to react-router and other dep upgrades — Shopify/hydrogen-demo-store8 reactions · 1 comment
- Aug 5, 2022CartProvider V2 — Shopify/hydrogen-v16 reactions · 15 comments
- Feb 14, 2023Cannot use the builder/react sdk in the new version of shopify-hydrogen using Remix — BuilderIO/builder-shopify-hydrogen5 reactions · 11 comments
- May 12, 2022Use ESM for SSR builds — vitejs/vite4 reactions · 3 comments
- Apr 5, 2022Move cart queries to an API endpoint — Shopify/hydrogen-v14 reactions · 9 comments
23 more on GitHub
- Mar 30, 2022Introduce Link prefetch behavior — Shopify/hydrogen-v14 reactions
- Dec 7, 2021Default preloading queries — Shopify/hydrogen-v14 reactions · 5 comments
- Jun 30, 2023Adds Hydrogen 2.0 (via Remix) Adapter — netlify/remix-compute3 reactions · 16 comments
- Apr 27, 2023createWithCache_unstable not working on Oxygen — sanity-io/hydrogen-sanity-demo3 reactions · 5 comments
- Oct 24, 2022[BUG] Environment variables in `hydrogen.config.ts` don't work with `npm run preview` — Shopify/hydrogen-v13 reactions
- Sep 1, 2022Cloudflare adapter disables known cloudflare worker "compatible" dependencies — solidjs/solid-start3 reactions · 24 comments
- May 19, 2022Consider implementing Link prefetching for mobile — Shopify/hydrogen-v13 reactions · 3 comments
- May 18, 2022Bug [Flight]: Hydration fails when suspended components introduce new client components — react/react3 reactions · 4 comments
- Apr 20, 2022[Hydrogen docs]: Content fixes in source files — Shopify/hydrogen-v13 reactions · 1 comment
- Mar 28, 2022Do not cache GraphQL errors — Shopify/hydrogen-v13 reactions · 2 comments
- Feb 8, 2022Standardize `data` prop across components — Shopify/hydrogen-v13 reactions · 2 comments
- Jan 18, 2022Improvements to API Routing — Shopify/hydrogen-v13 reactions · 2 comments
- Jun 4, 2026chore(deps): bump turbo-stream and @shopify/hydrogen in /packages/tokpulse-hydrogen — Hardonian/TokPulse2 reactions · 5 comments
- Feb 7, 2023[BUG] CartLineQuantityAdjustButton clears lineItem attributes — Shopify/hydrogen-react2 reactions · 5 comments
- Nov 14, 2022Fix preload cache ballooning — Shopify/hydrogen-v12 reactions · 5 comments
- Aug 17, 2022Expose the private token and storefrontId within Hydrogen config — Shopify/hydrogen-v12 reactions · 7 comments
- Jul 14, 2022Improve CSS support in server components — Shopify/hydrogen-v12 reactions · 8 comments
- Jul 12, 2022HMR in server components — Shopify/hydrogen-v12 reactions · 1 comment
- Jul 11, 2022Add assets proxy in Oxygen — Shopify/hydrogen-v12 reactions · 1 comment
- Jun 14, 2022Upgrade to React v18.2 — Shopify/hydrogen-v12 reactions · 2 comments
- May 23, 2022Replace `graphql-tag` with internal `gql` utility — Shopify/hydrogen-v12 reactions · 4 comments
- Mar 10, 2022Support mutations & refreshing RSC responses from API endpoints — Shopify/hydrogen-v12 reactions · 2 comments
- Dec 31, 2021React Server Components — vikejs/vike2 reactions · 7 comments
On Bluesky · 1
- Sep 13, 2025If I need to build a storefront, I'd probably check out Medusa [1] or Shopify Hydrogen [2]. Otherwise, probably Elixir/Phoenix and LiveView… — @nezteb.net3 likes and reposts
In this repository9 other files it gives its agents.
- templates/skeleton/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- cookbook/CLAUDE.mdCLAUDE.md
- templates/skeleton/CLAUDE.mdCLAUDE.md
- templates/skeleton/.cursor/rules/hydrogen-react-router.mdcCursor rule
- e2e-test-writingSkill
- hydrogen-dev-workflowSkill
- hydrogen-release-processSkill
- hydrogen-versioningSkill
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
14 rules. About 0 are common, 13 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈13
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 7
Use role-based locators: - Never CSS classes unless absolutely necessary
- Distinctive: line 9
Never use timeouts or networkidle: - Wait for visible effects only
- Distinctive: line 11
Wait for user-visible changes: - Not implementation details like network requests
- Distinctive: line 24
When testing homepage sections that query dynamic store data (e.g., "most recently updated collection"), assert structure rather than …
- Very specific: line 39
Only assert specific entity names when navigating to a known entity by handle (a stable identifier), e.g., …
- Distinctive: line 46
Exception: If you need to clear state within a single test (e.g., testing empty cart after clearing), do so explicitly in that test.
- Distinctive: line 92
Always choose selectors based on DOM elements and semantic structure, NOT CSS classes or styles.
- Distinctive: line 102
Always try role-based selectors first: Only use CSS classes when:
- Distinctive: line 110
Writing tests should drive better markup: When you can't write a good locator, that's often a signal of missing accessibility features.
- Distinctive: line 152
Test both presence and absence to ensure complete validation of state.
- Distinctive: line 171
Key Pattern: After removing an item, assert both:
- Distinctive: line 198
Wait for the actual data change the user sees, not intermediate states or implementation details.
- Distinctive: line 233
Wait for the visible effect rather than the underlying mechanism:
- Distinctive: line 265
If you need to debug visually, use Playwright's trace viewer or UI mode temporarily, but never commit headed configuration.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
E2E Testing Guidelines
Quick Reference
The Golden Rules
- Use role-based locators - Never CSS classes unless absolutely necessary
- Assert absence broadly, presence specifically - Wide net for "not there", scoped for "is there"
- Never use timeouts or networkidle - Wait for visible effects only
- Improve accessibility while testing - Tests drive better markup
- Wait for user-visible changes - Not implementation details like network requests
Anti-Patterns to Avoid
❌ page.waitForTimeout(1000) - Arbitrary waits (flaky)
❌ page.waitForLoadState('networkidle') - Unreliable
❌ page.waitForResponse(...) - Implementation detail
❌ page.locator('.css-class') - Fragile selectors
❌ Adding test IDs when accessibility markup would work
❌ Hardcoding dynamic store data names (e.g., collection titles from sortKey: UPDATED_AT queries)
Dynamic Store Data
When testing homepage sections that query dynamic store data (e.g., "most recently updated collection"), assert structure rather than specific names:
// GOOD: Assert that a featured collection heading exists (any h1)
const featuredCollectionHeading = page.getByRole('heading', {level: 1});
await expect(featuredCollectionHeading).toBeVisible();
// AVOID: Hardcoding a collection name that depends on store state
const featuredCollectionHeading = page.getByRole('heading', {
level: 1,
name: 'Winter Collection', // ❌ Breaks when a different collection is most recently updated
});Only assert specific entity names when navigating to a known entity by handle (a stable identifier),
e.g., /products/${KNOWN_PRODUCT.handle}.
Test Isolation
Playwright automatically provides test isolation - each test runs in its own browser context with isolated storage, cookies, and state. You generally don't need to manually clear cookies or storage between tests.
Exception: If you need to clear state within a single test (e.g., testing empty cart after clearing), do so explicitly in that test.
Test Organization
Test Setup Strategy
Per Playwright best practices: Use beforeEach hooks to eliminate repetitive setup steps while maintaining test isolation.
// GOOD: Use beforeEach for shared setup
test.describe('Quantity Management', () => {
test.beforeEach(async ({storefront}) => {
await storefront.goto('/');
await storefront.navigateToInStockProduct();
await storefront.addToCart();
});
test('increases quantity', async ({storefront}) => {
const firstItem = storefront.getCartLineItemByIndex(0);
await storefront.increaseLineItemQuantity(firstItem);
expect(await storefront.getLineItemQuantity(firstItem)).toBe(2);
});
});
// ACCEPTABLE: Duplicate simple 1-2 line setups when it improves clarity
test('adds item to empty cart', async ({storefront}) => {
await storefront.goto('/');
await storefront.navigateToInStockProduct();
await storefront.addToCart();
await expect(storefront.getCartLineItems()).toHaveCount(1);
});
// AVOID: Repeating 3+ lines in every test
test('increases quantity', async ({storefront}) => {
await storefront.goto('/'); // Repeated
await storefront.navigateToInStockProduct(); // Repeated
await storefront.addToCart(); // Repeated
// Use beforeEach instead
});Selector Strategy
DOM Elements over CSS
Always choose selectors based on DOM elements and semantic structure, NOT CSS classes or styles. Tests should reflect how a user perceives and interacts with the page.
Priority order for selectors:
- Role + accessible name (preferred):
getByRole('button', {name: 'Add to cart'}) - Role + landmark:
getByRole('banner').getByRole('link', {name: /cart/i}) - Text content:
getByText('Continue to Checkout') - Test IDs (when semantic selectors aren't possible):
getByTestId('cart-drawer') - CSS classes (last resort only): Only when semantic selectors are impractical
Always try role-based selectors first. Only use CSS classes when:
- The element has no semantic role
- Multiple similar elements need disambiguation
- Role-based selectors would be overly complex
Accessibility Improvements During Test Writing
Writing tests should drive better markup. When you can't write a good locator, that's often a signal of missing accessibility features.
It is encouraged and expected to improve accessibility in the application code when:
- It enables better test locators (role-based instead of test IDs or CSS)
- It provides genuine accessibility benefits for users
- The change is semantically correct
// BEFORE: Missing ARIA label, forced to use CSS
getCartTotals() {
return this.page.locator('div.cart-summary'); // Fragile
}
// AFTER: Add aria-label to markup, use role-based locator
// In application code:
<div role="region" aria-label="Totals">
<dl>...</dl>
</div>
// In test:
getCartTotals() {
return this.page.getByLabel('Totals'); // Resilient + accessible
}Examples of acceptable accessibility improvements:
- Adding
aria-labelor preferablyaria-labelledbyto landmark regions for disambiguation - Adding
aria-labelledbyto associate labels with controls - Adding accessible names to native elements without overriding their roles (e.g.,
<ul aria-label="Line items">or preferably<ul aria-labelledby="line-items-heading">) - Adding accessible names to buttons (e.g.,
aria-label="Remove gift card ending in 1234")
Not acceptable:
- Adding
aria-labelpurely for test purposes when it provides no user benefit - Over-labeling elements that are already accessible
- Adding explicit ARIA roles that duplicate native semantics (e.g.,
role="list"on<ul>,role="button"on<button>) - Using
data-testidwhen role-based selectors would work with proper markup
Presence vs Absence Assertions
Test both presence and absence to ensure complete validation of state.
Granularity Rule: Assert absence broadly and presence specifically.
// GOOD: Assert absence broadly (element doesn't exist anywhere)
await expect(this.page.getByText('Applied Gift Card(s)')).toHaveCount(0);
await expect(this.page.getByText(`***${GIFT_CARD_1_LAST_4}`)).toHaveCount(0);
// GOOD: Assert presence specifically (within correct context)
const giftCards = this.page.getByRole('region', {name: 'Gift cards'});
await expect(
giftCards.locator('dd').filter({hasText: `***${GIFT_CARD_1_LAST_4}`}),
).toBeVisible();
// WHY: Absence assertions cast a wide net (element shouldn't exist ANYWHERE).
// Presence assertions are scoped (element should exist in the RIGHT PLACE).Key Pattern: After removing an item, assert both:
- The specific item is gone (
.toHaveCount(0)) - The empty state is displayed (
.toBeVisible())
Real-world examples:
// GOOD: Remove item, assert it's gone AND empty state is shown
await removeGiftCardButton.click();
await expect(page.getByText(`***${GIFT_CARD_1_LAST_4}`)).toHaveCount(0);
await expect(page.getByText('No gift cards applied')).toBeVisible();
// AVOID: Only asserting the removal (could still have items if count changes to 1)
const initialCount = await page.getByRole('listitem').count();
await clearButton.click();
const newCount = await page.getByRole('listitem').count();
expect(newCount).not.toBe(initialCount); // ❌ Passes even if count=1
// GOOD: Assert absence broadly (no list items exist anywhere)
await clearButton.click();
await expect(page.getByRole('listitem')).toHaveCount(0);
await expect(page.getByText('Cart is empty')).toBeVisible();Wait for Visible Effects, Not Mechanisms
Wait for the actual data change the user sees, not intermediate states or implementation details.
NEVER use: page.waitForTimeout(), page.waitForLoadState('networkidle'), or arbitrary waits.
// GOOD: Wait for actual data change (user-visible effect)
await increaseButton.click();
await expect.poll(() => getLineItemQuantity(item)).toBe(2);
// GOOD: Wait for element state change
await applyButton.click();
await expect(input).toHaveValue(''); // Input cleared
await expect(applyButton).toBeEnabled(); // Button ready
// AVOID: Waiting for network (implementation detail)
await increaseButton.click();
await page.waitForResponse((resp) => resp.url().includes('cart'));
// AVOID: Arbitrary timeouts (flaky and slow)
await increaseButton.click();
await page.waitForTimeout(1000);
// AVOID: Network idle (unreliable, slow)
await page.goto('/cart');
await page.waitForLoadState('networkidle');Why avoid timeouts and networkidle?
- Timeouts are arbitrary (too short = flaky, too long = slow)
- Network idle is unreliable (analytics, polling, websockets)
- Visible effects are deterministic and match user experience
Waiting for State Changes
Wait for the visible effect rather than the underlying mechanism:
// GOOD: Wait for actual data change
await increaseButton.click();
await expect.poll(() => getLineItemQuantity(item)).toBe(2);
// AVOID: Waiting for button state (re-enables before data updates)
await increaseButton.click();
await expect(increaseButton).toBeEnabled();Running Tests
Always Use Headless Mode
Tests should ALWAYS be run in headless mode, both in development and in CI. This:
- Prevents browser windows from interfering with other work
- Ensures consistent behavior across environments
- Is faster than headed mode
The Playwright config does not specify a headed mode by default, so tests run headless automatically. Never add headless: false to the config or pass --headed flag:
# CORRECT: Run tests (headless by default)
pnpm exec playwright test --project=skeleton
# AVOID: Running with headed browser
pnpm exec playwright test --project=skeleton --headed # Don't do thisIf you need to debug visually, use Playwright's trace viewer or UI mode temporarily, but never commit headed configuration.
Fixture Design Principles
Deep Modules
Following John Ousterhout's principles, fixtures should expose entity locators but hide implementation details:
// GOOD: Entity locators are public
getCartLineItems() // Returns the domain entities
getCartDrawer() // Returns the cart drawer element
// GOOD: Button locators hidden inside action methods
async increaseLineItemQuantity(lineItem) {
const button = lineItem.getByRole('button', {name: 'Increase quantity'}); // Hidden
await button.click();
// ... wait for effect
}Visibility-Aware Locators
The skeleton template has both a cart drawer (aside) and a cart page. Both contain similar elements but only one is visible at a time.
// GOOD: Role-based selectors with chaining for specificity
getCartLineItems() {
return this.page.getByRole('list', {name: /cart|line items/i}).getByRole('listitem');
}
getCheckoutButton() {
return this.page.getByRole('button', {name: /checkout/i});
}
// ACCEPTABLE: Test IDs when semantic selectors need disambiguation
getCartLineItems() {
return this.page.getByTestId('cart-line-items').getByRole('listitem');
}
// AVOID: CSS selectors (DOM can change, leading to flaky tests)
getCartLineItems() {
return this.page.locator('li.cart-line:visible'); // Not resilient
}Why avoid CSS? Per Playwright docs, CSS selectors are "not recommended as the DOM can often change leading to non resilient tests." Use role-based selectors that reflect how users perceive the page.
Customer Account Tests
Running Locally
Prerequisites:
- Shopify CLI authenticated:
cd templates/skeleton && pnpm exec shopify auth login - Skeleton linked to benchmark store:
cd templates/skeleton && pnpm exec shopify hydrogen link - ejson configured (
./scripts/setup-ejson-private-key.sh) — required for both the test email and the loadtest header (OTP bypass)
# With ejson configured:
pnpm exec playwright test --project=skeleton e2e/specs/skeleton/customerAccount.spec.ts
# Override test email (ejson is still required for the loadtest header):
CUSTOMER_ACCOUNT_TEST_EMAIL="hydrogen-e2e-test@example.com" \
pnpm exec playwright test --project=skeleton e2e/specs/skeleton/customerAccount.spec.ts
# Against an existing Oxygen deployment (skips tunnel):
CUSTOMER_ACCOUNT_URL=https://your-oxygen-deployment.oxygen.myshopify.com \
OXYGEN_AUTH_BYPASS_TOKEN=your-token \
pnpm exec playwright test --project=skeleton e2e/specs/skeleton/customerAccount.spec.tsWithout CUSTOMER_ACCOUNT_URL, the test starts a local dev server with --customer-account-push which creates a Cloudflare quick-tunnel.
Architecture
Session reuse pattern: The Auth Setup describe block performs a full OAuth login once and saves the browser session to disk via storageState. Subsequent describe blocks (Auth Persistence, Account Pages, Logout) load this file via test.use({storageState}) to skip the expensive Shopify redirect chain.
Oxygen auth bypass: Password-protected Oxygen deployments require an oxygen-auth-bypass-token HTTP header (not a cookie). This is set via test.use({extraHTTPHeaders}) at file scope, so it applies to all tests regardless of storageState overrides. See Shopify docs.
Serial mode: Tests run serially because they share a session file on disk. Parallel execution would race on that file and break the dependency chain. Cloudflare rate limits are also a concern.
CI Split
The main E2E job excludes customer account tests via --grep-invert "@customer-account". A dedicated test_e2e_customer_account job deploys the skeleton to Oxygen and runs only these tests against the deployment URL. A health check step polls the deployment (with the bypass header) until it returns HTTP 200 before Playwright runs.
Tag coupling: The @customer-account tag in customerAccount.spec.ts is coupled to the --grep-invert in .github/workflows/ci.yml. If you rename the tag, update both places.
Consent and Analytics Tests
The new-cookies project loads the Customer Privacy API and privacy banner from Shopify's CDN. To test unreleased versions, point these variables at locally built bundles; the storefront fixture serves them in place of the CDN scripts:
E2E_CONSENT_API_BUNDLE_PATH=/path/to/consent-tracking-api.js \
E2E_PRIVACY_BANNER_BUNDLE_PATH=/path/to/storefront-banner.js \
pnpm e2e:new-cookieslong-session.spec.ts moves the browser clock past the 30-minute visit timeout, so it runs in parallel with the rest of the suite. Its real-time variant waits more than 30 minutes and only runs with E2E_REAL_TIME_SESSION=1.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

