-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathgithub-discussion-schema.test.mjs
42 lines (34 loc) · 1.1 KB
/
github-discussion-schema.test.mjs
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
import { expect, use } from "chai";
import chaiJsonSchema from "chai-json-schema";
import fs from "fs";
import { describe, it } from "node:test";
import path, { join } from "path";
import stripJsonComments from "strip-json-comments";
import yaml from "yaml";
const cwd = process.cwd();
const SCHEMA_FILE = join(cwd, "schemas/discussion-data.yaml");
const GH_DATA = join(
cwd,
process.env.DATA_REPO ?? "data-repo",
"data/github/discussions",
);
const schema = await yaml.parse(fs.readFileSync(SCHEMA_FILE).toString());
use(chaiJsonSchema);
if (!fs.existsSync(GH_DATA)) {
console.log(
`Directory ${GH_DATA} does not exist. Skipping discussions test.`,
);
process.exit(0);
}
const filesInDir = fs
.readdirSync(GH_DATA)
.filter((file) => path.extname(file) === ".json");
filesInDir.forEach((file) => {
const content = fs.readFileSync(join(GH_DATA, file)).toString();
const data = JSON.parse(stripJsonComments(content));
describe(`Validate '${file}'`, function () {
it("should be properly validated by the json schema", () => {
expect(data).to.be.jsonSchema(schema);
});
});
});