Skip to content

Commit

Permalink
- update version
Browse files Browse the repository at this point in the history
- npm publish
- update demo link
  • Loading branch information
zacharygriffee committed Jan 23, 2024
1 parent 55162df commit 86d6cbb
Showing 1 changed file with 40 additions and 37 deletions.
77 changes: 40 additions & 37 deletions tests/adapt.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,52 +218,55 @@ test("readme example of isource", async t => {
t.is(b4a.toString(await yourSource.get("folder/answer")), "42");
});

test("fromRandomAccessStorageCollection", async t => {
const fileObject = {
["snacks.txt"]: new RAM(b4a.from("pretzels, chips, olives, fries")),
["margarita/standard.txt"]: new RAM(b4a.from("tequila, triple sec, sour")),
["margarita/watermelon.txt"]: new RAM(b4a.from("tequila, triple sec, sour, watermelon puree")),
["margarita/golden.txt"]: new RAM(b4a.from("tequila, triple sec, sour, orange juice")),
["margarita/package.json"]: new RAM(b4a.from(`
// Test requires fetch.
if (typeof fetch !== "undefined") {
test("fromRandomAccessStorageCollection", async t => {
const fileObject = {
["snacks.txt"]: new RAM(b4a.from("pretzels, chips, olives, fries")),
["margarita/standard.txt"]: new RAM(b4a.from("tequila, triple sec, sour")),
["margarita/watermelon.txt"]: new RAM(b4a.from("tequila, triple sec, sour, watermelon puree")),
["margarita/golden.txt"]: new RAM(b4a.from("tequila, triple sec, sour, orange juice")),
["margarita/package.json"]: new RAM(b4a.from(`
{
"name": "in-memory-package-json-for-margarita"
}
`))
};
const storeOfStorageInstalls = {};
const source = iSource({
put(k, buf) {
storeOfStorageInstalls[k] = buf;
},
get(k) {
return storeOfStorageInstalls[k];
}
})
const files = await RandomAccessCollection.install("RandomStorage", source);
t.ok(storeOfStorageInstalls.RandomStorage)
};
const storeOfStorageInstalls = {};
const source = iSource({
put(k, buf) {
storeOfStorageInstalls[k] = buf;
},
get(k) {
return storeOfStorageInstalls[k];
}
})
const files = await RandomAccessCollection.install("RandomStorage", source);
t.ok(storeOfStorageInstalls.RandomStorage)

files.setCollection(fileObject);
const howtoMakeWatermelonMargarita = await files.get("margarita/watermelon.txt");
t.alike(howtoMakeWatermelonMargarita, b4a.from("tequila, triple sec, sour, watermelon puree"));
files.setCollection(fileObject);
const howtoMakeWatermelonMargarita = await files.get("margarita/watermelon.txt");
t.alike(howtoMakeWatermelonMargarita, b4a.from("tequila, triple sec, sour, watermelon puree"));

const doWeHaveSnacks = await files.exists("snacks.txt");
const doWeHaveSlashSnacks = await files.exists("/snacks.txt");
const doWeHaveSnacks = await files.exists("snacks.txt");
const doWeHaveSlashSnacks = await files.exists("/snacks.txt");

t.ok(doWeHaveSlashSnacks === doWeHaveSnacks, "Don't need leading slash to be absolute path, but its always recommended.");
t.ok(doWeHaveSlashSnacks === doWeHaveSnacks, "Don't need leading slash to be absolute path, but its always recommended.");

const doWeHaveMartinis = await files.exists("martini.txt");
t.absent(doWeHaveMartinis, "We don't have martinis here.");
const doWeHaveMartinis = await files.exists("martini.txt");
t.absent(doWeHaveMartinis, "We don't have martinis here.");

const [margaritaStandard, nothingElse] = await findDown(files, ["standard*"]);
t.is(margaritaStandard, "/margarita/standard.txt", "This library will coerce file names with root slash.");
t.absent(nothingElse);
const dir = await readdir(files, {recursive: true});
t.is(dir.length, Object.values(fileObject).length, "We just list all files recursively");
const [margaritaHasAJsonFile] = await findPackageJson(files, {cwd: "/margarita/"});
t.is(margaritaHasAJsonFile, "/margarita/package.json", "We found that margarita has a package.json");
const loadJson = await loadPackageJson(files, {cwd: "/margarita/"});
t.is(loadJson.name, "in-memory-package-json-for-margarita", "We can read the json file.");
});
const [margaritaStandard, nothingElse] = await findDown(files, ["standard*"]);
t.is(margaritaStandard, "/margarita/standard.txt", "This library will coerce file names with root slash.");
t.absent(nothingElse);
const dir = await readdir(files, {recursive: true});
t.is(dir.length, Object.values(fileObject).length, "We just list all files recursively");
const [margaritaHasAJsonFile] = await findPackageJson(files, {cwd: "/margarita/"});
t.is(margaritaHasAJsonFile, "/margarita/package.json", "We found that margarita has a package.json");
const loadJson = await loadPackageJson(files, {cwd: "/margarita/"});
t.is(loadJson.name, "in-memory-package-json-for-margarita", "We can read the json file.");
});
}



Expand Down

0 comments on commit 86d6cbb

Please sign in to comment.