-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
25,075 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.cov.lcov | ||
.DS_Store | ||
.test-report.xml | ||
coverage/ | ||
deno.lock | ||
docs/*.css | ||
docs/*.html | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { assertEquals, assertThrows } from "jsr:@std/assert@^0.218.2"; | ||
import { mockDocumentLoader } from "../testing/docloader.ts"; | ||
import { FetchError, kvCache } from "./docloader.ts"; | ||
|
||
Deno.test("new FetchError()", () => { | ||
const e = new FetchError("https://example.com/", "An error message."); | ||
assertEquals(e.name, "FetchError"); | ||
assertEquals(e.url, new URL("https://example.com/")); | ||
assertEquals(e.message, "https://example.com/: An error message."); | ||
|
||
const e2 = new FetchError(new URL("https://example.org/")); | ||
assertEquals(e2.url, new URL("https://example.org/")); | ||
assertEquals(e2.message, "https://example.org/"); | ||
}); | ||
|
||
Deno.test("kvCache()", async (t) => { | ||
const kv = await Deno.openKv(":memory:"); | ||
|
||
await t.step("cached", async () => { | ||
const loader = kvCache({ | ||
kv, | ||
loader: mockDocumentLoader, | ||
rules: [ | ||
["https://example.org/", Temporal.Duration.from({ days: 1 })], | ||
[new URL("https://example.net/"), Temporal.Duration.from({ days: 1 })], | ||
[ | ||
new URLPattern("https://example.com/*"), | ||
Temporal.Duration.from({ days: 30 }), | ||
], | ||
], | ||
prefix: ["_test"], | ||
}); | ||
const result = await loader("https://example.com/object"); | ||
assertEquals(result, { | ||
contextUrl: null, | ||
documentUrl: "https://example.com/object", | ||
document: { | ||
"@context": "https://www.w3.org/ns/activitystreams", | ||
id: "https://example.com/object", | ||
name: "Fetched object", | ||
type: "Object", | ||
}, | ||
}); | ||
const cache = await kv.get(["_test", "https://example.com/object"]); | ||
assertEquals(cache.value, result); | ||
|
||
await kv.set( | ||
["_test", "https://example.com/mock"], | ||
{ | ||
contextUrl: null, | ||
documentUrl: "https://example.com/mock", | ||
document: { | ||
"id": "https://example.com/mock", | ||
}, | ||
}, | ||
); | ||
const result2 = await loader("https://example.com/mock"); | ||
assertEquals(result2, { | ||
contextUrl: null, | ||
documentUrl: "https://example.com/mock", | ||
document: { | ||
"id": "https://example.com/mock", | ||
}, | ||
}); | ||
}); | ||
|
||
await t.step("maximum cache duration", () => { | ||
assertThrows( | ||
() => | ||
kvCache({ | ||
kv, | ||
loader: mockDocumentLoader, | ||
rules: [ | ||
[ | ||
"https://example.com", | ||
Temporal.Duration.from({ days: 30, seconds: 1 }), | ||
], | ||
], | ||
}), | ||
TypeError, | ||
"The maximum cache duration is 30 days", | ||
); | ||
}); | ||
|
||
kv.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"@type": "https://example.com/" | ||
} |
Oops, something went wrong.