Skip to content

fix(js-cypress): stop tests depending on the apify.com marketing site#808

Open
l2ysho wants to merge 1 commit into
masterfrom
fix-flaky-cypress-template
Open

fix(js-cypress): stop tests depending on the apify.com marketing site#808
l2ysho wants to merge 1 commit into
masterfrom
fix-flaky-cypress-template

Conversation

@l2ysho

@l2ysho l2ysho commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Problem

The js-cypress template's example specs hit the live apify.com marketing site, so the template's CI broke whenever that site changed — even though the template itself was untouched:

  • first-spec.cy.jscy.visit('/'), asserted cy.contains('div', 'Apify')
  • second-spec.cy.jscy.visit('/store'), clicked .ActorStoreItem-title containing Web Scraper, asserted a redirect to https://apify.com/apify/web-scraper

The harness runs these for real: js-cypress is not in SKIP_TESTS, and checkTemplateRun() (test/templates.test.js:156) executes apify run, which runs src/main.jscypress.run() against the configured site.

Observed failure on PR #806 / run 27280506506 (windows-latest, node 24):

It's demo code — it shouldn't depend on production marketing markup the template repo doesn't control.

Fix

Repoint the demo at https://example.com (IANA / RFC-2606 reserved for documentation — stable markup, no app JS) and harden the specs:

  • first-spec → asserts the stable Example Domain heading.
  • second-spec → selects the outbound link by a[href*="iana.org"] instead of by visible text, and asserts visibility — no cross-origin click. (While testing I found example.com now serves a Learn more link variant rather than the old More information...; the attribute selector is robust to that copy churn.)
  • cypress/support/e2e.jsCypress.on('uncaught:exception', () => false), documented with a link to the React error docs, so a broken JS handler on the visited page can't auto-fail the demo.
  • Updated baseUrl default/prefill in cypress.config.js, src/main.js, and .actor/input_schema.json, and documented the new target + how to override it via the baseUrl input in the README.

Scope is limited to templates/js-cypress/**; the Apify SDK + Cypress wiring (input schema, dataset/KVS result storage, video recording) is unchanged, so the template still teaches the same thing.

Verification

Done locally on the final files (in an isolated copy, mirroring prepareActor's fs.cpSync to a tmp dir):

  • npm install, npm run lint, npm run format:check — all pass.
  • node --check on every touched JS file; JSON files parse.
  • Confirmed the asserted elements (<h1>Example Domain</h1> and a link with href*="iana.org") exist in the live example.com HTML across its served variants.

The actual headless browser run can't execute in my sandbox (no Xvfb / no root). Relying on this PR's CI matrix (ubuntu-24.04 + windows-latest, Node 22/24) for the cross-OS browser run — please confirm two consecutive green runs, with attention to the Windows job that was flaky on timing.

🤖 Generated with Claude Code

The js-cypress template's example specs hit the live apify.com marketing
site: first-spec visited `/` and second-spec visited `/store`, clicked
`.ActorStoreItem-title` and asserted a redirect. This made the template's
CI hostage to the marketing site — React hydration errors (e.g. minified
#418), CSS class renames, and slow Windows-runner renders all broke the
Node template matrix even though the template itself was unchanged
(see run 27280506506).

Repoint the demo at https://example.com (IANA/RFC-2606 reserved for
documentation — stable markup, no app JS), and harden the specs:

- first-spec: assert the stable `Example Domain` heading.
- second-spec: select the outbound link by `href*="iana.org"` instead of
  by visible text (robust to copy changes) and assert visibility, avoiding
  a cross-origin click.
- support/e2e.js: swallow page-level uncaught exceptions so a broken JS
  handler on the visited page can't auto-fail the demo (documented, with a
  link to the React error docs).
- Update baseUrl default/prefill in cypress.config.js, src/main.js and
  input_schema.json, and document the new target + how to override it via
  the `baseUrl` input in the README.

The template still demonstrates Cypress + Apify SDK wiring end to end.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants