Skip to content

Fix @clavex/react Jest suite (ESM + React interop) #1

Description

@fcraviolatti

Problem

@clavex/react's Jest suite does not run cleanly under the monorepo. Build and
type emission (tsup) are unaffected — this is purely a test-harness issue.

Symptoms

  1. With the default ts-jest (CommonJS) preset the suite fails to compile:

    src/ClavexProvider.tsx:72:20 - error TS1343: The 'import.meta' meta-property
    is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext',
    'system', 'node16', 'node18', 'node20', or 'nodenext'.
    

    Root cause: the source uses import.meta.env, which requires ESM.

  2. Switching to ts-jest/presets/default-esm + useESM: true + module: esnext
    fixes compilation but then breaks React module interop — React.useContext
    resolves to null under jest ESM:

    Cannot read properties of null (reading 'useContext')   (src/context.tsx:45)
    

    5 tests fail because React/context is mis-resolved.

Current workaround

  • jest.config.js left on the default ts-jest preset (documented inline).
  • CI (.github/workflows/ci.yml) runs npm test with continue-on-error: true
    so the react suite does not block the pipeline.

Goal

Working jest-ESM setup for @clavex/react with correct React CJS/ESM interop,
so the suite passes and continue-on-error can be removed.

Things to try

  • ts-jest/presets/default-esm + extensionsToTreatAsEsm + moduleNameMapper
    pinning a single React instance.
  • Or migrate the suite to Vitest (native ESM + import.meta, jsdom).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions