fix(dom): keep readiness gate async-free so TestCafe t.eval accepts the bundle#2346
Open
prklm10 wants to merge 1 commit into
Open
fix(dom): keep readiness gate async-free so TestCafe t.eval accepts the bundle#2346prklm10 wants to merge 1 commit into
prklm10 wants to merge 1 commit into
Conversation
…he bundle The @percy/dom bundle is injected into the browser verbatim by SDKs. TestCafe's `t.eval` (used by @percy/testcafe/index.js) statically rejects any async/await or generator syntax in the evaluated source. The readiness gate added in 1.31.14 (PER-7348) introduced two `async` functions into the bundle, which broke every @percy/testcafe snapshot with: eval code, arguments or dependencies cannot contain generators or "async/await" syntax (use Promises instead). Rewrite `runAllChecks` and `waitForReady` to explicit Promise chains (behavior unchanged — both were already Promise-returning at every call site) so the bundle is async-free again, matching the pre-1.31.14 (1.31.13) profile. Add a package-local .eslintrc in packages/dom/src that forbids async/await and generators via no-restricted-syntax, so this contract can't silently regress. Fixes PER-10121 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes PER-10121
Root cause
The
@percy/dombundle is injected into the browser verbatim by SDKs.@percy/testcafe/index.js:29does:TestCafe's
t.eval/ClientFunction machinery statically rejects anyasync/awaitor generator syntax in the evaluated source.The readiness gate shipped in 1.31.14 (PER-7348, #2184) added two
asyncfunctions —runAllChecksandwaitForReadyinpackages/dom/src/readiness.js— which are the only async/await in the entire dom source. Because the rollup babel target (browsers: ['last 2 versions and supports async-functions']) intentionally does not down-level async, those tokens flow straight intodist/bundle.js. Every@percy/testcafesnapshot then fails with:and the build finalizes with
Failure: Snapshot command was not called. Playwright/other SDKs are unaffected because they don't route the bundle through TestCafe's restrictive evaluator.Bundle token profile (published):
asyncawaitFix
Rewrite
runAllChecksandwaitForReadyto explicit Promise chains (return Promise.all(...),Promise.race(...).catch(...).then(...)). Behavior is unchanged — both were already Promise-returning at every call site (runAllChecks(...).then(...),await waitForReady(...)), and the try/catch →.catch/.thenmapping preserves the timeout/abort/post-processing semantics exactly. The rebuilt bundle is back to 0 async / 0 await / 0 generators, matching the 1.31.13 profile that TestCafe accepts.Add a package-local
packages/dom/src/.eslintrcthat forbidsasync/await/generators viano-restricted-syntax, so this browser-injection contract can't silently regress again (which is exactly how it shipped).Testing
@percy/domsuite green: 902 tests pass, including the readiness suite (waitForReady returns a Promise,stays sync even when readiness config is present, timeout/graceful-degradation cases).dist/bundle.jsverified async/await/generator-free.readiness.js.🤖 Generated with Claude Code