@paima/schema2typebox
Version:
Creates typebox code from JSON schemas
46 lines • 2.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const globals_1 = require("@jest/globals");
const node_fs_1 = require("node:fs");
const index_1 = require("../src/index");
const util_1 = require("./util");
(0, globals_1.describe)("when testing against real world schemas", () => {
(0, globals_1.test)("works for schema.org - dayOfWeek", async () => {
const inputSchema = (0, node_fs_1.readFileSync)((0, util_1.buildOsIndependentPath)([
process.cwd(),
..."test/fixture/dayOfWeek.json".split("/"),
]), "utf-8");
const result = await (0, index_1.schema2typebox)({ input: inputSchema });
const expectedResult = (0, node_fs_1.readFileSync)((0, util_1.buildOsIndependentPath)([
process.cwd(),
..."test/fixture/dayOfWeek.ts".split("/"),
]), "utf-8");
await (0, util_1.expectEqualIgnoreFormatting)(result, expectedResult);
});
(0, globals_1.test)("works for recursive", async () => {
const originalCwd = process.cwd();
process.chdir((0, util_1.buildOsIndependentPath)([process.cwd(), "test", "fixture"]));
try {
const inputSchema = (0, node_fs_1.readFileSync)("recursive.json", "utf-8");
const result = await (0, index_1.schema2typebox)({ input: inputSchema });
const expectedResult = (0, node_fs_1.readFileSync)("recursive.ts", "utf-8");
await (0, util_1.expectEqualIgnoreFormatting)(result, expectedResult);
}
finally {
process.chdir(originalCwd);
}
});
(0, globals_1.test)("works for nested", async () => {
const inputSchema = (0, node_fs_1.readFileSync)((0, util_1.buildOsIndependentPath)([
process.cwd(),
..."test/fixture/multi.json".split("/"),
]), "utf-8");
const result = await (0, index_1.schema2typebox)({ input: inputSchema });
const expectedResult = (0, node_fs_1.readFileSync)((0, util_1.buildOsIndependentPath)([
process.cwd(),
..."test/fixture/multi.ts".split("/"),
]), "utf-8");
await (0, util_1.expectEqualIgnoreFormatting)(result, expectedResult);
});
});
//# sourceMappingURL=schema.spec.js.map