43 lines
1.7 KiB
JavaScript
43 lines
1.7 KiB
JavaScript
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const os = require("node:os");
|
|
const path = require("node:path");
|
|
const { findLatestBundle, resolveBundlePath } = require("../lib/bundles");
|
|
|
|
/**
|
|
* Crée un bundle Hugo minimal pour les tests.
|
|
* @param {string} rootDir Racine temporaire.
|
|
* @param {string} relativePath Chemin relatif du bundle.
|
|
* @returns {Promise<string>} Chemin absolu du bundle créé.
|
|
*/
|
|
async function createBundle(rootDir, relativePath) {
|
|
const bundleDir = path.join(rootDir, relativePath);
|
|
await fs.mkdir(bundleDir, { recursive: true });
|
|
await fs.writeFile(path.join(bundleDir, "index.md"), "---\ntitle: Test\ndate: 2026-03-20T12:00:00+01:00\n---\n", "utf8");
|
|
return bundleDir;
|
|
}
|
|
|
|
test("resolveBundlePath accepte un dossier de bundle ou un index.md", () => {
|
|
const bundleDir = path.resolve("content/example/bundle");
|
|
const indexPath = path.join(bundleDir, "index.md");
|
|
|
|
assert.equal(resolveBundlePath(bundleDir), bundleDir);
|
|
assert.equal(resolveBundlePath(indexPath), bundleDir);
|
|
});
|
|
|
|
test("findLatestBundle retourne le bundle modifie le plus recemment", async () => {
|
|
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "bundles-test-"));
|
|
const olderBundle = await createBundle(tempRoot, "alpha/article-a");
|
|
const newerBundle = await createBundle(tempRoot, "beta/article-b");
|
|
|
|
await fs.utimes(olderBundle, new Date("2026-03-20T10:00:00Z"), new Date("2026-03-20T10:00:00Z"));
|
|
await fs.utimes(newerBundle, new Date("2026-03-20T11:00:00Z"), new Date("2026-03-20T11:00:00Z"));
|
|
|
|
const latestBundle = await findLatestBundle(tempRoot);
|
|
|
|
assert.equal(latestBundle, newerBundle);
|
|
|
|
await fs.rm(tempRoot, { recursive: true, force: true });
|
|
});
|