Skip to content

fix: remove jest.mock() from root __tests__/ for ESM compatibility#47

Merged
OwenMcGirr merged 1 commit into
mainfrom
fix/46-jest-globals-esm
Apr 12, 2026
Merged

fix: remove jest.mock() from root __tests__/ for ESM compatibility#47
OwenMcGirr merged 1 commit into
mainfrom
fix/46-jest-globals-esm

Conversation

@OwenMcGirr
Copy link
Copy Markdown
Collaborator

Closes #46

Problem

CI runs Jest with NODE_OPTIONS=--experimental-vm-modules. In ESM mode, jest is not injected as a global — top-level jest.mock() calls throw ReferenceError: jest is not defined.

Four tests in root __tests__/ were affected:

  • azure-ssml.test.ts
  • abstract-tts-gender.test.ts
  • google-gender.test.ts
  • elevenlabs-gender.test.ts

Fix

The jest.mock() calls were either no-ops (mocking with requireActual) or unnecessary (engine clients work fine instantiated with fake credentials, as already demonstrated by src/__tests__/azure-mstts-namespace.test.ts). Removed all four top-level mock blocks and replaced with direct static imports.

Added import { jest } from "@jest/globals" to azure-ssml.test.ts for the jest.spyOn call, which is the correct ESM pattern.

Test plan

  • NODE_OPTIONS=--experimental-vm-modules npx jest __tests__/azure-ssml __tests__/abstract-tts-gender __tests__/google-gender __tests__/elevenlabs-gender — all 4 pass in ESM mode
  • npm test — no regressions

jest.mock() at the top level requires jest to be a global, which it is
not in ESM mode (NODE_OPTIONS=--experimental-vm-modules). The mocks were
either no-ops (mock with requireActual) or unnecessary (engine clients
work fine with fake credentials). Removed all four top-level jest.mock()
calls and replaced with direct imports. Added import { jest } from
"@jest/globals" in azure-ssml.test.ts for the jest.spyOn call.
@OwenMcGirr OwenMcGirr merged commit e290652 into main Apr 12, 2026
5 checks passed
@OwenMcGirr OwenMcGirr deleted the fix/46-jest-globals-esm branch April 12, 2026 09:45
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.

fix: jest globals undefined in root __tests__/ when running with --experimental-vm-modules

1 participant