Skip to content

Commit

Permalink
test: update deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
skick1234 committed Apr 19, 2024
1 parent e75d771 commit bbf8844
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 433 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
patreon: DisTube
ko_fi: skick
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<a href="https://github.com/skick1234/DisTube/stargazers" target="_blank"><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/skick1234/DisTube?logo=github&logoColor=white&style=flat-square"/></a>
<a href="https://discord.gg/feaDd9h" target="_blank"><img alt="Discord" src="https://img.shields.io/discord/732254550689316914?logo=discord&logoColor=white&style=flat-square"/></a>
</p>
<p>
<a href='https://ko-fi.com/skick' target='_blank'><img height='48' src='https://storage.ko-fi.com/cdn/kofi3.png' alt='Buy Me a Coffee at ko-fi.com' /></a>
</p>
</div>

# DisTube
Expand Down
2 changes: 1 addition & 1 deletion tests/DisTube.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("Constructor", () => {
expect(distube.filters).toEqual(defaultFilters);
expect(distube.extractorPlugins.find(p => p.type === PluginType.CUSTOM)).toBeFalsy();
expect(distube.customPlugins.find(p => p.type === PluginType.EXTRACTOR)).toBeFalsy();
expect(client.on).not.toBeCalled();
expect(client.on).not.toHaveBeenCalled();
});
});

Expand Down
160 changes: 81 additions & 79 deletions tests/core/DisTubeHandler.test.ts

Large diffs are not rendered by default.

25 changes: 3 additions & 22 deletions tests/core/DisTubeOptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
import { Options, defaultOptions } from "@";

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

const typeOfOption = (option: string) => {
Expand All @@ -34,13 +16,12 @@ const typeOfOption = (option: string) => {
};

test("Validate DisTubeOptions", () => {
const n: any = NaN;
expect(() => {
new Options(n);
new Options(<any>NaN);
}).toThrow("Expected 'object' for 'DisTubeOptions', but got NaN");
for (const option of Object.keys(defaultOptions)) {
const options = {};
options[option] = n;
options[option] = NaN;
expect(() => {
new Options(options);
}).toThrow(`Expected '${typeOfOption(option)}' for 'DisTubeOptions.${option}', but got NaN`);
Expand Down
164 changes: 2 additions & 162 deletions tests/core/DisTubeStream.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { StreamType as DiscordVoiceStreamType } from "@discordjs/voice";
import { liveFormats, regularFormats } from "../raw";
import { DisTubeError, DisTubeStream, StreamType, chooseBestVideoFormat } from "@";

import { FFmpeg as _FFmpeg } from "prism-media";

jest.mock("prism-media");

const FFmpeg = _FFmpeg as unknown as jest.Mocked<typeof _FFmpeg>;
import { chooseBestVideoFormat } from "@";

const regularItag = 251;
const liveItag = 95;
Expand Down Expand Up @@ -37,157 +30,4 @@ describe("chooseBestVideoFormat()", () => {
});
});

describe("DisTubeStream.YouTube()", () => {
test("Regular video", () => {
const stream = DisTubeStream.YouTube(
<any>{ source: "youtube", formats: regularFormats, isLive: false, duration: 60 },
{
ffmpegArgs: ["added", "arguments"],
type: StreamType.RAW,
},
);
const url = regularFormats.find(f => f.itag === regularItag).url;
expect(stream).toMatchObject({
url,
type: DiscordVoiceStreamType.Raw,
stream: expect.any(FFmpeg),
});
expect(FFmpeg).toBeCalledWith(
expect.objectContaining({
args: expect.arrayContaining([
"-reconnect",
"1",
"-reconnect_streamed",
"1",
"-reconnect_delay_max",
"5",
"-i",
url,
"-analyzeduration",
"0",
"-loglevel",
"0",
"-ar",
"48000",
"-ac",
"2",
"-f",
"s16le",
"added",
"arguments",
]),
}),
);
});

test("Live video", () => {
const stream = DisTubeStream.YouTube(<any>{ source: "youtube", formats: liveFormats, isLive: true, duration: 60 }, {
seek: 1,
});
const url = liveFormats.find(f => f.itag === liveItag).url;
expect(stream).toMatchObject({
url,
type: DiscordVoiceStreamType.OggOpus,
stream: expect.any(FFmpeg),
});
expect(FFmpeg).toBeCalledWith(
expect.objectContaining({
args: expect.arrayContaining([
"-reconnect",
"1",
"-reconnect_streamed",
"1",
"-reconnect_delay_max",
"5",
"-i",
url,
"-analyzeduration",
"0",
"-loglevel",
"0",
"-ar",
"48000",
"-ac",
"2",
"-ss",
"1",
"-f",
"opus",
"-acodec",
"libopus",
]),
}),
);
});

test("Should not return a DisTubeStream", () => {
const s: any = { source: "test" };
expect(() => {
DisTubeStream.YouTube(s);
}).toThrow(new DisTubeError("INVALID_TYPE", "youtube", s.source, "Song#source"));
expect(() => {
DisTubeStream.YouTube(<any>{ source: "youtube" });
}).toThrow(new DisTubeError("UNAVAILABLE_VIDEO"));
expect(() => {
DisTubeStream.YouTube(<any>{ source: "youtube", formats: [{}] }, 0 as any);
}).toThrow(new DisTubeError("INVALID_TYPE", "object", 0, "options"));
expect(() => {
DisTubeStream.YouTube(<any>{ source: "youtube", formats: [{}] }, [] as any);
}).toThrow(new DisTubeError("INVALID_TYPE", "object", [], "options"));
expect(() => {
DisTubeStream.YouTube(<any>{ source: "youtube", formats: [{}] });
}).toThrow(new DisTubeError("UNPLAYABLE_FORMATS"));
expect(FFmpeg).not.toBeCalled();
});
});

describe("DisTubeStream.DirectLink()", () => {
test("Valid URL", () => {
const url = "https://distube.js.org";
const stream = DisTubeStream.DirectLink(url);
expect(stream).toMatchObject({
url,
type: DiscordVoiceStreamType.OggOpus,
stream: expect.any(FFmpeg),
});
expect(FFmpeg).toBeCalledWith(
expect.objectContaining({
args: expect.arrayContaining([
"-reconnect",
"1",
"-reconnect_streamed",
"1",
"-reconnect_delay_max",
"5",
"-i",
url,
"-analyzeduration",
"0",
"-loglevel",
"0",
"-ar",
"48000",
"-ac",
"2",
"-f",
"opus",
"-acodec",
"libopus",
]),
}),
);
});

test("Should not return a DisTubeStream", () => {
expect(() => {
DisTubeStream.DirectLink("", 0 as any);
}).toThrow(new DisTubeError("INVALID_TYPE", "object", 0, "options"));
expect(() => {
DisTubeStream.DirectLink("", [] as any);
}).toThrow(new DisTubeError("INVALID_TYPE", "object", [], "options"));
expect(() => {
DisTubeStream.DirectLink("not an url");
}).toThrow(new DisTubeError("INVALID_TYPE", "an URL", "not an url"));
expect(FFmpeg).not.toBeCalled();
});
});
test.todo("DisTubeStream"); // Do after v5 refactoring
Loading

0 comments on commit bbf8844

Please sign in to comment.