From 02fa7aaa1ee5d4bab76916d8afc9d37b162961b1 Mon Sep 17 00:00:00 2001 From: Vladimir Voitenko Date: Mon, 13 Nov 2023 17:30:47 +0500 Subject: [PATCH] packages:js:fix-tests --- packages/js/src/cli/__tests__/genDiff.spec.ts | 8 ++- packages/js/src/cli/__tests__/snippets.ts | 70 +++++++++---------- .../generators/spec/generators/types-gen.ts | 1 + 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/packages/js/src/cli/__tests__/genDiff.spec.ts b/packages/js/src/cli/__tests__/genDiff.spec.ts index 49891be..fff3384 100644 --- a/packages/js/src/cli/__tests__/genDiff.spec.ts +++ b/packages/js/src/cli/__tests__/genDiff.spec.ts @@ -10,7 +10,8 @@ import { formExpectedCode, formYamlContent, loginFieldContent, - passwordFieldContent + passwordFieldContent, + typesExpectedCode } from './snippets' describe('CLI:gen-diff', () => { @@ -18,6 +19,7 @@ describe('CLI:gen-diff', () => { const outputFolder = path.join(os.tmpdir(), 'tech-spec-output-' + uuid4()) const formPath = path.join(outputFolder, 'forms.ts') const designSystemsPath = path.join(outputFolder, 'designs.ts') + const typesPath = path.join(outputFolder, 'types.ts') function saveDesignSystemFile (content: string): void { fs.writeFileSync( @@ -50,6 +52,9 @@ describe('CLI:gen-diff', () => { function saveDesignSystemCodeFile (content: string): void { fs.writeFileSync(designSystemsPath, content) } + function saveTypesCodeFile (content: string): void { + fs.writeFileSync(typesPath, content) + } beforeAll(() => { fs.mkdirSync(techSpecFolder) fs.mkdirSync(outputFolder) @@ -68,6 +73,7 @@ describe('CLI:gen-diff', () => { saveDesignSystemCodeFile(designSystemExpectedCode) saveLoginFieldFile(loginFieldContent) savePasswordFieldFile(passwordFieldContent) + saveTypesCodeFile(typesExpectedCode) const output = await runCLI( `gen-diff ${techSpecFolder} ${outputFolder}` ) diff --git a/packages/js/src/cli/__tests__/snippets.ts b/packages/js/src/cli/__tests__/snippets.ts index fe12db9..62d6be5 100644 --- a/packages/js/src/cli/__tests__/snippets.ts +++ b/packages/js/src/cli/__tests__/snippets.ts @@ -196,23 +196,40 @@ export const designSystemExpectedCode = `export const main = { } as const; ` export const typesExpectedCode = `\ +export const timeFutureType = { + type: "time", + allowOnly: "future" +} as const; +export const priceType = { + type: "float", + min: 0.1, + max: null +} as const; +export const passwordType = { + type: "int", + min: 1, + max: 100 +} as const; +export const loginType = { + type: "string", + regex: /^[\\w_]{4,100}$/ +} as const; export const justDateType = { type: "date", allowOnly: null } as const; +export const futureDateType = { + type: "date", + allowOnly: "future" +} as const; +export const datetimeFutureType = { + type: "datetime", + allowOnly: "future" +} as const; export const cityType = { type: "string", regex: /.{1,30}/ } as const; -export const AnyDocumentType = { - type: "file", - minSize: null, - maxSize: { - value: 500, - unit: "kb" - }, - allowedMimeTypes: null -} as const; export const avatarType = { type: "image", minSize: null, @@ -225,36 +242,19 @@ export const avatarType = { minWidth: null, maxHeight: null, minHeight: null, - aspectRation: { + aspectRatio: { width: 1, height: 1 } } as const; -export const datetimeFutureType = { - type: "datetime", - allowOnly: "future" -} as const; -export const timeFutureType = { - type: "time", - allowOnly: "future" -} as const; -export const futureDateType = { - type: "date", - allowOnly: "future" -} as const; -export const priceType = { - type: "float", - min: 0.1, - max: null -} as const; -export const passwordType = { - type: "int", - min: 1, - max: 100 -} as const; -export const loginType = { - type: "string", - regex: /^[\\w_]{4,100}$/ +export const AnyDocumentType = { + type: "file", + minSize: null, + maxSize: { + value: 500, + unit: "kb" + }, + allowedMimeTypes: null } as const; export const citiesEnumType = { type: "enum", diff --git a/packages/js/src/generators/spec/generators/types-gen.ts b/packages/js/src/generators/spec/generators/types-gen.ts index 5c6e88d..fe214e1 100644 --- a/packages/js/src/generators/spec/generators/types-gen.ts +++ b/packages/js/src/generators/spec/generators/types-gen.ts @@ -32,6 +32,7 @@ export class TypesSpecGenerator extends BaseSpecGenerator { (t): t is [string, ts.ObjectLiteralExpression] => t !== null ) .map(([typeName, typeValue]) => this.genType(typeName, typeValue)) + .sort((t1, t2) => t1.metadata.name.localeCompare(t2.metadata.name)) }