chore: Upgrade to Vitest 4 and regroup tests for performance (#2618)
This commit is contained in:
@@ -8,7 +8,7 @@ interface AudioMocks {
|
||||
// and pushed here in construction order, so tests can dispatch real events
|
||||
// and read real properties (`loop`, `currentTime`, etc.) on the instances.
|
||||
instances: HTMLAudioElement[];
|
||||
ctor: Mock<[string?], HTMLAudioElement>;
|
||||
ctor: Mock<(url?: string) => HTMLAudioElement>;
|
||||
}
|
||||
|
||||
// Uses real jsdom HTMLAudioElement instances and only stubs the parts jsdom
|
||||
@@ -33,7 +33,10 @@ const useAudioElementMocks = (): AudioMocks => {
|
||||
vi.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation(() => {});
|
||||
|
||||
const RealAudio = window.Audio;
|
||||
handle.ctor = vi.fn((url?: string) => {
|
||||
|
||||
// The source calls `new Audio(...)`, and a mock implementation must be
|
||||
// callable with `new`, so it cannot be an arrow function.
|
||||
handle.ctor = vi.fn(function (url?: string) {
|
||||
const audio = new RealAudio(url);
|
||||
handle.instances.push(audio);
|
||||
return audio;
|
||||
|
||||
@@ -10,7 +10,7 @@ import { mock, type MockProxy } from 'vitest-mock-extended';
|
||||
// over the same observable state.
|
||||
interface AudioMocks {
|
||||
audioContext: MockProxy<AudioContext>;
|
||||
audioContextCtor: Mock<[], MockProxy<AudioContext>>;
|
||||
audioContextCtor: Mock<() => MockProxy<AudioContext>>;
|
||||
|
||||
// Filled in the order `createOscillator()` / `createGain()` were called.
|
||||
oscillators: MockProxy<OscillatorNode>[];
|
||||
@@ -73,7 +73,11 @@ export const useAudioMocks = (): AudioMocks => {
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
audio.audioContextCtor = vi.fn(() => audio.audioContext);
|
||||
// The source calls `new AudioContext()`, and a mock implementation must be
|
||||
// callable with `new`, so it cannot be an arrow function.
|
||||
audio.audioContextCtor = vi.fn(function () {
|
||||
return audio.audioContext;
|
||||
});
|
||||
vi.stubGlobal('AudioContext', audio.audioContextCtor);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user