Files
bip-kit/test/video-embed.test.js
GandClaude Opus 5 a5362991de chore: add a formatter (#12)
* chore: add a formatter, matching the style this repo already writes

singleQuote=false was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.

Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format with prettier (7 files)

Mechanical. No behaviour change. This SHA is listed in
.git-blame-ignore-revs so `git blame` skips it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore: teach git blame to skip the reformat

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-31 09:41:59 +02:00

51 lines
1.6 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { parseVideoEmbed, videoEmbedSrc } from "../dist/index.js";
test("every allowlisted YouTube URL shape yields the same id", () => {
for (const url of [
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"https://youtube.com/watch?v=dQw4w9WgXcQ",
"https://youtu.be/dQw4w9WgXcQ",
"https://www.youtube.com/embed/dQw4w9WgXcQ",
"youtube.com/watch?v=dQw4w9WgXcQ",
]) {
assert.deepEqual(parseVideoEmbed(url), { provider: "youtube", id: "dQw4w9WgXcQ" }, url);
}
});
test("Vimeo URLs yield numeric ids", () => {
assert.deepEqual(parseVideoEmbed("https://vimeo.com/76979871"), {
provider: "vimeo",
id: "76979871",
});
});
test("surrounding whitespace is tolerated", () => {
assert.equal(parseVideoEmbed(" https://vimeo.com/76979871 ").id, "76979871");
});
test("anything off the allowlist is rejected, however video-shaped", () => {
for (const url of [
"https://dailymotion.com/video/x123456",
"https://evil.example.com/watch?v=dQw4w9WgXcQ",
"https://youtube.com.evil.example.com/watch?v=dQw4w9WgXcQ",
"javascript:alert(1)",
"",
"not a url at all",
]) {
assert.equal(parseVideoEmbed(url), null, url);
}
});
test("embed src is the privacy-preserving player, never the raw URL", () => {
assert.equal(
videoEmbedSrc({ provider: "youtube", id: "dQw4w9WgXcQ" }),
"https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ",
);
assert.equal(
videoEmbedSrc({ provider: "vimeo", id: "76979871" }),
"https://player.vimeo.com/video/76979871",
);
});