Skip to content

Instantly share code, notes, and snippets.

@LayZeeDK
Last active August 11, 2025 09:08
Show Gist options
  • Save LayZeeDK/960e025cecbe228c9627caedf82b0274 to your computer and use it in GitHub Desktop.
Save LayZeeDK/960e025cecbe228c9627caedf82b0274 to your computer and use it in GitHub Desktop.
Resolve Nx generator unit test issues in Nx 19 + Jest 29.
/// <reference types="jest" />
import type { getFileInfo, resolveConfig } from 'prettier';
/**
* Resolve `TypeError: performance.mark is not a function`.
*
* @see https://github.com/nrwl/nx/issues/23435#issuecomment-2127183725
*/
const performanceMock: Performance = {
...performance,
mark: jest.fn(),
measure: jest.fn(),
};
Object.defineProperties(globalThis, {
performance: { value: performanceMock },
});
jest.doMock('perf_hooks', () => ({
...jest.requireActual('perf_hooks'),
performance: performanceMock,
}));
jest.doMock('node:perf_hooks', () => ({
...jest.requireActual('node:perf_hooks'),
performance: performanceMock,
}));
/**
* Resolve `TypeError: A dynamic import callback was invoked without --experimental-vm-modules` in unit tests.
*
* @see https://github.com/nrwl/nx/issues/26387#issuecomment-2191174250
*/
jest.mock('prettier', () => ({
resolveConfig: jest
.fn()
.mockImplementation(
(): ReturnType<typeof resolveConfig> => Promise.resolve(null)
),
getFileInfo: jest.fn().mockImplementation(
(): ReturnType<typeof getFileInfo> =>
Promise.resolve({
ignored: true,
inferredParser: null,
})
),
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment