Skip to content

Commit d7f8755

Browse files
committed
Fixes #41
1 parent bb9c24b commit d7f8755

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/AssetCache.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ class AssetCache {
3333
}
3434

3535
for (let k of key) {
36-
hash.update(k);
36+
k = ""+k;
37+
if(k) {
38+
hash.update(k);
39+
} else {
40+
throw new Error(`Not able to convert asset key (${k}) to string.`);
41+
}
3742
}
3843

3944
return ("" + hash.digest("hex")).slice(0, hashLength);

test/RemoteAssetCacheTest.js

+30
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,36 @@ test("Fetching (dry run)!", async (t) => {
123123
t.false(ac.hasCacheFiles());
124124
});
125125

126+
test("Fetching pass in URL", async (t) => {
127+
let pngUrl = new URL("https://www.zachleat.com/img/avatar-2017-big.png");
128+
let ac = new RemoteAssetCache(pngUrl);
129+
let buffer = await ac.fetch();
130+
t.is(Buffer.isBuffer(buffer), true);
131+
132+
try {
133+
await ac.destroy();
134+
} catch (e) {}
135+
});
136+
137+
test("Fetching pass non-stringable", async (t) => {
138+
class B {}
139+
140+
let ac = new RemoteAssetCache(new B(), undefined, {
141+
dryRun: true,
142+
});
143+
144+
try {
145+
await ac.fetch();
146+
} catch (e) {
147+
t.is(
148+
e.message,
149+
"Failed to parse URL from [object Object]"
150+
);
151+
t.truthy(e.cause);
152+
}
153+
});
154+
155+
126156
test("formatUrlForDisplay (manual query param removal)", async (t) => {
127157
let finalUrl = "https://example.com/207115/photos/243-0-1.jpg";
128158
let longUrl =

0 commit comments

Comments
 (0)