mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor: use eslint-config-neon for packages. (#8579)
Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
import { Buffer } from 'node:buffer';
|
||||
import process from 'node:process';
|
||||
import { PassThrough, Readable } from 'node:stream';
|
||||
import { opus, VolumeTransformer } from 'prism-media';
|
||||
import { SILENCE_FRAME } from '../src/audio/AudioPlayer';
|
||||
import { AudioResource, createAudioResource, NO_CONSTRAINT, VOLUME_CONSTRAINT } from '../src/audio/AudioResource';
|
||||
import { Edge, findPipeline as _findPipeline, StreamType, TransformerType } from '../src/audio/TransformerGraph';
|
||||
import { findPipeline as _findPipeline, StreamType, TransformerType, type Edge } from '../src/audio/TransformerGraph';
|
||||
|
||||
jest.mock('prism-media');
|
||||
jest.mock('../src/audio/TransformerGraph');
|
||||
|
||||
function wait() {
|
||||
async function wait() {
|
||||
// eslint-disable-next-line no-promise-executor-return
|
||||
return new Promise((resolve) => process.nextTick(resolve));
|
||||
}
|
||||
|
||||
@@ -16,12 +19,14 @@ async function started(resource: AudioResource) {
|
||||
while (!resource.started) {
|
||||
await wait();
|
||||
}
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
const findPipeline = _findPipeline as unknown as jest.MockedFunction<typeof _findPipeline>;
|
||||
|
||||
beforeAll(() => {
|
||||
// @ts-expect-error no type
|
||||
findPipeline.mockImplementation((from: StreamType, constraint: (path: Edge[]) => boolean) => {
|
||||
const base = [
|
||||
{
|
||||
@@ -38,6 +43,7 @@ beforeAll(() => {
|
||||
type: TransformerType.InlineVolume,
|
||||
});
|
||||
}
|
||||
|
||||
return base as any[];
|
||||
});
|
||||
});
|
||||
@@ -113,11 +119,12 @@ describe('createAudioResource', () => {
|
||||
await started(resource);
|
||||
expect(resource.readable).toEqual(true);
|
||||
expect(resource.read()).toEqual(Buffer.from([1]));
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let index = 0; index < 5; index++) {
|
||||
await wait();
|
||||
expect(resource.readable).toEqual(true);
|
||||
expect(resource.read()).toEqual(SILENCE_FRAME);
|
||||
}
|
||||
|
||||
await wait();
|
||||
expect(resource.readable).toEqual(false);
|
||||
expect(resource.read()).toEqual(null);
|
||||
|
||||
Reference in New Issue
Block a user