deno.land / x / wasm@wasmer-sdk-v0.6.0 / tests / directory.test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import { expect } from "@esm-bundle/chai";import { init, initializeLogger, Directory } from "..";
const decoder = new TextDecoder("utf-8");const encoder = new TextEncoder();
const initialized = (async () => { await init(new URL("../dist/wasmer_js_bg.wasm", import.meta.url)); initializeLogger("warn");})();
describe("In-Memory Directory", function () { this.beforeAll(async () => await initialized);
it("read empty dir", async () => { const dir = new Directory();
const contents = await dir.readDir("/");
expect(contents.length).to.equal(0); });
it("can round-trip a file", async () => { const dir = new Directory();
await dir.writeFile("/file.txt", encoder.encode("Hello, World!")); const contents = await dir.readFile("/file.txt");
expect(decoder.decode(contents)).to.equal("Hello, World!"); });
it("read dir with file", async () => { const dir = new Directory();
await dir.writeFile("/file.txt", new Uint8Array()); const contents = await dir.readDir("/");
expect(contents).to.deep.equal([{ name: "file.txt", type: "file" }]); });
it("create child dir", async () => { const dir = new Directory();
await dir.createDir("/tmp/");
expect(await dir.readDir("/")).to.deep.equal([ { name: "tmp", type: "dir" }, ]); });
it("can be created with DirectoryInit", async () => { const dir = new Directory({ "/file.txt": "file", "/another/nested/file.txt": "another", });
expect(await dir.readTextFile("/file.txt")).to.equal("file"); expect(await dir.readTextFile("/another/nested/file.txt")).to.equal( "another", ); });});
Version Info