From 552d0ba0590bbad78f61e44db05c152ea8cdfec9 Mon Sep 17 00:00:00 2001 From: Alberto Marchetti Date: Thu, 7 Dec 2023 05:28:16 +0200 Subject: [PATCH] Add a simple `_example` folder in the `_tests_` one that can be easily reused to create new tests --- src/__tests__/_example/index.ts | 36 +++++++++++++++++++++ src/__tests__/_example/schemas/OneSchema.ts | 5 +++ 2 files changed, 41 insertions(+) create mode 100644 src/__tests__/_example/index.ts create mode 100644 src/__tests__/_example/schemas/OneSchema.ts diff --git a/src/__tests__/_example/index.ts b/src/__tests__/_example/index.ts new file mode 100644 index 00000000..7cceaefa --- /dev/null +++ b/src/__tests__/_example/index.ts @@ -0,0 +1,36 @@ +import { existsSync, readFileSync, rmdirSync } from 'fs'; + +import { convertFromDirectory } from '../../index'; + +describe('example', () => { + const typeOutputDirectory = './src/__tests__/_example/interfaces'; + + beforeAll(() => { + if (existsSync(typeOutputDirectory)) { + rmdirSync(typeOutputDirectory, { recursive: true }); + } + }); + + test('test example', async () => { + const result = await convertFromDirectory({ + schemaDirectory: './src/__tests__/_example/schemas', + typeOutputDirectory, + sortPropertiesByName: false + }); + + expect(result).toBe(true); + + const oneContent = readFileSync(`${typeOutputDirectory}/One.ts`).toString(); + expect(oneContent).toBe( + `/** + * This file was automatically generated by joi-to-typescript + * Do not modify this file manually + */ + +export interface Example { + thing: string; +} +` + ); + }); +}); diff --git a/src/__tests__/_example/schemas/OneSchema.ts b/src/__tests__/_example/schemas/OneSchema.ts new file mode 100644 index 00000000..1e990120 --- /dev/null +++ b/src/__tests__/_example/schemas/OneSchema.ts @@ -0,0 +1,5 @@ +import Joi from 'joi'; + +export const exampleSchema = Joi.object({ + thing: Joi.string().required() +}).meta({ className: 'Example' });