mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
test: fix type errors (#11325)
* test: fix type errors * chore: use MockedFunction --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -15,7 +15,7 @@ const mockRedisClient = {
|
||||
test('pubsub with custom encoding', async () => {
|
||||
const encode = vi.fn((data) => data);
|
||||
|
||||
const broker = new PubSubRedisBroker(mockRedisClient, { encode, group: 'group' });
|
||||
const broker = new PubSubRedisBroker(mockRedisClient, { encode, name: 'yeet', group: 'group' });
|
||||
await broker.publish('test', 'test');
|
||||
expect(encode).toHaveBeenCalledWith('test');
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/* eslint-disable id-length */
|
||||
/* eslint-disable promise/prefer-await-to-then */
|
||||
// @ts-nocheck
|
||||
import { performance } from 'node:perf_hooks';
|
||||
import { MockAgent, setGlobalDispatcher } from 'undici';
|
||||
import type { Interceptable, MockInterceptor } from 'undici/types/mock-interceptor';
|
||||
@@ -137,7 +136,7 @@ test('Handle unexpected 429', async () => {
|
||||
});
|
||||
|
||||
expect(await unexpectedLimit).toStrictEqual({ test: true });
|
||||
expect(performance.now()).toBeGreaterThanOrEqual(previous + 1_000);
|
||||
expect(firstResolvedTime!).toBeGreaterThanOrEqual(previous + 1_000);
|
||||
});
|
||||
|
||||
test('server responding too slow', async () => {
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
import { Buffer, File as NativeFile } from 'node:buffer';
|
||||
import { Buffer, File } from 'node:buffer';
|
||||
import { URLSearchParams } from 'node:url';
|
||||
import { DiscordSnowflake } from '@sapphire/snowflake';
|
||||
import type { Snowflake } from 'discord-api-types/v10';
|
||||
import { Routes } from 'discord-api-types/v10';
|
||||
import { type FormData, fetch } from 'undici';
|
||||
import { File as UndiciFile, MockAgent, setGlobalDispatcher } from 'undici';
|
||||
import { MockAgent, setGlobalDispatcher } from 'undici';
|
||||
import type { Interceptable, MockInterceptor } from 'undici/types/mock-interceptor.js';
|
||||
import { beforeEach, afterEach, test, expect, vitest } from 'vitest';
|
||||
import { REST } from '../src/index.js';
|
||||
import { genPath } from './util.js';
|
||||
|
||||
const File = NativeFile ?? UndiciFile;
|
||||
|
||||
const newSnowflake: Snowflake = DiscordSnowflake.generate().toString();
|
||||
|
||||
const api = new REST().setToken('A-Very-Fake-Token');
|
||||
|
||||
@@ -82,7 +82,7 @@ test('resolveBody', async () => {
|
||||
const fd = new globalThis.FormData();
|
||||
fd.append('key', 'value');
|
||||
|
||||
const resolved = await resolveBody(fd);
|
||||
const resolved = await resolveBody(fd as UndiciFormData);
|
||||
|
||||
expect(resolved).toBeInstanceOf(UndiciFormData);
|
||||
expect([...(resolved as UndiciFormData).entries()]).toStrictEqual([['key', 'value']]);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Buffer } from 'node:buffer';
|
||||
import { once } from 'node:events';
|
||||
import process from 'node:process';
|
||||
import { Readable } from 'node:stream';
|
||||
import { describe, test, expect, vitest, type Mock, beforeEach, afterEach } from 'vitest';
|
||||
import { describe, test, expect, vitest, type MockedFunction, beforeEach, afterEach } from 'vitest';
|
||||
import { addAudioPlayer, deleteAudioPlayer } from '../src/DataStore';
|
||||
import { VoiceConnection, VoiceConnectionStatus } from '../src/VoiceConnection';
|
||||
import type { AudioPlayer } from '../src/audio/AudioPlayer';
|
||||
@@ -252,7 +252,9 @@ describe('State transitions', () => {
|
||||
expect(connection.dispatchAudio).toHaveBeenCalledTimes(6);
|
||||
await wait();
|
||||
player['_stepPrepare']();
|
||||
const prepareAudioPacket = connection.prepareAudioPacket as unknown as Mock<typeof connection.prepareAudioPacket>;
|
||||
const prepareAudioPacket = connection.prepareAudioPacket as unknown as MockedFunction<
|
||||
typeof connection.prepareAudioPacket
|
||||
>;
|
||||
expect(prepareAudioPacket).toHaveBeenCalledTimes(6);
|
||||
expect(prepareAudioPacket.mock.calls[5]![0]).toEqual(silence().next().value);
|
||||
|
||||
@@ -307,7 +309,9 @@ describe('State transitions', () => {
|
||||
|
||||
await wait();
|
||||
expect(player.checkPlayable()).toEqual(false);
|
||||
const prepareAudioPacket = connection.prepareAudioPacket as unknown as Mock<typeof connection.prepareAudioPacket>;
|
||||
const prepareAudioPacket = connection.prepareAudioPacket as unknown as MockedFunction<
|
||||
typeof connection.prepareAudioPacket
|
||||
>;
|
||||
expect(prepareAudioPacket).toHaveBeenCalledTimes(5);
|
||||
|
||||
expect(player.state.status).toEqual(AudioPlayerStatus.Idle);
|
||||
@@ -338,7 +342,9 @@ describe('State transitions', () => {
|
||||
expect(addAudioPlayer).toBeCalledTimes(1);
|
||||
expect(player.checkPlayable()).toEqual(true);
|
||||
|
||||
const prepareAudioPacket = connection.prepareAudioPacket as unknown as Mock<typeof connection.prepareAudioPacket>;
|
||||
const prepareAudioPacket = connection.prepareAudioPacket as unknown as MockedFunction<
|
||||
typeof connection.prepareAudioPacket
|
||||
>;
|
||||
|
||||
// Run through a few packet cycles
|
||||
for (let index = 1; index <= 5; index++) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// @ts-nocheck
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { findPipeline, StreamType, TransformerType, type Edge } from '../src/audio/TransformerGraph';
|
||||
|
||||
@@ -10,12 +9,12 @@ const noConstraint = () => true;
|
||||
* @param pipeline - The pipeline of edges returned by findPipeline(...)
|
||||
*/
|
||||
function reducePath(pipeline: Edge[]) {
|
||||
const streams = [pipeline[0].from.type];
|
||||
const streams = [pipeline[0]!.from.type];
|
||||
for (const edge of pipeline.slice(1)) {
|
||||
streams.push(edge.from.type);
|
||||
}
|
||||
|
||||
streams.push(pipeline[pipeline.length - 1].to.type);
|
||||
streams.push(pipeline[pipeline.length - 1]!.to.type);
|
||||
return streams;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
/* eslint-disable @typescript-eslint/dot-notation */
|
||||
// @ts-nocheck
|
||||
import { EventEmitter } from 'node:events';
|
||||
import type { Mocked } from 'vitest';
|
||||
import { vitest, describe, test, expect, beforeEach } from 'vitest';
|
||||
import * as _DataStore from '../src/DataStore';
|
||||
import {
|
||||
@@ -25,16 +25,16 @@ vitest.mock('../src/networking/Networking', async (importOriginal) => {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
||||
const actual = await importOriginal<typeof import('../src/networking/Networking')>();
|
||||
const Networking = actual.Networking;
|
||||
Networking.prototype.createWebSocket = vitest.fn();
|
||||
Networking.prototype['createWebSocket'] = vitest.fn();
|
||||
return {
|
||||
...actual,
|
||||
Networking,
|
||||
};
|
||||
});
|
||||
|
||||
const DataStore = _DataStore as unknown as vitest.Mocked<typeof _DataStore>;
|
||||
const AudioPlayer = _AudioPlayer as unknown as vitest.Mocked<typeof _AudioPlayer>;
|
||||
const PlayerSubscription = _PlayerSubscription as unknown as vitest.Mock<_PlayerSubscription>;
|
||||
const DataStore = _DataStore as unknown as Mocked<typeof _DataStore>;
|
||||
const AudioPlayer = _AudioPlayer as unknown as Mocked<typeof _AudioPlayer>;
|
||||
const PlayerSubscription = _PlayerSubscription as unknown as Mocked<typeof _PlayerSubscription>;
|
||||
|
||||
const _NetworkingClass = Networking.Networking;
|
||||
vitest.spyOn(Networking, 'Networking').mockImplementation((...args) => new _NetworkingClass(...args));
|
||||
@@ -133,9 +133,10 @@ describe('createVoiceConnection', () => {
|
||||
|
||||
const stateSetter = vitest.spyOn(existingVoiceConnection, 'state', 'set');
|
||||
|
||||
// @ts-expect-error: We're testing
|
||||
DataStore.getVoiceConnection.mockImplementation((guildId, group = 'default') =>
|
||||
guildId === existingJoinConfig.guildId && group === existingJoinConfig.group ? existingVoiceConnection : null,
|
||||
guildId === existingJoinConfig.guildId && group === existingJoinConfig.group
|
||||
? existingVoiceConnection
|
||||
: undefined,
|
||||
);
|
||||
|
||||
const newAdapter = createFakeAdapter();
|
||||
@@ -172,9 +173,10 @@ describe('createVoiceConnection', () => {
|
||||
|
||||
const rejoinSpy = vitest.spyOn(existingVoiceConnection, 'rejoin');
|
||||
|
||||
// @ts-expect-error: We're testing
|
||||
DataStore.getVoiceConnection.mockImplementation((guildId, group = 'default') =>
|
||||
guildId === existingJoinConfig.guildId && group === existingJoinConfig.group ? existingVoiceConnection : null,
|
||||
guildId === existingJoinConfig.guildId && group === existingJoinConfig.group
|
||||
? existingVoiceConnection
|
||||
: undefined,
|
||||
);
|
||||
|
||||
const newAdapter = createFakeAdapter();
|
||||
@@ -204,9 +206,10 @@ describe('createVoiceConnection', () => {
|
||||
adapterCreator: existingAdapter.creator,
|
||||
});
|
||||
|
||||
// @ts-expect-error: We're testing
|
||||
DataStore.getVoiceConnection.mockImplementation((guildId, group = 'default') =>
|
||||
guildId === existingJoinConfig.guildId && group === existingJoinConfig.group ? existingVoiceConnection : null,
|
||||
guildId === existingJoinConfig.guildId && group === existingJoinConfig.group
|
||||
? existingVoiceConnection
|
||||
: undefined,
|
||||
);
|
||||
|
||||
const newAdapter = createFakeAdapter();
|
||||
@@ -444,7 +447,7 @@ describe('VoiceConnection#onNetworkingStateChange', () => {
|
||||
voiceConnection['_state'] = {
|
||||
...(voiceConnection.state as VoiceConnectionSignallingState),
|
||||
status: VoiceConnectionStatus.Connecting,
|
||||
networking: new Networking.Networking({} as any, false),
|
||||
networking: new Networking.Networking({} as any, {}),
|
||||
};
|
||||
|
||||
voiceConnection['onNetworkingStateChange'](
|
||||
@@ -462,7 +465,7 @@ describe('VoiceConnection#onNetworkingStateChange', () => {
|
||||
voiceConnection['_state'] = {
|
||||
...(voiceConnection.state as VoiceConnectionSignallingState),
|
||||
status: VoiceConnectionStatus.Connecting,
|
||||
networking: new Networking.Networking({} as any, false),
|
||||
networking: new Networking.Networking({} as any, {}),
|
||||
};
|
||||
|
||||
voiceConnection['onNetworkingStateChange'](
|
||||
@@ -492,7 +495,7 @@ describe('VoiceConnection#destroy', () => {
|
||||
voiceConnection.destroy();
|
||||
expect(DataStore.getVoiceConnection).toHaveReturnedWith(voiceConnection);
|
||||
expect(DataStore.untrackVoiceConnection).toHaveBeenCalledWith(voiceConnection);
|
||||
expect(DataStore.createJoinVoiceChannelPayload.mock.calls[0][0]).toMatchObject({
|
||||
expect(DataStore.createJoinVoiceChannelPayload.mock.calls[0]?.[0]).toMatchObject({
|
||||
channelId: null,
|
||||
guildId: joinConfig.guildId,
|
||||
});
|
||||
@@ -518,7 +521,7 @@ describe('VoiceConnection#disconnect', () => {
|
||||
voiceConnection.state = {
|
||||
status: VoiceConnectionStatus.Ready,
|
||||
adapter,
|
||||
networking: new Networking.Networking({} as any, false),
|
||||
networking: new Networking.Networking({} as any, {}),
|
||||
};
|
||||
const leavePayload = Symbol('dummy');
|
||||
DataStore.createJoinVoiceChannelPayload.mockImplementation(() => leavePayload as any);
|
||||
@@ -542,7 +545,7 @@ describe('VoiceConnection#disconnect', () => {
|
||||
voiceConnection.state = {
|
||||
status: VoiceConnectionStatus.Ready,
|
||||
adapter,
|
||||
networking: new Networking.Networking({} as any, false),
|
||||
networking: new Networking.Networking({} as any, {}),
|
||||
};
|
||||
adapter.sendPayload.mockImplementation(() => false);
|
||||
expect(voiceConnection.disconnect()).toEqual(false);
|
||||
@@ -676,7 +679,7 @@ describe('VoiceConnection#onSubscriptionRemoved', () => {
|
||||
// Arrange
|
||||
const ws = new EventEmitter() as any;
|
||||
|
||||
const oldNetworking = new Networking.Networking({} as any, false);
|
||||
const oldNetworking = new Networking.Networking({} as any, {});
|
||||
oldNetworking.state = {
|
||||
code: Networking.NetworkingStatusCode.Ready,
|
||||
connectionData: {} as any,
|
||||
@@ -685,7 +688,7 @@ describe('VoiceConnection#onSubscriptionRemoved', () => {
|
||||
ws,
|
||||
};
|
||||
|
||||
const newNetworking = new Networking.Networking({} as any, false);
|
||||
const newNetworking = new Networking.Networking({} as any, {});
|
||||
newNetworking.state = {
|
||||
...oldNetworking.state,
|
||||
udp: new EventEmitter() as any,
|
||||
@@ -706,7 +709,7 @@ describe('VoiceConnection#onSubscriptionRemoved', () => {
|
||||
// Arrange
|
||||
const udp = new EventEmitter() as any;
|
||||
|
||||
const oldNetworking = new Networking.Networking({} as any, false);
|
||||
const oldNetworking = new Networking.Networking({} as any, {});
|
||||
oldNetworking.state = {
|
||||
code: Networking.NetworkingStatusCode.Ready,
|
||||
connectionData: {} as any,
|
||||
@@ -715,7 +718,7 @@ describe('VoiceConnection#onSubscriptionRemoved', () => {
|
||||
ws: new EventEmitter() as any,
|
||||
};
|
||||
|
||||
const newNetworking = new Networking.Networking({} as any, false);
|
||||
const newNetworking = new Networking.Networking({} as any, {});
|
||||
newNetworking.state = {
|
||||
...oldNetworking.state,
|
||||
ws: new EventEmitter() as any,
|
||||
@@ -735,7 +738,7 @@ describe('VoiceConnection#onSubscriptionRemoved', () => {
|
||||
test('Applies initial listeners', () => {
|
||||
// Arrange
|
||||
|
||||
const newNetworking = new Networking.Networking({} as any, false);
|
||||
const newNetworking = new Networking.Networking({} as any, {});
|
||||
newNetworking.state = {
|
||||
code: Networking.NetworkingStatusCode.Ready,
|
||||
connectionData: {} as any,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/* eslint-disable id-length */
|
||||
/* eslint-disable @typescript-eslint/dot-notation */
|
||||
// @ts-nocheck
|
||||
import { Buffer } from 'node:buffer';
|
||||
import { once } from 'node:events';
|
||||
import process from 'node:process';
|
||||
@@ -15,7 +14,6 @@ import {
|
||||
} from '../__mocks__/rtp';
|
||||
import { VoiceConnection, VoiceConnectionStatus } from '../src/VoiceConnection';
|
||||
import { VoiceReceiver } from '../src/receive/VoiceReceiver';
|
||||
import { methods } from '../src/util/Secretbox';
|
||||
|
||||
vitest.mock('../src/VoiceConnection', async (importOriginal) => {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
||||
@@ -33,18 +31,8 @@ async function nextTick() {
|
||||
return new Promise((resolve) => process.nextTick(resolve));
|
||||
}
|
||||
|
||||
function* rangeIter(start: number, end: number) {
|
||||
for (let i = start; i <= end; i++) {
|
||||
yield i;
|
||||
}
|
||||
}
|
||||
|
||||
function range(start: number, end: number) {
|
||||
return Buffer.from([...rangeIter(start, end)]);
|
||||
}
|
||||
|
||||
describe('VoiceReceiver', () => {
|
||||
let voiceConnection: _VoiceConnection;
|
||||
let voiceConnection: VoiceConnection;
|
||||
let receiver: VoiceReceiver;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -64,7 +52,7 @@ describe('VoiceReceiver', () => {
|
||||
['RTP Packet Desktop', RTP_PACKET_DESKTOP],
|
||||
['RTP Packet Chrome', RTP_PACKET_CHROME],
|
||||
['RTP Packet Android', RTP_PACKET_ANDROID],
|
||||
])('onUdpMessage: decrypt from %s', async (testName, RTP_PACKET) => {
|
||||
])('onUdpMessage: decrypt from %s', async (_testName, RTP_PACKET) => {
|
||||
receiver['decrypt'] = vitest.fn().mockImplementationOnce(() => RTP_PACKET.decrypted);
|
||||
|
||||
const spy = vitest.spyOn(receiver.ssrcMap, 'get');
|
||||
@@ -144,8 +132,6 @@ describe('VoiceReceiver', () => {
|
||||
});
|
||||
|
||||
describe('decrypt', () => {
|
||||
const secretKey = new Uint8Array([1, 2, 3, 4]);
|
||||
|
||||
test('decrypt: aead_xchacha20_poly1305_rtpsize', () => {
|
||||
const nonceSpace = Buffer.alloc(24);
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
// @ts-nocheck
|
||||
import { Buffer } from 'node:buffer';
|
||||
import { createSocket as _createSocket } from 'node:dgram';
|
||||
import { EventEmitter } from 'node:events';
|
||||
import type { MockedFunction } from 'vitest';
|
||||
import { describe, test, expect, vitest, beforeEach, afterEach } from 'vitest';
|
||||
import { VoiceUDPSocket } from '../src/networking/VoiceUDPSocket';
|
||||
|
||||
vitest.mock('node:dgram');
|
||||
vitest.useFakeTimers();
|
||||
|
||||
const createSocket = _createSocket as unknown as vitest.Mock<typeof _createSocket>;
|
||||
const createSocket = _createSocket as unknown as MockedFunction<typeof _createSocket>;
|
||||
|
||||
beforeEach(() => {
|
||||
createSocket.mockReset();
|
||||
});
|
||||
|
||||
class FakeSocket extends EventEmitter {
|
||||
public send(buffer: Buffer, port: number, address: string) {}
|
||||
public send(_buffer: Buffer, _port: number, _address: string) {}
|
||||
|
||||
public close() {
|
||||
this.emit('close');
|
||||
@@ -49,10 +49,10 @@ describe('VoiceUDPSocket#performIPDiscovery', () => {
|
||||
*/
|
||||
test('Resolves and cleans up with a successful flow', async () => {
|
||||
const fake = new FakeSocket();
|
||||
fake.send = vitest.fn().mockImplementation((buffer: Buffer, port: number, address: string) => {
|
||||
fake.send = vitest.fn().mockImplementation((_buffer: Buffer, _port: number, _address: string) => {
|
||||
fake.emit('message', VALID_RESPONSE);
|
||||
});
|
||||
createSocket.mockImplementation((type) => fake as any);
|
||||
createSocket.mockImplementation((_type) => fake as any);
|
||||
socket = new VoiceUDPSocket({ ip: '1.2.3.4', port: 25_565 });
|
||||
|
||||
expect(createSocket).toHaveBeenCalledWith('udp4');
|
||||
@@ -72,7 +72,7 @@ describe('VoiceUDPSocket#performIPDiscovery', () => {
|
||||
test('Waits for a valid response in an unexpected flow', async () => {
|
||||
const fake = new FakeSocket();
|
||||
const fakeResponse = Buffer.from([1, 2, 3, 4, 5]);
|
||||
fake.send = vitest.fn().mockImplementation(async (buffer: Buffer, port: number, address: string) => {
|
||||
fake.send = vitest.fn().mockImplementation(async (_buffer: Buffer, _port: number, _address: string) => {
|
||||
fake.emit('message', fakeResponse);
|
||||
await wait();
|
||||
fake.emit('message', VALID_RESPONSE);
|
||||
@@ -92,7 +92,7 @@ describe('VoiceUDPSocket#performIPDiscovery', () => {
|
||||
|
||||
test('Rejects if socket closes before IP discovery can be completed', async () => {
|
||||
const fake = new FakeSocket();
|
||||
fake.send = vitest.fn().mockImplementation(async (buffer: Buffer, port: number, address: string) => {
|
||||
fake.send = vitest.fn().mockImplementation(async (_buffer: Buffer, _port: number, _address: string) => {
|
||||
await wait();
|
||||
fake.close();
|
||||
});
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
// @ts-nocheck
|
||||
import { Buffer } from 'node:buffer';
|
||||
import EventEmitter, { once } from 'node:events';
|
||||
import process from 'node:process';
|
||||
import { Readable } from 'node:stream';
|
||||
import { opus as _opus } from 'prism-media';
|
||||
import { describe, test, expect, vitest, type Mock, beforeAll, beforeEach } from 'vitest';
|
||||
import { describe, test, expect, vitest, type Mock, beforeAll, beforeEach, type Mocked } from 'vitest';
|
||||
import { StreamType } from '../src/audio/index';
|
||||
import { demuxProbe } from '../src/util/demuxProbe';
|
||||
|
||||
vitest.mock('prism-media');
|
||||
|
||||
const WebmDemuxer = _opus.WebmDemuxer as unknown as Mock<_opus.WebmDemuxer>;
|
||||
const OggDemuxer = _opus.OggDemuxer as unknown as Mock<_opus.OggDemuxer>;
|
||||
const WebmDemuxer = _opus.WebmDemuxer as unknown as Mocked<typeof _opus.WebmDemuxer>;
|
||||
const OggDemuxer = _opus.OggDemuxer as unknown as Mocked<typeof _opus.OggDemuxer>;
|
||||
|
||||
async function nextTick() {
|
||||
// eslint-disable-next-line no-promise-executor-return
|
||||
@@ -52,12 +51,12 @@ describe('demuxProbe', () => {
|
||||
const oggWrite: Mock<(buffer: Buffer) => void> = vitest.fn();
|
||||
|
||||
beforeAll(() => {
|
||||
WebmDemuxer.prototype = {
|
||||
(WebmDemuxer as any).prototype = {
|
||||
...WebmDemuxer,
|
||||
...EventEmitter.prototype,
|
||||
write: webmWrite,
|
||||
};
|
||||
OggDemuxer.prototype = {
|
||||
(OggDemuxer as any).prototype = {
|
||||
...OggDemuxer,
|
||||
...EventEmitter.prototype,
|
||||
write: oggWrite,
|
||||
@@ -78,9 +77,9 @@ describe('demuxProbe', () => {
|
||||
|
||||
test('Detects WebM', async () => {
|
||||
const stream = Readable.from(gen(10), { objectMode: false });
|
||||
webmWrite.mockImplementation(function mock(data: Buffer) {
|
||||
webmWrite.mockImplementation(function mock(this: EventEmitter, data: Buffer) {
|
||||
if (data[0] === 5) this.emit('head', validHead);
|
||||
} as any);
|
||||
});
|
||||
const probe = await demuxProbe(stream);
|
||||
expect(probe.type).toEqual(StreamType.WebmOpus);
|
||||
await expect(collectStream(probe.stream)).resolves.toEqual(range(10));
|
||||
@@ -88,9 +87,9 @@ describe('demuxProbe', () => {
|
||||
|
||||
test('Detects Ogg', async () => {
|
||||
const stream = Readable.from(gen(10), { objectMode: false });
|
||||
oggWrite.mockImplementation(function mock(data: Buffer) {
|
||||
oggWrite.mockImplementation(function mock(this: EventEmitter, data: Buffer) {
|
||||
if (data[0] === 5) this.emit('head', validHead);
|
||||
} as any);
|
||||
});
|
||||
const probe = await demuxProbe(stream);
|
||||
expect(probe.type).toEqual(StreamType.OggOpus);
|
||||
await expect(collectStream(probe.stream)).resolves.toEqual(range(10));
|
||||
@@ -98,9 +97,9 @@ describe('demuxProbe', () => {
|
||||
|
||||
test('Rejects invalid OpusHead', async () => {
|
||||
const stream = Readable.from(gen(10), { objectMode: false });
|
||||
oggWrite.mockImplementation(function mock(data: Buffer) {
|
||||
oggWrite.mockImplementation(function mock(this: EventEmitter, data: Buffer) {
|
||||
if (data[0] === 5) this.emit('head', invalidHead);
|
||||
} as any);
|
||||
});
|
||||
const probe = await demuxProbe(stream);
|
||||
expect(probe.type).toEqual(StreamType.Arbitrary);
|
||||
await expect(collectStream(probe.stream)).resolves.toEqual(range(10));
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// @ts-nocheck
|
||||
import { describe, test, expect, vitest, beforeAll, beforeEach } from 'vitest';
|
||||
import * as VoiceConnection from '../src/VoiceConnection';
|
||||
import { joinVoiceChannel } from '../src/joinVoiceChannel';
|
||||
@@ -21,7 +20,7 @@ describe('joinVoiceChannel', () => {
|
||||
guildId: '456',
|
||||
adapterCreator,
|
||||
});
|
||||
expect(createVoiceConnection.mock.calls[0][0]).toMatchObject({
|
||||
expect(createVoiceConnection.mock.calls[0]?.[0]).toMatchObject({
|
||||
channelId: '123',
|
||||
guildId: '456',
|
||||
group: 'default',
|
||||
@@ -35,7 +34,7 @@ describe('joinVoiceChannel', () => {
|
||||
group: 'abc',
|
||||
adapterCreator,
|
||||
});
|
||||
expect(createVoiceConnection.mock.calls[0][0]).toMatchObject({
|
||||
expect(createVoiceConnection.mock.calls[0]?.[0]).toMatchObject({
|
||||
channelId: '123',
|
||||
guildId: '456',
|
||||
group: 'abc',
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/consistent-type-imports */
|
||||
// @ts-nocheck
|
||||
import { beforeEach, test, vi, expect } from 'vitest';
|
||||
import { test, vi, expect } from 'vitest';
|
||||
import {
|
||||
managerToFetchingStrategyOptions,
|
||||
WorkerContextFetchingStrategy,
|
||||
@@ -9,17 +7,20 @@ import {
|
||||
WorkerReceivePayloadOp,
|
||||
type WorkerReceivePayload,
|
||||
type WorkerSendPayload,
|
||||
type SessionInfo,
|
||||
} from '../../src/index.js';
|
||||
import { mockGatewayInformation } from '../gateway.mock.js';
|
||||
|
||||
const session = {
|
||||
const session: SessionInfo = {
|
||||
shardId: 0,
|
||||
shardCount: 1,
|
||||
sequence: 123,
|
||||
sessionId: 'abc',
|
||||
resumeURL: 'wss://resume.url/',
|
||||
};
|
||||
|
||||
vi.mock('node:worker_threads', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
||||
const { EventEmitter }: typeof import('node:events') = await vi.importActual('node:events');
|
||||
class MockParentPort extends EventEmitter {
|
||||
public postMessage(message: WorkerReceivePayload) {
|
||||
|
||||
Reference in New Issue
Block a user