-
-
Notifications
You must be signed in to change notification settings - Fork 387
/
Copy pathbasic.test.js
65 lines (54 loc) · 1.68 KB
/
basic.test.js
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
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { generateApi } from "../../../src/index.js";
describe("basic", async () => {
let tmpdir = "";
beforeAll(async () => {
tmpdir = await fs.mkdtemp(path.join(os.tmpdir(), "swagger-typescript-api"));
});
afterAll(async () => {
await fs.rm(tmpdir, { recursive: true });
});
test("--extra-templates", async () => {
await generateApi({
name: "schema",
input: path.resolve(import.meta.dirname, "schema.json"),
output: tmpdir,
silent: true,
extraTemplates: [
{
name: "external-template-name",
path: path.resolve(import.meta.dirname, "./templates/test.ejs")
},
],
});
const content = await fs.readFile(path.join(tmpdir, "external-template-name.ts"), {
encoding: "utf8",
});
expect(content).toMatchSnapshot();
});
test("--extra-templates-route", async () => {
await generateApi({
name: "schema",
input: path.resolve(import.meta.dirname, "schema.json"),
output: tmpdir,
silent: true,
extraTemplates: [
{
name: (config)=>{
console.log(config.route.moduleName)
return `contexts/${config.route.moduleName}Context`
},
path: path.resolve(import.meta.dirname, "./templates/test-route.ejs"),
modular: true
},
],
});
const content = await fs.readFile(path.join(tmpdir, "contexts/wrongPathParams1Context.ts"), {
encoding: "utf8",
});
expect(content).toMatchSnapshot();
});
});