Skip to content

Commit

Permalink
Fixes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed May 13, 2024
1 parent bb9c24b commit d7f8755
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/AssetCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ class AssetCache {
}

for (let k of key) {
hash.update(k);
k = ""+k;
if(k) {
hash.update(k);
} else {
throw new Error(`Not able to convert asset key (${k}) to string.`);
}
}

return ("" + hash.digest("hex")).slice(0, hashLength);
Expand Down
30 changes: 30 additions & 0 deletions test/RemoteAssetCacheTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,36 @@ test("Fetching (dry run)!", async (t) => {
t.false(ac.hasCacheFiles());
});

test("Fetching pass in URL", async (t) => {
let pngUrl = new URL("https://www.zachleat.com/img/avatar-2017-big.png");
let ac = new RemoteAssetCache(pngUrl);
let buffer = await ac.fetch();
t.is(Buffer.isBuffer(buffer), true);

try {
await ac.destroy();
} catch (e) {}
});

test("Fetching pass non-stringable", async (t) => {
class B {}

let ac = new RemoteAssetCache(new B(), undefined, {
dryRun: true,
});

try {
await ac.fetch();
} catch (e) {
t.is(
e.message,
"Failed to parse URL from [object Object]"
);
t.truthy(e.cause);
}
});


test("formatUrlForDisplay (manual query param removal)", async (t) => {
let finalUrl = "https://example.com/207115/photos/243-0-1.jpg";
let longUrl =
Expand Down

0 comments on commit d7f8755

Please sign in to comment.