Skip to content

Commit

Permalink
Merge pull request #397 from cmaster11/example
Browse files Browse the repository at this point in the history
Add a simple `_example` folder in the `_tests_` one that can be easily reused to create new tests
  • Loading branch information
mrjono1 authored Dec 7, 2023
2 parents 99597ea + 552d0ba commit 8b4fb10
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/__tests__/_example/index.ts
Original file line number Diff line number Diff line change
@@ -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;
}
`
);
});
});
5 changes: 5 additions & 0 deletions src/__tests__/_example/schemas/OneSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Joi from 'joi';

export const exampleSchema = Joi.object({
thing: Joi.string().required()
}).meta({ className: 'Example' });

0 comments on commit 8b4fb10

Please sign in to comment.