发布

  • fix(testing): template the e2e config for fresh projects instead of ast-parsing it (#36304)

    frostbyte_neo 发布于 2026-07-13 13:57:00 +00:00

    Current Behavior

    @nx/cypress's e2e configuration generator scaffolds a cypress.config
    from a base template (defineConfig({})), reads it back, and uses
    @phenomnomnominal/tsquery to inject the e2e block. Loading tsquery
    reads ts.SyntaxKind at import time. When a workspace resolves an
    incompatible TypeScript — e.g. npm install hoisting typescript@7 to
    satisfy tsquery's unbounded >3.0.0 peer in a workspace that pins no
    TypeScript — that read throws:

     NX   Cannot convert undefined or null to object
        at Object.keys (<anonymous>)
        at .../@phenomnomnominal/tsquery/dist/src/syntax-kind.js
    

    …and app generation fails. This is what crashes e2e-expo /
    e2e-react-native (and any cypress-scaffolded app) on the macOS CI job,
    which installs test workspaces with npm. The bare apps workspace pins
    no TypeScript, so npm hoists TS 7 for tsquery's peer.

    Expected Behavior

    For a freshly generated config the AST round-trip is unnecessary: nx
    just wrote the empty base and knows every value going in (the module
    shape was already decided when the base template was selected). The
    generator now templates the complete cypress.config directly via a new
    buildE2EConfigFromBase (no tsquery), so generation never loads tsquery
    and no longer depends on the resolved TypeScript version.

    The AST-based addDefaultE2EConfig is kept for the case that genuinely
    needs it — merging the e2e config into a pre-existing, possibly
    user-authored
    config (nx g @nx/cypress:configuration on a project
    that already has a config). The templated output is byte-identical
    to the previous AST output, so generated files and snapshots are
    unchanged.

    Verified: 227 cypress unit tests pass, 41 config snapshots unchanged,
    and e2e-expo:e2e-macos-local passes under npm with zero tsquery
    crashes (was 53).

    Related Issue(s)

    Surfaced by the macOS e2e (e2e-expo / e2e-react-native) crashing
    once TypeScript 7 was published to npm — cypress config generation
    loaded tsquery, which reads the top-level SyntaxKind export that TS 7
    removed.


    View session information

    下载附件