spb/social-runtime-crawler
Public
TypeScript 91.8%
HTML 3.2%
JavaScript 3%
SQL 1.4%
CSS 0.7%
1import { describe, expect, it } from "vitest";2import { parseCount, parseDuration, tokenize, canonicalUrl } from "./util.ts";34describe("parseCount", () => {5 it("handles fr/en thousands, decimals, suffixes and unicode spaces", () => {6 expect(parseCount("3 624 visionnements")).toBe(3624);7 expect(parseCount("3 624 vues")).toBe(3624);8 expect(parseCount("12,345 views")).toBe(12345);9 expect(parseCount("1,2 M de vues")).toBe(1_200_000);10 expect(parseCount("48 k vues")).toBe(48_000);11 expect(parseCount("483")).toBe(483);12 expect(parseCount("17 k")).toBe(17_000);13 expect(parseCount("no number")).toBeUndefined();14 });15});16describe("parseDuration", () => {17 it("parses mm:ss and h:mm:ss", () => {18 expect(parseDuration("12:34")).toBe(754);19 expect(parseDuration("1:02:03")).toBe(3723);20 });21});22describe("tokenize", () => {23 it("keeps 2-letter domain tokens and drops stopwords", () => {24 const t = tokenize("Discover public Quebec creators discussing AI");25 expect(t.has("ai")).toBe(true);26 expect(t.has("quebec")).toBe(true);27 expect(t.has("public")).toBe(false);28 });29});30describe("canonicalUrl", () => {31 it("strips tracking params and www", () => {32 expect(canonicalUrl("https://www.youtube.com/watch?v=abc&si=xyz&t=10")).toBe("https://youtube.com/watch?v=abc");33 });34});35