-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.test.ts
80 lines (72 loc) · 1.95 KB
/
compile.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { importFromString } from "module-from-string";
import { resolve } from "path";
import { describe, expect, it } from "vitest";
import typeToSchema from "../src";
import { IMockVitePlugin } from "./mockTypes";
const EXPECTED_SCHEMA_OF_RICH_TYPE = {
$schema: "http://json-schema.org/draft-07/schema#",
additionalProperties: false,
definitions: {
DefinitionLinked: { type: "number" },
},
type: "object",
required: [
"num",
"int",
"str",
"bool",
"arr",
"obj",
// "recursion",
"defInlined",
"defLinked",
"fixedArr",
"nestedArr",
"fixedObj",
],
properties: {
num: { type: "number" },
int: { type: "integer" },
str: { type: "string" },
bool: { type: "boolean" },
arr: { items: {}, type: "array" },
obj: { type: "object" },
optional: { type: "number" },
// recursion: { $ref: "#/definitions/RichType" }, // NOTE: Must be "#"
defInlined: { type: "string" },
defLinked: { $ref: "#/definitions/DefinitionLinked" },
fixedArr: {
type: "array",
items: [{ type: "number" }, { type: "string" }, { type: "boolean" }],
maxItems: 3,
minItems: 3,
},
fixedObj: {
type: "object",
additionalProperties: false,
required: ["fst", "snd", "trd"],
properties: {
fst: { type: "number" },
snd: { type: "string" },
trd: { type: "boolean" },
},
},
nestedArr: {
type: "array",
items: {
type: "array",
items: { type: "number" },
},
},
},
};
describe("compile", () => {
it("RichType have correct schema", async () => {
const plugin = typeToSchema() as IMockVitePlugin;
// Imitate plugin call by Vite
const id: string = resolve(__dirname, "./fixtures/richType?schema");
const build = plugin.load(id);
const moduleOfSchemas = await importFromString(build);
expect(moduleOfSchemas["RichType"]).toEqual(EXPECTED_SCHEMA_OF_RICH_TYPE);
});
});