1
0

run npm install to generate a package lock

This commit is contained in:
sashinexists
2024-12-07 13:18:31 +11:00
parent e7d08a91b5
commit 23437d228e
2501 changed files with 290663 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import { ObjectTree } from "@weborigami/async-tree";
import assert from "node:assert";
import { describe, test } from "node:test";
import { handleExtension } from "../../src/runtime/handlers.js";
describe("handlers", () => {
test("attaches an unpack method to a value with an extension", async () => {
const fixture = createFixture();
const numberValue = await fixture.get("foo");
assert(typeof numberValue === "number");
assert.equal(numberValue, 1);
const jsonFile = await fixture.get("bar.json");
const withHandler = await handleExtension(fixture, jsonFile, "bar.json");
assert.equal(String(withHandler), `{ "bar": 2 }`);
const data = await withHandler.unpack();
assert.deepEqual(data, { bar: 2 });
});
test("immediately unpacks if key ends in slash", async () => {
const fixture = createFixture();
const jsonFile = await fixture.get("bar.json");
const data = await handleExtension(fixture, jsonFile, "bar.json/");
assert.deepEqual(data, { bar: 2 });
});
});
function createFixture() {
const parent = new ObjectTree({
"json.handler": {
unpack: (buffer) => JSON.parse(String(buffer)),
},
});
let tree = new ObjectTree({
foo: 1, // No extension, should be left alone
"bar.json": `{ "bar": 2 }`,
});
tree.parent = parent;
return tree;
}