Skip to content

Commit

Permalink
test: update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
skick1234 committed Apr 22, 2024
1 parent 91485a8 commit f5a2763
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/core/DisTubeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export class Options {
streamType: StreamType;
directLink: boolean;
/** @deprecated */
ffmpegPath: null = null;
ffmpegPath: undefined = undefined;
/** @deprecated */
ffmpegDefaultArgs: null = null;
ffmpegDefaultArgs: undefined = undefined;
ffmpeg: FFmpegOptions;
constructor(options: DisTubeOptions) {
if (typeof options !== "object" || Array.isArray(options)) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/DisTubeStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const chooseBestVideoFormat = ({ duration, formats, isLive }: Song) =>
.filter(f => f.hasAudio && (duration < 10 * 60 || f.hasVideo) && (!isLive || f.isHLS))
.sort((a, b) => Number(b.audioBitrate) - Number(a.audioBitrate) || Number(a.bitrate) - Number(b.bitrate))[0];

let checked = false;
let checked = process.env.NODE_ENV === "test";
export const checkFFmpeg = (distube: DisTube) => {
if (checked) return;
const path = distube.options.ffmpeg.path;
Expand Down
3 changes: 2 additions & 1 deletion src/core/manager/QueueManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GuildIdManager } from ".";
import { DisTubeError, DisTubeStream, Events, Queue, RepeatMode, objectKeys } from "../..";
import { DisTubeError, DisTubeStream, Events, Queue, RepeatMode, checkFFmpeg, objectKeys } from "../..";
import type { Song } from "../..";
import type { GuildTextBasedChannel, VoiceBasedChannel } from "discord.js";

Expand Down Expand Up @@ -30,6 +30,7 @@ export class QueueManager extends GuildIdManager<Queue> {
const queue = new Queue(this.distube, voice, song, textChannel);
await queue._taskQueue.queuing();
try {
checkFFmpeg(this.distube);
await voice.join();
this.#voiceEventHandler(queue);
this.add(queue.id, queue);
Expand Down
27 changes: 26 additions & 1 deletion tests/core/DisTubeOptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
import { Options, defaultOptions } from "@";

test("Default DisTubeOptions", () => {
expect(new Options({})).toEqual(defaultOptions);
expect(new Options({})).toEqual({
directLink: true,
emitAddListWhenCreatingQueue: true,
emitAddSongWhenCreatingQueue: true,
emitNewSongOnly: false,
emptyCooldown: 60,
ffmpeg: {
args: {
global: {},
input: {},
output: {},
},
path: "ffmpeg",
},
joinNewVoiceChannel: true,
leaveOnEmpty: true,
leaveOnFinish: false,
leaveOnStop: true,
nsfw: false,
plugins: [],
savePreviousSongs: true,
searchCooldown: 60,
searchSongs: 0,
streamType: 0,
ytdlOptions: {},
});
});

const typeOfOption = (option: string) => {
Expand Down
10 changes: 4 additions & 6 deletions tests/core/DisTubeVoice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,20 @@ describe("Methods", () => {
voice.emittedError = true;
DiscordVoice.createAudioResource.mockReturnValue(audioResource as any);
const stream = {
stream: {
on: jest.fn(),
},
on: jest.fn(),
type: {},
};
expect(voice.play(stream as any)).toBeUndefined();
expect(voice.emittedError).toBe(false);
expect(stream.stream.on).toHaveBeenCalledWith("error", expect.any(Function));
expect(stream.on).toHaveBeenCalledWith("error", expect.any(Function));
expect(voice.audioResource).toBe(audioResource);
expect(audioPlayer.play).toHaveBeenCalledTimes(1);
expect(audioPlayer.play).toHaveBeenNthCalledWith(1, audioResource);
const error = {};
stream.stream.on.mock.calls[0][1](error);
stream.on.mock.calls[0][1](error);
expect(voice.emittedError).toBe(true);
expect(voice.emit).toHaveBeenCalledWith("error", error);
stream.stream.on.mock.calls[0][1](error);
stream.on.mock.calls[0][1](error);
expect(voice.emit).toHaveBeenCalledTimes(1);

audioPlayer.state.status = DiscordVoice.AudioPlayerStatus.Paused;
Expand Down
10 changes: 7 additions & 3 deletions tests/core/manager/QueueManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DisTubeVoiceManager = _DTVM as unknown as jest.Mocked<typeof _DTVM>;

function createFakeDisTube() {
return {
options: { ...defaultOptions },
options: { ...defaultOptions, ffmpeg: { path: "ffmpeg", args: { global: {}, input: {}, output: {} } } },
voices: new DisTubeVoiceManager(this),
emit: jest.fn(),
emitError: jest.fn(),
Expand Down Expand Up @@ -160,7 +160,7 @@ describe("QueueManager#createStream()", () => {
expect.objectContaining({
ffmpeg: expect.objectContaining({
path: "ffmpeg",
args: { ...defaultOptions.ffmpegDefaultArgs },
args: { global: expect.any(Object), input: expect.any(Object), output: expect.any(Object) },
}),
seek: 1,
}),
Expand Down Expand Up @@ -189,7 +189,11 @@ describe("QueueManager#createStream()", () => {
expect.objectContaining({
ffmpeg: expect.objectContaining({
path: "ffmpeg",
args: { ...defaultOptions.ffmpegDefaultArgs, af: `${distube.filters["3d"]},${distube.filters.bassboost}` },
args: {
global: expect.any(Object),
input: expect.any(Object),
output: expect.objectContaining({ af: `${distube.filters["3d"]},${distube.filters.bassboost}` }),
},
}),
seek: undefined,
}),
Expand Down

0 comments on commit f5a2763

Please sign in to comment.