-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
Copy pathroot.spec.ts
66 lines (61 loc) · 2.33 KB
/
root.spec.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
import { afterAll, beforeAll, describe, it } from "vitest";
import $RefParser, { JSONParserError } from "../../../lib/index.js";
import path from "../../utils/path.js";
import { expect, vi } from "vitest";
import helper from "../../utils/helper";
describe.skipIf(process.env.BROWSER)("Schemas with imports in relative and absolute locations work", () => {
describe("Schemas with relative imports that should be resolved from the root", () => {
beforeAll(() => {
vi.spyOn(process, "cwd").mockImplementation(() => {
return __dirname;
});
});
afterAll(() => {
vi.restoreAllMocks();
});
it("should not parse successfully when set to resolve relative (default)", async () => {
const parser = new $RefParser();
try {
await parser.dereference(path.rel("schemas/accountList.json"));
helper.shouldNotGetCalled();
} catch (err) {
expect(err).to.be.an.instanceOf(JSONParserError);
}
});
it("should parse successfully when set to resolve relative (default)", async () => {
const parser = new $RefParser();
const schema = await parser.dereference(path.rel("schemas/accountList.json"), {
dereference: { externalReferenceResolution: "root" },
});
expect(schema).to.eql(parser.schema);
});
});
describe("Schemas with relative imports that should be resolved relatively", () => {
beforeAll(() => {
vi.spyOn(process, "cwd").mockImplementation(() => {
return __dirname;
});
});
afterAll(() => {
vi.restoreAllMocks();
});
it("should parse successfully when set to resolve relative (default)", async () => {
const parser = new $RefParser();
const schema = await parser.dereference(path.rel("schemas-relative/accountList.json"), {
dereference: { externalReferenceResolution: "relative" },
});
expect(schema).to.eql(parser.schema);
});
it("should not parse successfully when set to resolve relative (default)", async () => {
const parser = new $RefParser();
try {
await parser.dereference(path.rel("schemas-relative/accountList.json"), {
dereference: { externalReferenceResolution: "root" },
});
helper.shouldNotGetCalled();
} catch (err) {
expect(err).to.be.an.instanceOf(JSONParserError);
}
});
});
});