1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:37:35 +00:00

LibJS: Add support for JSON modules

We now have one supported assertion: 'type' if that is 'json' we attempt
to parse the module as JSON.
This commit is contained in:
davidot 2022-01-27 14:51:21 +01:00 committed by Linus Groh
parent 202de6ed25
commit 6b5c882af3
8 changed files with 277 additions and 24 deletions

View file

@ -0,0 +1,34 @@
describe("basic behavior", () => {
test("can import json modules", () => {
let passed = false;
let error = null;
let result = null;
import("./json-module.json", { assert: { type: "json" } })
.then(jsonObj => {
passed = true;
result = jsonObj;
})
.catch(err => {
error = err;
});
runQueuedPromiseJobs();
if (error) throw error;
console.log(JSON.stringify(result));
expect(passed).toBeTrue();
expect(result).not.toBeNull();
expect(result).not.toBeUndefined();
const jsonResult = result.default;
expect(jsonResult).not.toBeNull();
expect(jsonResult).not.toBeUndefined();
expect(jsonResult).toHaveProperty("value", "value");
expect(jsonResult).toHaveProperty("array", [1, 2, 3]);
expect(jsonResult).toHaveProperty("map", { innerValue: "innerValue" });
});
});