Skip to content

Commit e35d4ea

Browse files
authored
Move schema into source directory (#2)
Use parser validate in examples test
1 parent c308f7b commit e35d4ea

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

src/examples.spec.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
import { readdirSync, readFileSync } from "node:fs";
22
import { dirname, join } from "node:path";
33
import { fileURLToPath } from "node:url";
4-
import Ajv from "ajv";
54
import { describe, expect, it } from "vitest";
5+
import { validate } from "./parser";
66

77
const base = dirname(fileURLToPath(import.meta.url));
88
const examplesDir = join(base, "../examples");
9-
const schema = JSON.parse(
10-
readFileSync(join(base, "../scene.schema.json"), "utf8"),
11-
);
12-
13-
const ajv = new Ajv();
14-
const validate = ajv.compile(schema);
159

1610
describe("example json files", () => {
1711
for (const file of readdirSync(examplesDir)) {
1812
if (!file.endsWith(".json")) continue;
1913
it(`validates ${file}`, () => {
2014
const data = JSON.parse(readFileSync(join(examplesDir, file), "utf8"));
21-
expect(validate(data)).toBe(true);
15+
expect(() => validate(data)).not.toThrow();
2216
});
2317
}
2418
});

src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type AnyNode = {
3434

3535
const schemaPath = join(
3636
dirname(fileURLToPath(import.meta.url)),
37-
"../scene.schema.json",
37+
"scene.schema.json",
3838
);
3939
const schema = JSON.parse(readFileSync(schemaPath, "utf8"));
4040
const ajv = new Ajv();
File renamed without changes.

0 commit comments

Comments
 (0)