fix: remove jest.mock() from root __tests__/ for ESM compatibility#47
Merged
Conversation
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.
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.
Closes #46
Problem
CI runs Jest with
NODE_OPTIONS=--experimental-vm-modules. In ESM mode,jestis not injected as a global — top-leveljest.mock()calls throwReferenceError: jest is not defined.Four tests in root
__tests__/were affected:azure-ssml.test.tsabstract-tts-gender.test.tsgoogle-gender.test.tselevenlabs-gender.test.tsFix
The
jest.mock()calls were either no-ops (mocking withrequireActual) or unnecessary (engine clients work fine instantiated with fake credentials, as already demonstrated bysrc/__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"toazure-ssml.test.tsfor thejest.spyOncall, 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 modenpm test— no regressions