Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
67 lines (62 loc) · 1.96 KB
/
Copy pathindex.ts
File metadata and controls
67 lines (62 loc) · 1.96 KB
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
import { DynamicExecutor } from "@nestia/e2e";
import { NestFactory } from "@nestjs/core";
import {
ISwagger,
OpenAiComposer,
OpenAiTypeChecker,
} from "@wrtnio/openai-function-schema";
import fs from "fs";
import typia from "typia";
import { TestModule } from "./controllers/TestModule";
import { ITestProps } from "./structures/ITestProps";
import swagger from "./swagger.json";
const main = async (): Promise<void> => {
// PREPARE SERVER
const app = await NestFactory.create(TestModule, { logger: false });
await app.listen(3_000);
// ARCHIVE DOCUMENTS
for (const keyword of [true, false])
await fs.promises.writeFile(
`${__dirname}/../../test/${keyword ? "keyword" : "positional"}.json`,
JSON.stringify(
OpenAiComposer.document({
swagger: typia.assert<ISwagger>(swagger),
options: {
keyword,
separate: (schema) =>
OpenAiTypeChecker.isString(schema) &&
(schema["x-wrtn-secret-key"] !== undefined ||
schema["contentMediaType"] !== undefined),
},
}),
null,
2,
),
"utf8",
);
// DO TEST
const report: DynamicExecutor.IReport = await DynamicExecutor.validate({
prefix: "test_",
parameters: () => [
{
connection: { host: `http://localhost:3000` },
swagger: typia.assert<ISwagger>(swagger),
} satisfies ITestProps,
],
})(__dirname + "/features");
// REPORT EXCEPTIONS
const exceptions: Error[] = report.executions
.filter((exec) => exec.error !== null)
.map((exec) => exec.error!);
if (exceptions.length === 0) {
console.log("Success");
console.log("Elapsed time", report.time.toLocaleString(), `ms`);
} else {
for (const exp of exceptions) console.log(exp);
console.log("Failed");
console.log("Elapsed time", report.time.toLocaleString(), `ms`);
}
await app.close();
if (exceptions.length) process.exit(-1);
};
main().catch(console.error);