23 lines
1.4 KiB
JavaScript
23 lines
1.4 KiB
JavaScript
// Test de getYouTubeProfilePicture (non exportée) : module recompilé avec une exportation de test
|
|
const path = require("path"), fs = require("fs"), Module = require("module"), assert = require("assert");
|
|
const SRC = require("path").resolve(__dirname, "../../src");
|
|
require(path.join(SRC, "../node_modules/loguix")).setup(path.join(__dirname, "logs"), path.join(SRC, "../package.json"));
|
|
const file = path.join(SRC, "media/YoutubeInformation.js");
|
|
const m = new Module(file, module); m.filename = file; m.paths = Module._nodeModulePaths(path.dirname(file));
|
|
m._compile(fs.readFileSync(file, "utf8") + "\nmodule.exports.__avatar = getYouTubeProfilePicture;", file);
|
|
const get = m.exports.__avatar;
|
|
(async () => {
|
|
let t = Date.now();
|
|
const a1 = await get("https://www.youtube.com/@aftkt");
|
|
console.log("avatar #1:", Date.now() - t, "ms", a1);
|
|
assert.ok(a1 && a1.startsWith("https://"));
|
|
t = Date.now();
|
|
const a2 = await get("https://www.youtube.com/@aftkt");
|
|
console.log("avatar #2 (cache):", Date.now() - t, "ms");
|
|
assert.strictEqual(a2, a1); assert.ok(Date.now() - t < 20);
|
|
assert.strictEqual(await get("https://evil.example.com/@x"), null);
|
|
assert.strictEqual(await get("https://www.youtube.com/channel/undefined"), null);
|
|
assert.strictEqual(await get(undefined), null);
|
|
console.log("OK");
|
|
})().catch(e => { console.error("ÉCHEC", e); process.exit(1); });
|