feat: initial project setup with CLI, utils, and tests

This commit is contained in:
Andrea Debernardi
2026-05-09 21:59:41 +02:00
commit ed8df811f7
27 changed files with 2518 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { urlToOutputPath } from "../src/utils/wayback-url.js";
test("urlToOutputPath preserves host and path layout", () => {
assert.equal(
urlToOutputPath(
"https://example.com/wp-content/uploads/2020/01/photo.jpg",
"/out",
),
"/out/example.com/wp-content/uploads/2020/01/photo.jpg",
);
});
test("urlToOutputPath decodes percent-encoded segments", () => {
assert.equal(
urlToOutputPath("https://example.com/uploads/foto%20test.jpg", "/out"),
"/out/example.com/uploads/foto test.jpg",
);
});
test("urlToOutputPath sanitizes path-traversal segments", () => {
const out = urlToOutputPath("https://example.com/../etc/passwd", "/out");
assert.ok(!out.includes(".."));
});
test("urlToOutputPath omits host directory when hostPrefix=false", () => {
assert.equal(
urlToOutputPath(
"https://example.com/wp-content/uploads/2020/01/photo.jpg",
"/out",
{ hostPrefix: false },
),
"/out/wp-content/uploads/2020/01/photo.jpg",
);
});
test("urlToOutputPath falls back to 'index' for empty paths", () => {
assert.equal(
urlToOutputPath("https://example.com/", "/out"),
"/out/example.com/index",
);
});