2026-07-06 19:48:12 -04:00
|
|
|
import { test } from 'node:test';
|
|
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
|
import {
|
|
|
|
|
getYouTubeVideoId,
|
|
|
|
|
getYoutubeShortsId,
|
|
|
|
|
isYouTubeShorts,
|
|
|
|
|
getVimeoVideoId,
|
2026-07-06 20:01:05 -04:00
|
|
|
getTikTokVideoId,
|
|
|
|
|
getDailymotionId,
|
|
|
|
|
getStreamableId,
|
|
|
|
|
getTwitchTarget,
|
|
|
|
|
getSpotifyEmbedTarget,
|
|
|
|
|
isSoundCloudTrack,
|
2026-07-06 19:48:12 -04:00
|
|
|
buildVideoEmbedUrl,
|
2026-07-06 20:01:05 -04:00
|
|
|
spotifyEmbedHeight,
|
|
|
|
|
parseMediaEmbed,
|
2026-07-06 19:48:12 -04:00
|
|
|
} from './videoEmbed';
|
|
|
|
|
|
2026-07-06 20:01:05 -04:00
|
|
|
const HOST = 'chat.lotusguild.org';
|
|
|
|
|
|
|
|
|
|
test('YouTube: watch / youtu.be / embed / shorts', () => {
|
2026-07-06 19:48:12 -04:00
|
|
|
assert.equal(getYouTubeVideoId('https://www.youtube.com/watch?v=dQw4w9WgXcQ'), 'dQw4w9WgXcQ');
|
|
|
|
|
assert.equal(getYouTubeVideoId('https://youtu.be/dQw4w9WgXcQ?t=42'), 'dQw4w9WgXcQ');
|
|
|
|
|
assert.equal(getYouTubeVideoId('https://www.youtube.com/embed/dQw4w9WgXcQ'), 'dQw4w9WgXcQ');
|
|
|
|
|
assert.equal(getYouTubeVideoId('https://youtube.com/shorts/abc123DEF_-'), 'abc123DEF_-');
|
|
|
|
|
assert.equal(getYouTubeVideoId('https://vimeo.com/123'), null);
|
|
|
|
|
assert.equal(isYouTubeShorts('https://www.youtube.com/shorts/abc123'), true);
|
|
|
|
|
assert.equal(getYoutubeShortsId('https://youtube.com/shorts/abc123'), 'abc123');
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-06 20:01:05 -04:00
|
|
|
test('Vimeo', () => {
|
2026-07-06 19:48:12 -04:00
|
|
|
assert.equal(getVimeoVideoId('https://vimeo.com/123456789'), '123456789');
|
|
|
|
|
assert.equal(getVimeoVideoId('https://vimeo.com/channels/staffpicks'), null);
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-06 20:01:05 -04:00
|
|
|
test('TikTok: canonical /video/<id> only', () => {
|
|
|
|
|
assert.equal(getTikTokVideoId('https://www.tiktok.com/@user/video/7234567890123456789'), '7234567890123456789');
|
|
|
|
|
assert.equal(getTikTokVideoId('https://vm.tiktok.com/ZMabc/'), null); // short link redirects
|
|
|
|
|
assert.equal(getTikTokVideoId('https://www.tiktok.com/@user'), null);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Dailymotion + Streamable', () => {
|
|
|
|
|
assert.equal(getDailymotionId('https://www.dailymotion.com/video/x8abcde'), 'x8abcde');
|
|
|
|
|
assert.equal(getDailymotionId('https://dai.ly/x8abcde'), 'x8abcde');
|
|
|
|
|
assert.equal(getStreamableId('https://streamable.com/abc12'), 'abc12');
|
|
|
|
|
assert.equal(getStreamableId('https://streamable.com/e/abc12'), null); // already an embed path
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Twitch: channel / video / clip', () => {
|
|
|
|
|
assert.deepEqual(getTwitchTarget('https://www.twitch.tv/somestreamer'), {
|
|
|
|
|
type: 'channel',
|
|
|
|
|
value: 'somestreamer',
|
2026-07-06 19:48:12 -04:00
|
|
|
});
|
2026-07-06 20:01:05 -04:00
|
|
|
assert.deepEqual(getTwitchTarget('https://www.twitch.tv/videos/123456789'), {
|
|
|
|
|
type: 'video',
|
|
|
|
|
value: '123456789',
|
|
|
|
|
});
|
|
|
|
|
assert.deepEqual(getTwitchTarget('https://clips.twitch.tv/FunnyClipSlug'), {
|
|
|
|
|
type: 'clip',
|
|
|
|
|
value: 'FunnyClipSlug',
|
|
|
|
|
});
|
|
|
|
|
assert.deepEqual(getTwitchTarget('https://www.twitch.tv/streamer/clip/CoolSlug'), {
|
|
|
|
|
type: 'clip',
|
|
|
|
|
value: 'CoolSlug',
|
2026-07-06 19:48:12 -04:00
|
|
|
});
|
2026-07-06 20:01:05 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Spotify target + height', () => {
|
|
|
|
|
assert.deepEqual(getSpotifyEmbedTarget('https://open.spotify.com/track/4cOdK2wGLETKBW3PvgPWqT'), {
|
|
|
|
|
type: 'track',
|
|
|
|
|
id: '4cOdK2wGLETKBW3PvgPWqT',
|
|
|
|
|
});
|
|
|
|
|
assert.deepEqual(getSpotifyEmbedTarget('https://open.spotify.com/intl-de/album/xyz'), {
|
|
|
|
|
type: 'album',
|
|
|
|
|
id: 'xyz',
|
2026-07-06 19:48:12 -04:00
|
|
|
});
|
2026-07-06 20:01:05 -04:00
|
|
|
assert.equal(getSpotifyEmbedTarget('https://open.spotify.com/'), null);
|
|
|
|
|
assert.equal(spotifyEmbedHeight('track'), 152);
|
|
|
|
|
assert.equal(spotifyEmbedHeight('album'), 352);
|
2026-07-06 19:48:12 -04:00
|
|
|
});
|
|
|
|
|
|
2026-07-06 20:01:05 -04:00
|
|
|
test('SoundCloud track detection', () => {
|
|
|
|
|
assert.equal(isSoundCloudTrack('https://soundcloud.com/artist/some-track'), true);
|
|
|
|
|
assert.equal(isSoundCloudTrack('https://soundcloud.com/artist'), false); // bare profile
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('buildVideoEmbedUrl: cookie-less YouTube + Vimeo', () => {
|
2026-07-06 19:48:12 -04:00
|
|
|
assert.equal(
|
|
|
|
|
buildVideoEmbedUrl('youtube', 'dQw4w9WgXcQ'),
|
|
|
|
|
'https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?autoplay=1&rel=0',
|
|
|
|
|
);
|
2026-07-06 20:01:05 -04:00
|
|
|
assert.equal(buildVideoEmbedUrl('vimeo', '42'), 'https://player.vimeo.com/video/42?autoplay=1');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('parseMediaEmbed: routes provider + kind, builds embed URLs', () => {
|
|
|
|
|
assert.deepEqual(parseMediaEmbed('https://youtube.com/shorts/abc', HOST), {
|
|
|
|
|
provider: 'youtube',
|
|
|
|
|
kind: 'portrait',
|
|
|
|
|
embedUrl: 'https://www.youtube-nocookie.com/embed/abc?autoplay=1&rel=0',
|
|
|
|
|
});
|
|
|
|
|
assert.equal(parseMediaEmbed('https://www.youtube.com/watch?v=xyz', HOST)?.kind, 'landscape');
|
|
|
|
|
assert.equal(parseMediaEmbed('https://www.tiktok.com/@u/video/123', HOST)?.provider, 'tiktok');
|
|
|
|
|
assert.equal(parseMediaEmbed('https://www.tiktok.com/@u/video/123', HOST)?.kind, 'portrait');
|
|
|
|
|
assert.equal(parseMediaEmbed('https://streamable.com/abc', HOST)?.provider, 'streamable');
|
|
|
|
|
const spotify = parseMediaEmbed('https://open.spotify.com/track/abc', HOST);
|
|
|
|
|
assert.equal(spotify?.kind, 'audio');
|
|
|
|
|
assert.equal(spotify?.height, 152);
|
|
|
|
|
assert.equal(parseMediaEmbed('https://soundcloud.com/a/b', HOST)?.provider, 'soundcloud');
|
|
|
|
|
assert.equal(parseMediaEmbed('https://example.com/x', HOST), null);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('parseMediaEmbed: Twitch embed carries the parent host', () => {
|
|
|
|
|
const chan = parseMediaEmbed('https://twitch.tv/streamer', HOST);
|
|
|
|
|
assert.equal(chan?.provider, 'twitch');
|
|
|
|
|
assert.ok(chan?.embedUrl.includes('channel=streamer'));
|
|
|
|
|
assert.ok(chan?.embedUrl.includes(`parent=${HOST}`));
|
|
|
|
|
const clip = parseMediaEmbed('https://clips.twitch.tv/Slug', HOST);
|
|
|
|
|
assert.ok(clip?.embedUrl.startsWith('https://clips.twitch.tv/embed?clip=Slug'));
|
2026-07-06 19:48:12 -04:00
|
|
|
});
|