Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple _example folder in the _tests_ one that can be easily reused to create new tests #397

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' });