How to use fileContent method in storybook-root

Best JavaScript code snippet using storybook-root

generate-sdk.ts

Source:generate-sdk.ts Github

copy

Full Screen

1import fs from 'fs';2import { capitalizeFirst, uncapitalizeFirst } from '../src/meta/utils';3import * as meta from '../src/meta';4function main() {5 generateModelsTs();6 generateInputModelsTs();7 generateOutputModelsTs();8 generateFromInputToOutputClasses();9 generateFromInputClasses();10 generateShortcuts();11 generateGladiaClient();12 generateUnitTests();13}14function generateModelsTs() {15 const fileContent: string[] = [...getGeneratedMarks()];16 const endpoints = meta.getEndpoints();17 for (const endpoint of endpoints) {18 const typeName = meta.getModelTypeName(endpoint);19 const contentTypeName = meta.getContentTypeName(endpoint);20 const modelValuesName = meta.getModelValuesName(endpoint);21 fileContent.push(`export const ${modelValuesName} = [`);22 endpoint.models.map((model) => ` '${model}',`).forEach((model) => fileContent.push(model));23 fileContent.push('] as const;');24 fileContent.push(25 `export const ${contentTypeName} = "${endpoint.inputBodyContentType}" as const;`,26 );27 fileContent.push(`export type ${typeName} = typeof ${modelValuesName}[number];`);28 fileContent.push('');29 }30 fs.writeFileSync('./src/models.ts', fileContent.join('\n'));31}32function generateInputModelsTs() {33 const fileContent: string[] = [...getGeneratedMarks()];34 const endpoints = meta.getEndpoints();35 fileContent.push('import {');36 for (const endpoint of endpoints) {37 fileContent.push(` ${meta.getModelTypeName(endpoint)},`);38 }39 fileContent.push(`} from '../models';`);40 fileContent.push(`import { WithHeaders, WithModel } from './types';`);41 fileContent.push('');42 for (const endpoint of endpoints) {43 const inputModelName = meta.getInputModelType(endpoint);44 const modelTypeName = meta.getModelTypeName(endpoint);45 fileContent.push(`export interface ${inputModelName} `);46 fileContent.push(` extends WithHeaders, WithModel<${modelTypeName}> {`);47 endpoint.params.forEach((param) => {48 const optionalMark = param.required ? '' : '?';49 const paramType = (() => {50 switch (param.type) {51 case 'string':52 return 'string';53 case 'audio':54 case 'image':55 return 'Blob';56 case 'integer':57 case 'float':58 return 'number';59 case 'array':60 return 'string[]';61 default:62 return 'string';63 }64 })();65 fileContent.push(` ${param.name}${optionalMark}: ${paramType};`);66 });67 fileContent.push(`}`);68 }69 fs.writeFileSync('./src/client/input-models.ts', fileContent.join('\n'));70}71function generateOutputModelsTs() {72 const fileContent: string[] = [...getGeneratedMarks()];73 const endpoints = meta.getEndpoints();74 for (const endpoint of endpoints) {75 const outputModelName = meta.getOutputModelType(endpoint);76 const outputBodyContentType = endpoint.outputBodyContentType;77 switch (outputBodyContentType.type) {78 case 'prediction-standard-output':79 const predictionType = (() => {80 if (outputBodyContentType.predictionType === 'array') {81 return 'string[]';82 }83 return outputBodyContentType.predictionType;84 })();85 fileContent.push(`export type ${outputModelName} = {`);86 fileContent.push(` prediction: ${predictionType},`);87 fileContent.push(` prediction_raw: any,`);88 fileContent.push(`};`);89 break;90 case 'unknown':91 fileContent.push(92 `export type ${outputModelName} = Record<string, string | number | boolean>;`,93 );94 break;95 case 'binary':96 fileContent.push(`export type ${outputModelName} = ArrayBuffer;`);97 break;98 default:99 throw { kind: 'UnknownOutputType', outputType: endpoint.outputType };100 }101 }102 fs.writeFileSync('./src/client/output-models.ts', fileContent.join('\n'));103}104function generateFromInputToOutputClasses() {105 const endpoints = meta.getEndpointsByInputOutput();106 for (const [inputType, outputs] of Object.entries(endpoints)) {107 for (const [outputType, outputTypeEndpoints] of Object.entries(outputs)) {108 const fileContent: string[] = [...getGeneratedMarks()];109 fileContent.push(`import {`);110 for (const endpoint of outputTypeEndpoints) {111 const inputModelClassName = meta.getInputModelType(endpoint);112 fileContent.push(` ${inputModelClassName},`);113 }114 fileContent.push(`} from './input-models';`);115 fileContent.push(`import {`);116 for (const endpoint of outputTypeEndpoints) {117 const outputModelClassName = meta.getOutputModelType(endpoint);118 fileContent.push(` ${outputModelClassName},`);119 }120 fileContent.push(`} from './output-models';`);121 fileContent.push(`import {`);122 for (const endpoint of outputTypeEndpoints) {123 fileContent.push(` ${meta.getContentTypeName(endpoint)},`);124 }125 fileContent.push(`} from '../models';`);126 const importUrlFormData = outputTypeEndpoints.some(isEndpointNeedUrlFormData);127 fileContent.push(`import { getHttpClient, HttpClient } from '../internal/http-client';`);128 const shouldImportIsDefined = outputTypeEndpoints.some((endpoints) =>129 endpoints.params.some((param) => !param.required),130 );131 if (shouldImportIsDefined) {132 fileContent.push(`import { isDefined } from '../utils/fp';`);133 }134 if (importUrlFormData) {135 fileContent.push(`import { UrlFormData } from '../internal/url-form-data';`);136 }137 fileContent.push(`import { GladiaClientParams } from './gladia-client-params';`);138 fileContent.push('');139 fileContent.push(`export class ${getClientInputOutputClassName(inputType, outputType)} {`);140 fileContent.push(' private httpClient: HttpClient;');141 fileContent.push('');142 fileContent.push(' constructor(private params: GladiaClientParams) {');143 fileContent.push(' this.httpClient = getHttpClient(this.params);');144 fileContent.push(' }');145 fileContent.push('');146 for (const endpoint of outputTypeEndpoints) {147 const methodName = meta.getMethodName(endpoint);148 const inputModelType = meta.getInputModelType(endpoint);149 const outputModelType = meta.getOutputModelType(endpoint);150 fileContent.push(` ${methodName}(args: ${inputModelType}): Promise<${outputModelType}> {`);151 switch (inputType) {152 case 'text':153 case 'audio':154 case 'image':155 const useUrlFormData = isEndpointNeedUrlFormData(endpoint);156 if (useUrlFormData) {157 fileContent.push(` const formData = new UrlFormData();`);158 } else {159 fileContent.push(` const formData = new FormData();`);160 }161 for (const param of endpoint.params.filter((p) => p.in === 'formData')) {162 const argValue =163 param.type === 'integer' || param.type === 'float'164 ? `String(args.${param.name})`165 : `args.${param.name}`;166 if (param.required) {167 fileContent.push(` formData.append('${param.name}', ${argValue});`);168 } else {169 fileContent.push(` if (isDefined(args.${param.name})) {`);170 fileContent.push(` formData.append('${param.name}', ${argValue});`);171 fileContent.push(` }`);172 }173 }174 fileContent.push(` return this.httpClient.post({`);175 fileContent.push(` url: '${endpoint.url}',`);176 if (useUrlFormData) {177 fileContent.push(` headers: {`);178 fileContent.push(` 'Content-Type': ${meta.getContentTypeName(endpoint)},`);179 fileContent.push(` ...(args.headers ?? {}),`);180 fileContent.push(` },`);181 } else {182 // this enforce the browser to compute it self the Content-Type with correct boundary183 // this give something like:184 // Content-Type: multipart/form-data; boundary=---------------------------412830277717200702261256384337185 fileContent.push(` headers: {`);186 const contentTypeName = meta.getContentTypeName(endpoint);187 fileContent.push(188 ` 'Content-Type': this.params.useFetch ? ${contentTypeName} : undefined,`,189 );190 fileContent.push(` ...(args.headers ?? {}),`);191 fileContent.push(` },`);192 }193 fileContent.push(` query: {`);194 fileContent.push(` ...(args.model ? {model: args.model} : {}),`);195 for (const param of endpoint.params.filter((p) => p.in === 'query')) {196 const argValue =197 param.type === 'integer' || param.type === 'float'198 ? `String(args.${param.name})`199 : `args.${param.name}`;200 fileContent.push(` ${param.name}: ${argValue},`);201 }202 fileContent.push(` },`);203 if (endpoint.outputType !== 'text') {204 fileContent.push(` responseType: 'arraybuffer',`);205 }206 if (useUrlFormData) {207 fileContent.push(` body: formData.toString(),`);208 } else {209 fileContent.push(` body: formData,`);210 }211 fileContent.push(` });`);212 break;213 default:214 throw { kind: 'UnknownInputType', inputType };215 }216 fileContent.push(` }`);217 fileContent.push('');218 }219 fileContent.push('}');220 fileContent.push('');221 const outputFileName = getClientInputOutput(inputType, outputType);222 fs.writeFileSync(`./src/client/${outputFileName}.ts`, fileContent.join('\n'));223 }224 }225}226function isEndpointNeedUrlFormData(endpoint: meta.EndpointDef): boolean {227 return endpoint.inputBodyContentType === 'application/x-www-form-urlencoded';228}229function generateFromInputClasses() {230 const endpoints = meta.getEndpointsByInputOutput();231 for (const [inputType, outputs] of Object.entries(endpoints)) {232 const fileContent: string[] = [...getGeneratedMarks()];233 for (const outputType of Object.keys(outputs)) {234 const className = getClientInputOutputClassName(inputType, outputType);235 const fileName = getClientInputOutput(inputType, outputType);236 fileContent.push(`import { ${className} } from './${fileName}';`);237 }238 fileContent.push(`import { GladiaClientParams } from './gladia-client-params';`);239 fileContent.push('');240 fileContent.push(`export class ${getClientInputClassName(inputType)} {`);241 for (const outputType of Object.keys(outputs)) {242 const className = getClientInputOutputClassName(inputType, outputType);243 const memberName = getClientOutputMemberName(inputType, outputType);244 fileContent.push(` private ${memberName}: ${className};`);245 }246 fileContent.push('');247 fileContent.push(` constructor(params: GladiaClientParams) {`);248 for (const outputType of Object.keys(outputs)) {249 const className = getClientInputOutputClassName(inputType, outputType);250 const memberName = getClientOutputMemberName(inputType, outputType);251 fileContent.push(` this.${memberName} = new ${className}(params);`);252 }253 fileContent.push(' }');254 fileContent.push('');255 for (const outputType of Object.keys(outputs)) {256 const methodName = getClientOutputMethodName(outputType);257 const memberName = getClientOutputMemberName(inputType, outputType);258 fileContent.push(` ${methodName}() {`);259 fileContent.push(` return this.${memberName};`);260 fileContent.push(` }`);261 fileContent.push('');262 }263 fileContent.push('}');264 fileContent.push('');265 const inputFileName = getClientInput(inputType);266 fs.writeFileSync(`./src/client/${inputFileName}.ts`, fileContent.join('\n'));267 }268}269function generateShortcuts() {270 const endpointsByInputOutput = meta.getEndpointsByInputOutput();271 const endpoints = meta.getEndpoints();272 const fileContent: string[] = [...getGeneratedMarks()];273 for (const [inputType, outputs] of Object.entries(endpointsByInputOutput)) {274 fileContent.push(275 `import { ${getClientInputClassName(inputType)} } from './${getClientInput(inputType)}'`,276 );277 for (const outputType of Object.keys(outputs)) {278 const inputOutputClassName = getClientInputOutputClassName(inputType, outputType);279 const inputOutputFileName = getClientInputOutput(inputType, outputType);280 fileContent.push(`import { ${inputOutputClassName} } from './${inputOutputFileName}'`);281 }282 }283 fileContent.push(`import {`);284 for (const endpoint of endpoints) {285 const inputModelClassName = meta.getInputModelType(endpoint);286 fileContent.push(` ${inputModelClassName},`);287 }288 fileContent.push(`} from './input-models'`);289 fileContent.push('');290 fileContent.push(`export abstract class Shortcuts implements`);291 const implemented: string[] = [];292 for (const [inputType, outputs] of Object.entries(endpointsByInputOutput)) {293 for (const outputType of Object.keys(outputs)) {294 const inputOutputClassName = getClientInputOutputClassName(inputType, outputType);295 implemented.push(` Omit<${inputOutputClassName}, 'httpClient'>`);296 }297 }298 const lastImplemented = implemented.pop();299 implemented.forEach((i) => fileContent.push(`${i},`));300 fileContent.push(lastImplemented!);301 fileContent.push(`{`);302 fileContent.push('');303 for (const [inputType, outputs] of Object.entries(endpointsByInputOutput)) {304 const fromMethod = getClientInputMethodName(inputType);305 fileContent.push(` abstract ${fromMethod}(): ${getClientInputClassName(inputType)};`);306 fileContent.push('');307 for (const [outputType, outputTypeEndpoints] of Object.entries(outputs)) {308 fileContent.push(` // ${inputType.toUpperCase()} => ${outputType.toUpperCase()}`);309 fileContent.push('');310 const toMethod = getClientOutputMethodName(outputType);311 for (const endpoint of outputTypeEndpoints) {312 const methodName = meta.getMethodName(endpoint);313 const inputModelClassName = meta.getInputModelType(endpoint);314 fileContent.push(` ${methodName}(args: ${inputModelClassName}) {`);315 fileContent.push(` return this.${fromMethod}().${toMethod}().${methodName}(args);`);316 fileContent.push(` }`);317 fileContent.push('');318 }319 }320 }321 fileContent.push(`}`);322 fileContent.push('');323 fs.writeFileSync('./src/client/shortcuts.ts', fileContent.join('\n'));324}325function generateGladiaClient() {326 const fileContent: string[] = [...getGeneratedMarks()];327 const endpoints = meta.getEndpointsByInputOutput();328 fileContent.push(`import { GladiaClientParams } from './client/gladia-client-params';`);329 fileContent.push(`import { Shortcuts } from './client/shortcuts';`);330 for (const inputType of Object.keys(endpoints)) {331 fileContent.push(332 `import { ${getClientInputClassName(inputType)} } from './client/${getClientInput(333 inputType,334 )}';`,335 );336 }337 fileContent.push('');338 fileContent.push('export class GladiaClient extends Shortcuts {');339 for (const inputType of Object.keys(endpoints)) {340 fileContent.push(341 ` private ${getClientInputMemberName(inputType)}: ${getClientInputClassName(inputType)};`,342 );343 }344 fileContent.push('');345 fileContent.push(' constructor(params: GladiaClientParams) {');346 fileContent.push(' super();');347 fileContent.push(` const validatedParams: GladiaClientParams = {`);348 fileContent.push(` ...params,`);349 fileContent.push(` useFetch: params.useFetch ?? false,`);350 fileContent.push(` }`);351 for (const inputType of Object.keys(endpoints)) {352 fileContent.push(353 ` this.${getClientInputMemberName(inputType)} = new ${getClientInputClassName(354 inputType,355 )}(validatedParams);`,356 );357 }358 fileContent.push(' }');359 fileContent.push('');360 for (const inputType of Object.keys(endpoints)) {361 fileContent.push(` ${getClientInputMethodName(inputType)}() {`);362 fileContent.push(` return this.${getClientInputMemberName(inputType)};`);363 fileContent.push(` }`);364 fileContent.push('');365 }366 fileContent.push('}');367 fileContent.push('');368 fs.writeFileSync('./src/gladia-client.ts', fileContent.join('\n'));369}370function generateUnitTests() {371 const endpointsByInputOutput = meta.getEndpointsByInputOutput();372 for (const [inputType, outputs] of Object.entries(endpointsByInputOutput)) {373 const fromMethod = getClientInputMethodName(inputType);374 for (const [outputType, outputTypeEndpoints] of Object.entries(outputs)) {375 const toMethod = getClientOutputMethodName(outputType);376 const fileContent = [...getGeneratedMarks()];377 const inputOutputClassName = getClientInputOutputClassName(inputType, outputType);378 const inputOutputFileName = getClientInputOutput(inputType, outputType);379 fileContent.push(`import { GladiaClient } from '../src/gladia-client';`);380 fileContent.push(`import gladia from '../src/index';`);381 fileContent.push(`import { HttpClient } from '../src/internal/http-client';`);382 const helperMocks = getHelperMockList(outputTypeEndpoints);383 fileContent.push(384 `import { ${385 helperMocks.length === 0 ? '' : helperMocks + ', '386 }getPostMock, mockHttpClient } from './helpers/mocks';`,387 );388 fileContent.push('');389 fileContent.push(`describe('${inputOutputClassName}', () => {`);390 for (const endpoint of outputTypeEndpoints) {391 const methodName = meta.getMethodName(endpoint);392 fileContent.push(` describe('${methodName}', () => {`);393 fileContent.push(` let gladiaClient: GladiaClient;`);394 fileContent.push(` let httpClientMock: HttpClient;`);395 fileContent.push('');396 fileContent.push(` beforeEach(() => {`);397 fileContent.push(398 ` gladiaClient = gladia({ apiKey: 'API-KEY', customHttpClient: mockHttpClient() });`,399 );400 fileContent.push(401 ` httpClientMock = gladiaClient.${fromMethod}().${toMethod}()['httpClient'];`,402 );403 fileContent.push(` });`);404 fileContent.push('');405 for (const mode of ['full path', 'shortcuts'] as const) {406 fileContent.push(` describe('${mode}', () => {`);407 const callPath = getCallPath({ mode, fromMethod, toMethod, methodName });408 fileContent.push(409 ` it('should call the api with the text and the default model by default', async () => {`,410 );411 fileContent.push(...generateTestInputs(callPath, endpoint));412 fileContent.push(...generateTestAssertions(endpoint));413 fileContent.push(` });`);414 fileContent.push(415 ` it('should call the api with the text and the specified model', async () => {`,416 );417 const specifiedModel = getAnyModelExceptDefault(endpoint);418 fileContent.push(...generateTestInputs(callPath, endpoint, specifiedModel));419 fileContent.push(...generateTestAssertions(endpoint, specifiedModel));420 fileContent.push(` });`);421 fileContent.push(` });`);422 }423 fileContent.push(` });`);424 fileContent.push('');425 }426 fileContent.push(`});`);427 const fileName = `./tests/${inputOutputFileName}.spec.ts`;428 fs.writeFileSync(fileName, fileContent.join('\n'));429 }430 }431}432function getGeneratedMarks(): string[] {433 return ['/* Generated file with "scripts/generate-sdk.ts" */', ''];434}435function getClientInput(inputType: string): string {436 return `from-${inputType.toLowerCase()}`;437}438function getClientInputClassName(inputType: string): string {439 return `From${capitalizeFirst(inputType)}`;440}441function getClientInputMemberName(inputType: string): string {442 return `${uncapitalizeFirst(getClientInputClassName(inputType))}Inst`;443}444function getClientInputMethodName(inputType: string): string {445 return uncapitalizeFirst(getClientInputClassName(inputType));446}447function getClientInputOutput(inputType: string, outputType: string): string {448 return `from-${inputType.toLowerCase()}-to-${outputType.toLowerCase()}`;449}450function getClientInputOutputClassName(inputType: string, outputType: string): string {451 return `From${capitalizeFirst(inputType)}To${capitalizeFirst(outputType)}`;452}453function getClientOutputMemberName(inputType: string, outputType: string): string {454 return `${uncapitalizeFirst(getClientInputOutputClassName(inputType, outputType))}Inst`;455}456function getClientOutputMethodName(outputType: string): string {457 return `to${capitalizeFirst(outputType)}`;458}459function getAnyModelExceptDefault(endpoint: meta.EndpointDef): string {460 if (endpoint.models.length === 1) {461 return 'fake-model-name';462 } else {463 return endpoint.models.filter((m) => m !== endpoint.defaultModel)[0];464 }465}466interface GetCallPath {467 mode: 'full path' | 'shortcuts';468 fromMethod: string;469 toMethod: string;470 methodName: string;471}472function getCallPath({ mode, fromMethod, toMethod, methodName }: GetCallPath) {473 switch (mode) {474 case 'full path':475 return `${fromMethod}().${toMethod}().${methodName}`;476 case 'shortcuts':477 return methodName;478 }479}480function getEndpointsParamTypes(endpoints: meta.EndpointDef[]): meta.EndpointDefParam['type'][] {481 const allTypes = endpoints.flatMap((endpoint) => endpoint.params.map((param) => param.type));482 return [...new Set(allTypes)];483}484function getHelperMockList(endpoints: meta.EndpointDef[]) {485 return getEndpointsParamTypes(endpoints)486 .map((type) => {487 switch (type) {488 case 'integer':489 return 'getRandomInt';490 case 'float':491 return 'getRandomFloat';492 case 'array':493 return 'getRandomArray';494 default:495 return 'getRandomText';496 }497 })498 .reduce((all: string[], current: string) => {499 if (all.includes(current)) {500 return all;501 } else {502 return [...all, current];503 }504 }, [])505 .sort()506 .join(', ');507}508function generateTestInputs(509 callPath: string,510 endpoint: meta.EndpointDef,511 specifyModel?: string,512): string[] {513 const fileContent: string[] = [];514 for (const param of endpoint.params) {515 switch (param.type) {516 case 'integer':517 fileContent.push(` const ${param.name}_data = getRandomInt();`);518 break;519 case 'float':520 fileContent.push(` const ${param.name}_data = getRandomFloat();`);521 break;522 case 'audio':523 case 'image':524 fileContent.push(` const ${param.name}_data = new Blob([getRandomText()]);`);525 break;526 case 'array':527 fileContent.push(` const ${param.name}_data = getRandomArray();`);528 break;529 case 'string':530 case 'url':531 default:532 fileContent.push(` const ${param.name}_data = getRandomText();`);533 break;534 }535 }536 fileContent.push(` const result = await gladiaClient.${callPath}({`);537 for (const param of endpoint.params) {538 fileContent.push(` ${param.name}: ${param.name}_data,`);539 }540 if (specifyModel) {541 fileContent.push(` model: '${specifyModel}' as any,`);542 }543 fileContent.push(` });`);544 return fileContent;545}546function generateTestAssertions(endpoint: meta.EndpointDef, specifyModel?: string) {547 const fileContent: string[] = [];548 fileContent.push(549 ` const { postMock, firstCallArgs, firstCallBody } = getPostMock(httpClientMock);`,550 );551 fileContent.push(` expect(postMock).toHaveBeenCalledTimes(1);`);552 fileContent.push(` expect(firstCallArgs.url).toEqual('${endpoint.url}');`);553 fileContent.push(` expect(firstCallArgs.headers).toEqual({`);554 if (isEndpointNeedUrlFormData(endpoint)) {555 fileContent.push(` 'Content-Type': '${endpoint.inputBodyContentType}',`);556 } else {557 fileContent.push(` 'Content-Type': undefined,`);558 }559 fileContent.push(` });`);560 if (endpoint.outputType !== 'text') {561 fileContent.push(` expect(firstCallArgs.responseType).toEqual('arraybuffer');`);562 }563 fileContent.push(` expect(firstCallArgs.query).toEqual({`);564 if (specifyModel) {565 fileContent.push(` model: '${specifyModel}',`);566 }567 for (const param of endpoint.params.filter((p) => p.in === 'query')) {568 fileContent.push(` ${param.name}: ${param.name}_data,`);569 }570 fileContent.push(` });`);571 for (const param of endpoint.params.filter((p) => p.in === 'formData')) {572 switch (param.type) {573 case 'audio':574 case 'image':575 fileContent.push(` expect(firstCallBody.get('${param.name}')).toBeDefined();`);576 break;577 case 'integer':578 case 'float':579 fileContent.push(580 ` expect(firstCallBody.get('${param.name}')).toEqual(String(${param.name}_data));`,581 );582 break;583 case 'string':584 case 'url':585 case 'array':586 default:587 fileContent.push(588 ` expect(firstCallBody.get('${param.name}')).toEqual(${param.name}_data);`,589 );590 break;591 }592 }593 return fileContent;594}...

Full Screen

Full Screen

entity.spec.js

Source:entity.spec.js Github

copy

Full Screen

...70 assert.file(`${SERVER_NODEJS_DIR}src/service/mapper/foo.mapper.ts`);71 assert.file(`${SERVER_NODEJS_DIR}src/web/rest/foo.controller.ts`);72 const testControllerPath = `${SERVER_NODEJS_DIR}e2e/foo.e2e-spec.ts`;73 assert.file(testControllerPath);74 assert.fileContent(testControllerPath, 'FooService');75 });76 });77 describe('2-GreatEntity json entity with fields test', () => {78 before(done => {79 getPreCondition()80 .withArguments(['GreatEntity'])81 .withPrompts({})82 .on('end', done);83 });84 it('does creates entity file with enum and fields validated', () => {85 // Adds your tests here86 assert.file('.jhipster/GreatEntity.json');87 // test entity-client removed id primary key88 const entityReactPath = `${REACT_DIR}entities/great-entity/great-entity.tsx`;89 assert.file(entityReactPath);90 assert.fileContent(entityReactPath, '// removed th id primary key');91 const genderEnumPath = `${SERVER_NODEJS_DIR}src/domain/enumeration/gender.ts`;92 const greatEntityPath = `${SERVER_NODEJS_DIR}src/domain/great-entity.entity.ts`;93 const greatEntityDTOPath = `${SERVER_NODEJS_DIR}src/service/dto/great-entity.dto.ts`;94 assert.file(genderEnumPath);95 assert.file(greatEntityPath);96 assert.file(greatEntityDTOPath);97 // Gender enum class98 assert.fileContent(genderEnumPath, 'export enum Gender');99 // import enum in entity100 assert.fileContent(greatEntityPath, 'import { Gender } from "./enumeration/gender";');101 // import enum in entity dto102 assert.fileContent(greatEntityDTOPath, 'import { Gender } from "../../domain/enumeration/gender";');103 // name UUID unique field104 assert.fileContent(greatEntityPath, '@Column({ name: "name", nullable: true, unique: true })');105 assert.fileContent(greatEntityPath, 'name: string;');106 // name UUID with validation and swagger annotation107 assert.fileContent(greatEntityDTOPath, 'name: string;');108 assert.fileContent(greatEntityDTOPath, '@MinLength(5)');109 assert.fileContent(greatEntityDTOPath, '@ApiModelProperty({ description: "name field", required: false })');110 // Gender enum field with swagger annotation111 assert.fileContent(greatEntityPath, '@Column({ type: "simple-enum", name: "gender", enum: Gender })');112 assert.fileContent(greatEntityPath, 'gender: Gender;');113 assert.fileContent(greatEntityDTOPath, 'gender: Gender;');114 assert.fileContent(greatEntityDTOPath, '@ApiModelProperty({ enum: Gender, description: "gender enum field" })');115 // address string required field116 assert.fileContent(greatEntityPath, '@Column({ name: "address", length: 100 })');117 assert.fileContent(greatEntityPath, 'address: string;');118 // address string with validation and swagger annotation119 assert.fileContent(greatEntityDTOPath, 'address: string;');120 assert.fileContent(greatEntityDTOPath, '@IsNotEmpty()');121 assert.fileContent(greatEntityDTOPath, '@Length(1, 100)');122 assert.fileContent(greatEntityDTOPath, '@ApiModelProperty({ description: "address field" })');123 // description string field124 assert.fileContent(greatEntityPath, '@Column({ name: "description", nullable: true })');125 assert.fileContent(greatEntityPath, 'description: string;');126 // description string with validation and swagger annotation127 assert.fileContent(greatEntityDTOPath, 'description: string;');128 assert.fileContent(greatEntityDTOPath, '@Matches("^[A-Z]$")');129 assert.fileContent(greatEntityDTOPath, '@ApiModelProperty({ description: "description field", required: false })');130 // istrue Boolean field with swagger annotation131 assert.fileContent(greatEntityPath, '@Column({ type: "boolean", name: "istrue", nullable: true })');132 assert.fileContent(greatEntityPath, 'istrue: boolean;');133 assert.fileContent(greatEntityDTOPath, 'istrue: boolean;');134 assert.fileContent(greatEntityDTOPath, '@ApiModelProperty({ description: "istrue field", required: false })');135 // borndate LocalDate required field136 assert.fileContent(greatEntityPath, '@Column({ type: "date", name: "borndate" })');137 assert.fileContent(greatEntityPath, 'borndate: any;');138 assert.fileContent(greatEntityDTOPath, '@ApiModelProperty({ description: "borndate field" })');139 // profileimage Blob field140 assert.fileContent(greatEntityPath, '@Column({ type: "blob", name: "profileimage", nullable: true })');141 assert.fileContent(greatEntityPath, 'profileimage: any;');142 // storage AnyBlob field143 assert.fileContent(greatEntityPath, '@Column({ type: "blob", name: "storage", nullable: true })');144 assert.fileContent(greatEntityPath, 'storage: any;');145 // datafile TextBlob field146 assert.fileContent(greatEntityPath, '@Column({ type: "blob", name: "datafile", nullable: true })');147 assert.fileContent(greatEntityPath, 'datafile: any;');148 // image Blob field149 assert.fileContent(greatEntityPath, '@Column({ type: "blob", name: "image", nullable: true })');150 assert.fileContent(greatEntityPath, 'image: any;');151 // amount BigDecimal field152 assert.fileContent(greatEntityPath, ' type: "decimal",');153 assert.fileContent(greatEntityPath, ' name: "amount",');154 assert.fileContent(greatEntityPath, ' precision: 10,');155 assert.fileContent(greatEntityPath, ' scale: 2,');156 assert.fileContent(greatEntityPath, 'amount: number;');157 // cfu Integer field158 assert.fileContent(greatEntityPath, '@Column({ type: "integer", name: "cfu", nullable: true })');159 assert.fileContent(greatEntityPath, 'cfu: number;');160 // mynumber Double field161 assert.fileContent(greatEntityPath, '@Column({ type: "double", name: "mynumber", nullable: true })');162 assert.fileContent(greatEntityPath, 'mynumber: number;');163 // mynumber with validation and swagger annotation164 assert.fileContent(greatEntityDTOPath, 'mynumber: number;');165 assert.fileContent(greatEntityDTOPath, '@Min(1)');166 assert.fileContent(greatEntityDTOPath, '@Max(100)');167 assert.fileContent(greatEntityDTOPath, '@ApiModelProperty({ description: "mynumber field", required: false })');168 // count Long field169 assert.fileContent(greatEntityPath, '@Column({ type: "long", name: "count", nullable: true })');170 assert.fileContent(greatEntityPath, 'count: number;');171 // cent Float field172 assert.fileContent(greatEntityPath, '@Column({ type: "float", name: "cent", nullable: true })');173 assert.fileContent(greatEntityPath, 'cent: number;');174 // creationtime Instant field175 assert.fileContent(greatEntityPath, '@Column({ type: "datetime", name: "creationtime", nullable: true })');176 assert.fileContent(greatEntityPath, 'creationtime: any;');177 // deathtime ZonedDateTime field178 assert.fileContent(greatEntityPath, '@Column({ type: "datetime", name: "deathtime", nullable: true })');179 assert.fileContent(greatEntityPath, 'deathtime: any;');180 });181 });...

Full Screen

Full Screen

cleanLiterals.js

Source:cleanLiterals.js Github

copy

Full Screen

1var path = require('path'), fs=require('fs');2function fromDir(startPath,filter){3 var filteredFiles = [];4 var files=fs.readdirSync(startPath);5 for(var i=0;i<files.length;i++){6 var filename=path.join(startPath,files[i]);7 if (filename.indexOf(filter)>=0) {8 filteredFiles.push(filename);9 };10 };11 return filteredFiles;12};13var javascriptFiles = fromDir('./dist','.js');14var removeComments = /\/\/([^/]*?)\\n/g15var removeNewLines = / +/g16var removeSpacesBeforeColon = /\; +/g17var removeSpacesAfterColon = /\} +/g18var base = __dirname+'/';19javascriptFiles.forEach(function(file){20 if(file.indexOf('g.js') >=0){21 console.log(base+file);22 var filePath = path.join(__dirname, file);23 var fileContent = fs.readFileSync(filePath, 'utf8');24 fileContent = fileContent.replace(removeComments, '');25 fileContent = fileContent.replace(removeNewLines, '');26 fileContent = fileContent.replace(/, /g, ',');27 fileContent = fileContent.replace(/ = /g, '=');28 fileContent = fileContent.replace(/\. /g, '.');29 fileContent = fileContent.replace(/ < /g, '<');30 fileContent = fileContent.replace(/ > /g, '>');31 fileContent = fileContent.replace(/ == /g, '==');32 fileContent = fileContent.replace(/ -= /g, '-=');33 fileContent = fileContent.replace(/ >= /g, '>=');34 fileContent = fileContent.replace(/ <= /g, '<=');35 fileContent = fileContent.replace(/ - /g, '-');36 fileContent = fileContent.replace(/ \+= /g, '+=');37 fileContent = fileContent.replace(/ != /g, '!=');38 fileContent = fileContent.replace(/ \/= /g, '/=');39 fileContent = fileContent.replace(/ \*= /g, '*=');40 fileContent = fileContent.replace(/ && /g, '&&');41 fileContent = fileContent.replace(/; /g, ';');42 fileContent = fileContent.replace(/ \+ /g, '+');43 fileContent = fileContent.replace(/ \./g, '.');44 fileContent = fileContent.replace(/ ,/g, ',');45 fileContent = fileContent.replace(/&& /g, '&&');46 fileContent = fileContent.replace(/\( /g, '(');47 48 49 // fileContent = fileContent.replace(removeSpacesBeforeColon, ';');50 // fileContent = fileContent.replace(removeSpacesAfterColon, '}');51 //WORD TRANSFORMS52 fileContent = fileContent.replace(/terrainHeight/g, 'tH');53 fileContent = fileContent.replace(/waterCurrents/g, 'wC');54 fileContent = fileContent.replace(/objectsShape/g, 'oS');55 fileContent = fileContent.replace(/mapDecorations/g, 'mD');56 fileContent = fileContent.replace(/waterQuantity/g, 'wQ');57 fileContent = fileContent.replace(/myBoatsColor/g, 'bC');58 fileContent = fileContent.replace(/finalDestinationCorner/g, 'dC');59 fileContent = fileContent.replace(/shaderFunctions/g, 'sF');60 fileContent = fileContent.replace(/finalDestDeco/g, 'fD');61 fileContent = fileContent.replace(/drawLine/g, 'dL');62 fileContent = fileContent.replace(/finalDestTrr/g, 'fT');63 fileContent = fileContent.replace(/drawDonut/g, 'dD');64 fileContent = fileContent.replace(/blockers/g, 'bL');65 fileContent = fileContent.replace(/ballsCollisionForce/g, 'bF');66 fileContent = fileContent.replace(/ballsCollisionDamping/g, 'bD');67 fileContent = fileContent.replace(/waterPushByPlayer/g, 'wP');68 fileContent = fileContent.replace(/wCForceOfMap/g, 'wC');69 fileContent = fileContent.replace(/waterFrictionToObjects/g, 'wF');70 fileContent = fileContent.replace(/tHForce/g, 'tH');71 fileContent = fileContent.replace(/objectsBarLength/g, 'oL');72 fileContent = fileContent.replace(/objectsBarForce/g, 'oF');73 fileContent = fileContent.replace(/objectsBarDamping/g, 'oD');74 fileContent = fileContent.replace(/unlockedLevels/g, 'uL');75 fileContent = fileContent.replace(/baseOperations/g, 'bO');76 fileContent = fileContent.replace(/shaderCreator/g, 'sC');77 fileContent = fileContent.replace(/meshBuff/g, 'mB');78 fileContent = fileContent.replace(/texWidth/g, 'tW');79 fileContent = fileContent.replace(/texHeight/g, 'th');80 fileContent = fileContent.replace(/shaderMtx/g, 'sX');81 fileContent = fileContent.replace(/fillTex0/g, 'f0');82 fileContent = fileContent.replace(/fillTex1/g, 'f1');83 fileContent = fileContent.replace(/fillTex2/g, 'f2');84 fileContent = fileContent.replace(/levelEnded/g, 'lE');85 fileContent = fileContent.replace(/frameCounter/g, 'fC');86 fileContent = fileContent.replace(/confetti/g, 'cF');87 //shaders88 fileContent = fileContent.replace(/shaderP0/g, '$1');89 fileContent = fileContent.replace(/shdVtx0/g, '$2');90 fileContent = fileContent.replace(/shdMtx0/g, '$3');91 fileContent = fileContent.replace(/shdTex0/g, '$4');92 fileContent = fileContent.replace(/shaderP1/g, '$5');93 fileContent = fileContent.replace(/shdVtx1/g, '$6');94 fileContent = fileContent.replace(/shdMtx1/g, '$7');95 fileContent = fileContent.replace(/shdTex10/g, '$8');96 fileContent = fileContent.replace(/shdTex11/g, '$9');97 fileContent = fileContent.replace(/shaderP2/g, '$10');98 fileContent = fileContent.replace(/shdVtx2/g, '$11');99 fileContent = fileContent.replace(/shdMtx2/g, '$12');100 fileContent = fileContent.replace(/shdTex2/g, '$13');101 fileContent = fileContent.replace(/shaderP3/g, '$14');102 fileContent = fileContent.replace(/shdVtx3/g, '$15');103 fileContent = fileContent.replace(/shdMtx3/g, '$16');104 fileContent = fileContent.replace(/shdTex30/g, '$17');105 fileContent = fileContent.replace(/shdTex31/g, '$18');106 fileContent = fileContent.replace(/shaderP4/g, '$19');107 fileContent = fileContent.replace(/shdVtx4/g, '$20');108 fileContent = fileContent.replace(/shdMtx4/g, '$21');109 fileContent = fileContent.replace(/shdTex40/g, '$22');110 fileContent = fileContent.replace(/shdTex41/g, '$23');111 fileContent = fileContent.replace(/shdTex42/g, '$24');112 fileContent = fileContent.replace(/shaderP9/g, '$25');113 fileContent = fileContent.replace(/shdVtx9/g, '$26');114 fileContent = fileContent.replace(/shdMtx9/g, '$27');115 fileContent = fileContent.replace(/shdTex90/g, '$28');116 fileContent = fileContent.replace(/shdTex91/g, '$29');117 fileContent = fileContent.replace(/shaderP10/g, '$30');118 fileContent = fileContent.replace(/shdVtx10/g, '$31');119 fileContent = fileContent.replace(/shdMtx10/g, '$32');120 fileContent = fileContent.replace(/shdTex100/g, '$33');121 fileContent = fileContent.replace(/shdTex101/g, '$34');122 fileContent = fileContent.replace(/shdTex102/g, '$35');123 fileContent = fileContent.replace(/shaderP11/g, '$36');124 fileContent = fileContent.replace(/shdVtx11/g, '$37');125 fileContent = fileContent.replace(/shdMtx11/g, '$38');126 fileContent = fileContent.replace(/shdTex110/g, '$39');127 fileContent = fileContent.replace(/shdTex111/g, '$40');128 fileContent = fileContent.replace(/shaderP12/g, '$41');129 fileContent = fileContent.replace(/shdVtx12/g, '$42');130 fileContent = fileContent.replace(/shdMtx12/g, '$43');131 fileContent = fileContent.replace(/shdTex120/g, '$44');132 fileContent = fileContent.replace(/shdTex121/g, '$45');133 fileContent = fileContent.replace(/shaderP15/g, '$46');134 fileContent = fileContent.replace(/shdVtx15/g, '$47');135 fileContent = fileContent.replace(/shdTex150/g, '$48');136 fileContent = fileContent.replace(/shdTex151/g, '$49');137 // fileContent = fileContent.replace(/shaderP6/g, '$50');138 // fileContent = fileContent.replace(/shdVtx6/g, '$51');139 // fileContent = fileContent.replace(/shdMtx6/g, '$52');140 // fileContent = fileContent.replace(/shdTex6/g, '$53');141 // fileContent = fileContent.replace(/shaderPS/g, '$54');142 // fileContent = fileContent.replace(/shdVtxS/g, '$55');143 // fileContent = fileContent.replace(/shdMtxS/g, '$56');144 // fileContent = fileContent.replace(/shdTexS0/g, '$57');145 // fileContent = fileContent.replace(/shdTexS1/g, '$58');146 // fileContent = fileContent.replace(/shdTexS2/g, '$59');147 // fileContent = fileContent.replace(/shdTexS3/g, '$60');148 // fileContent = fileContent.replace(/shdTexS4/g, '$61');149 // fileContent = fileContent.replace(/;\\n/g, ';');150 fileContent = fileContent.replace(/\\n/g, '');151 // fileContent = fileContent.replace(/(\\n)/g, '');152 fs.writeFileSync(filePath, fileContent);153 console.log("FIXING FILE", file);154 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withReadme } from 'storybook-readme';5import { fileContent } from 'storybook-root';6import Readme from './README.md';7const stories = storiesOf('Test', module);8stories.add(9 withInfo({10 text: fileContent(Readme)11 })(() => <div>Test</div>)12);13stories.add(14 withReadme(Readme, () => <div>Test</div>)15);16stories.add(17 withReadme([Readme], () => <div>Test</div>)18);19 at Object.module.exports (C:\Users\jwade\Documents\GitHub\storybook-root\node_modules\babel-loader\lib\index.js:76:34)20 @ multi ./node_modules/@storybook/react/dist/server/config/polyfills.js ./node_modules/@storybook/react/dist/server/config/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true21I am trying to use storybook-root to include a README.md file in a storybook. I have a storybook setup and can run it without any problems. I am using the following code to include the README.md file. I am getting the following error: ERROR in ./src/test.js Module build failed: TypeError: Cannot read property 'file' of undefined at Object.module.exports (C:\Users\jwade\Documents\GitHub\storybook-root22ode_modules\babel-loader\lib\index.js:76:34) @ ./src sync .stories.js$ @ ./.storybook/config.js @ multi ./node_modules/@storybook/react/dist/server/config/polyfills.js ./node_modules/@storybook/react/dist/server/config/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true I am not sure if this is a problem with storybook-root or babel-loader or something else. Any help would be appreciated. Thanks

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fileContent } from 'storybook-root';2const storybookRoot = fileContent('storybook-root');3import { fileContent } from 'storybook-root';4const storybookRoot = fileContent('storybook-root');5import { fileContent } from 'storybook-root';6const storybookRoot = fileContent('storybook-root');7import { fileContent } from 'storybook-root';8const storybookRoot = fileContent('storybook-root');9import { fileContent } from 'storybook-root';10const storybookRoot = fileContent('storybook-root');11import { fileContent } from 'storybook-root';12const storybookRoot = fileContent('storybook-root');13import { fileContent } from 'storybook-root';14const storybookRoot = fileContent('storybook-root');15import { fileContent } from 'storybook-root';16const storybookRoot = fileContent('storybook-root');17import { fileContent } from 'storybook-root';18const storybookRoot = fileContent('storybook-root');19import { fileContent } from 'storybook-root';20const storybookRoot = fileContent('storybook-root');21import { fileContent } from 'storybook-root';22const storybookRoot = fileContent('storybook-root');23import { fileContent } from 'storybook-root';24const storybookRoot = fileContent('storybook-root');25import { fileContent } from '

Full Screen

Using AI Code Generation

copy

Full Screen

1const { fileContent } = require('storybook-root-cause');2const content = fileContent('path/to/file.js');3const { fileContent } = require('storybook-root-cause');4const content = fileContent('path/to/file.js');5const { fileContent } = require('storybook-root-cause');6const content = fileContent('path/to/file.js');7const { fileContent } = require('storybook-root-cause');8const content = fileContent('path/to/file.js');9const { fileContent } = require('storybook-root-cause');10const content = fileContent('path/to/file.js');11const { fileContent } = require('storybook-root-cause');12const content = fileContent('path/to/file.js');13const { fileContent } = require('storybook-root-cause');14const content = fileContent('path/to/file.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var storybook = require('storybook-root');2var fileContent = storybook.fileContent('test.txt');3console.log(fileContent);4var storybook = require('storybook-root');5var fileContent = storybook.fileContent('some/other/test.txt');6console.log(fileContent);7var storybook = require('storybook-root');8var fileContent = storybook.fileContentSync('test.txt');9console.log(fileContent);10var storybook = require('storybook-root');11var fileContent = storybook.fileContentSync('some/other/test.txt');12console.log(fileContent);13var storybook = require('storybook-root');14var fileContent = storybook.fileContentJSON('test.json');15console.log(fileContent);16{ "name": "John", "age": 30 }

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2const fs = require('fs');3const fileContent = storybookRoot.fileContent('test.txt');4fs.writeFileSync('test.txt', fileContent);5const fileContent = fs.readFileSync('test.txt', 'utf8');6console.log(fileContent);7const storybookRoot = require('storybook-root');8const fs = require('fs');9const fileContent = storybookRoot.fileContent('test.txt');10fs.writeFileSync('test.txt', fileContent);11const fileContent = fs.readFileSync('test.txt', 'utf8');12console.log(fileContent);13const storybookRoot = require('storybook-root');14const fs = require('fs');15const fileContent = storybookRoot.fileContent('test.txt');16fs.writeFileSync('test.txt', fileContent);17const fileContent = fs.readFileSync('test.txt', 'utf8');18console.log(fileContent);19const storybookRoot = require('storybook-root

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful