Migrate more jest tests to vitest (#33898)

* Migrate more jest tests to vitest

* Fix jest config

* Fix jest config

* Make remaining jest tests type-happy
This commit is contained in:
Michael Telatynski
2026-06-19 15:34:18 +00:00
committed by GitHub
parent fab71c80ed
commit 45234b9c94
62 changed files with 625 additions and 488 deletions
+25
View File
@@ -0,0 +1,25 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { vi } from "vitest";
import { mocked as jestMocked } from "jest-mock";
const isJest = typeof jest !== "undefined";
/**
* Subset of the vitest API surface, with jest equivalents for the same functions when running under jest.
*/
const adapter = {
fn: isJest ? (jest.fn as unknown as typeof vi.fn) : vi.fn,
spyOn: isJest ? (jest.spyOn as unknown as typeof vi.spyOn) : vi.spyOn,
mocked: isJest ? (jestMocked as typeof vi.mocked) : vi.mocked,
} as Pick<typeof vi, "fn" | "spyOn" | "mocked">;
const mocked = adapter.mocked;
export { adapter as vi, mocked };
export { type Mocked, type MockedObject } from "vitest";
+16 -14
View File
@@ -6,23 +6,25 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/
import { vi } from "./adapter.ts";
export const mocks = {
AudioBufferSourceNode: {
connect: jest.fn(),
start: jest.fn(),
stop: jest.fn(),
connect: vi.fn(),
start: vi.fn(),
stop: vi.fn(),
} as unknown as AudioBufferSourceNode,
AudioContext: {
close: jest.fn(),
createMediaElementSource: jest.fn(),
createMediaStreamDestination: jest.fn(),
createMediaStreamSource: jest.fn(),
createStreamTrackSource: jest.fn(),
createBufferSource: jest.fn((): AudioBufferSourceNode => ({ ...mocks.AudioBufferSourceNode })),
getOutputTimestamp: jest.fn(),
resume: jest.fn(),
setSinkId: jest.fn(),
suspend: jest.fn(),
decodeAudioData: jest.fn(),
close: vi.fn(),
createMediaElementSource: vi.fn(),
createMediaStreamDestination: vi.fn(),
createMediaStreamSource: vi.fn(),
createStreamTrackSource: vi.fn(),
createBufferSource: vi.fn((): AudioBufferSourceNode => ({ ...mocks.AudioBufferSourceNode })),
getOutputTimestamp: vi.fn(),
resume: vi.fn(),
setSinkId: vi.fn(),
suspend: vi.fn(),
decodeAudioData: vi.fn(),
} as unknown as AudioContext,
};