Skip to content

Commit e3739ba

Browse files
committed
refactor(test): 更新 exampleTest函数以支持多文件输出
- 扩展 exampleTest 函数以接受 PrinterConfigs 参数 - 实现多文件输出,包括主文件、类型文件和 Zod 文件 - 修改文件写入逻辑以适应新的输出结构
1 parent 3f52b56 commit e3739ba

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

test/helpers.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { PrinterConfigs, PrintResults } from '../src';
12
import type { OpenAPILatest } from '../src/types/openapi';
23
import * as crypto from 'node:crypto';
34
import fs from 'node:fs';
@@ -29,13 +30,23 @@ export function createTempDirname() {
2930
] as const;
3031
}
3132

32-
export function exampleTest(version: string, name: string, test: (document: OpenAPILatest.Document) => string) {
33+
export function exampleTest(version: string, name: string, test: (document: OpenAPILatest.Document, configs: PrinterConfigs) => PrintResults) {
3334
const src = path.join(__dirname, 'example-json', version, `${name}.json`);
34-
const dest = path.join(__dirname, 'example-dest', version, `${name}.ts`);
35+
const dir = path.join(__dirname, 'example-dest', version);
3536
const document = fs.readFileSync(src, 'utf8');
36-
const output = test(JSON.parse(document));
37-
const dir = path.dirname(dest);
37+
38+
const mainFile = path.join(dir, `${name}.ts`);
39+
const typeFile = path.join(dir, `${name}.type.ts`);
40+
const zodFile = path.join(dir, `${name}.zod.ts`);
41+
42+
const { main, type, zod } = test(JSON.parse(document), {
43+
mainFile,
44+
typeFile,
45+
zodFile,
46+
});
3847

3948
fs.mkdirSync(dir, { recursive: true });
40-
fs.writeFileSync(dest, output);
49+
fs.writeFileSync(mainFile, main.code);
50+
fs.writeFileSync(typeFile, type.code);
51+
fs.writeFileSync(zodFile, zod.code);
4152
}

0 commit comments

Comments
 (0)