mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
* chore: vitest config * feat: vitest * fix: do not actually create ws * chore: config * chore: lockfile * chore: revert downgrade, up node * chore: package - 'git add -A' * chore: delete mock-socket * chore: delete mock-socket * fix: lockfile --------- Co-authored-by: almeidx <github@almeidx.dev> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
35 lines
916 B
TypeScript
35 lines
916 B
TypeScript
import { describe, test, expect, vitest } from 'vitest';
|
|
import { SpeakingMap } from '../src/receive/SpeakingMap';
|
|
import { noop } from '../src/util/util';
|
|
|
|
vitest.useFakeTimers();
|
|
|
|
describe('SpeakingMap', () => {
|
|
test('Emits start and end', () => {
|
|
const speaking = new SpeakingMap();
|
|
const userId = '123';
|
|
|
|
const starts: string[] = [];
|
|
const ends: string[] = [];
|
|
|
|
speaking.on('start', (userId) => void starts.push(userId));
|
|
speaking.on('end', (userId) => void ends.push(userId));
|
|
|
|
for (let index = 0; index < 10; index++) {
|
|
speaking.onPacket(userId);
|
|
setTimeout(noop, SpeakingMap.DELAY / 2);
|
|
vitest.advanceTimersToNextTimer();
|
|
|
|
expect(starts).toEqual([userId]);
|
|
expect(ends).toEqual([]);
|
|
}
|
|
|
|
vitest.advanceTimersToNextTimer();
|
|
expect(ends).toEqual([userId]);
|
|
|
|
speaking.onPacket(userId);
|
|
vitest.advanceTimersToNextTimer();
|
|
expect(starts).toEqual([userId, userId]);
|
|
});
|
|
});
|