Skip to content

Commit

Permalink
packages:js:fix-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Voldemat committed Nov 13, 2023
1 parent 082e83f commit 02fa7aa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
8 changes: 7 additions & 1 deletion packages/js/src/cli/__tests__/genDiff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import {
formExpectedCode,
formYamlContent,
loginFieldContent,
passwordFieldContent
passwordFieldContent,
typesExpectedCode
} from './snippets'

describe('CLI:gen-diff', () => {
const techSpecFolder = path.join(os.tmpdir(), 'tech-spec-' + uuid4())
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(
Expand Down Expand Up @@ -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)
Expand All @@ -68,6 +73,7 @@ describe('CLI:gen-diff', () => {
saveDesignSystemCodeFile(designSystemExpectedCode)
saveLoginFieldFile(loginFieldContent)
savePasswordFieldFile(passwordFieldContent)
saveTypesCodeFile(typesExpectedCode)
const output = await runCLI(
`gen-diff ${techSpecFolder} ${outputFolder}`
)
Expand Down
70 changes: 35 additions & 35 deletions packages/js/src/cli/__tests__/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/js/src/generators/spec/generators/types-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class TypesSpecGenerator extends BaseSpecGenerator<Type> {
(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))
}

Expand Down

0 comments on commit 02fa7aa

Please sign in to comment.