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:
parent
202de6ed25
commit
6b5c882af3
8 changed files with 277 additions and 24 deletions
34
Userland/Libraries/LibJS/Tests/modules/json-modules.js
Normal file
34
Userland/Libraries/LibJS/Tests/modules/json-modules.js
Normal 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" });
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue