Skip to content

Commit

Permalink
feat(test-generator): run all schemas (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilch committed Sep 2, 2021
1 parent 8ba7f00 commit 00215ae
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
63 changes: 32 additions & 31 deletions packages/test-generator/index.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
import { StudioComponent } from '@amzn/amplify-ui-codegen-schema';
import { StudioTemplateRendererManager, StudioTemplateRendererFactory } from '@amzn/studio-ui-codegen';
import {
StudioComponent,
} from "@amzn/amplify-ui-codegen-schema"
import {
StudioTemplateRendererManager,
StudioTemplateRendererFactory,
} from "@amzn/studio-ui-codegen";
import {
AmplifyRenderer,
AmplifyRenderer,
ReactOutputConfig,
JSModuleEnum,
CompileTargetEnum,
JSOutputFormatEnum
} from "@amzn/studio-ui-codegen-react";
JSOutputFormatEnum,
} from '@amzn/studio-ui-codegen-react';
import path from 'path';

import * as schema from "./lib/dataBindingWithDataStore.json";
import * as schemas from './lib';

Error.stackTraceLimit = Infinity;

const rendererFactory = new StudioTemplateRendererFactory(
(component: StudioComponent) => new AmplifyRenderer(component)
(component: StudioComponent) => new AmplifyRenderer(component),
);

const outputPathDir = path.resolve(path.join(__dirname, '..', 'ui-components'));
const outputConfig: ReactOutputConfig = {
outputPathDir,
module: JSModuleEnum.CommonJS,
compileTarget: CompileTargetEnum.ES6,
outputFormat: JSOutputFormatEnum.tsx
outputFormat: JSOutputFormatEnum.tsx,
};
const rendererManager = new StudioTemplateRendererManager(rendererFactory, outputConfig);

console.log(rendererManager);

rendererManager.renderSchemaToTemplate(schema as any);

const compOnly = rendererFactory.buildRenderer(schema as any).renderComponentOnly();
console.log("Component Only Output");
console.log("componentText ");
console.log(compOnly.compText);
console.log("componentImports ");
console.log(compOnly.importsText);

const compOnlyAppSample = rendererFactory.buildRenderer(schema as any).renderSampleCodeSnippet();
console.log("Code Snippet Output");
console.log("componentText ");
console.log(compOnlyAppSample.compText);
console.log("componentImports ");
console.log(compOnlyAppSample.importsText);
Object.entries(schemas).forEach(([name, schema]) => {
console.log(name);
try {
rendererManager.renderSchemaToTemplate(schema as any);
const buildRenderer = rendererFactory.buildRenderer(schema as any);

const compOnly = buildRenderer.renderComponentOnly();
console.log('Component Only Output');
console.log('componentImports ');
console.log(compOnly.importsText);
console.log('componentText ');
console.log(compOnly.compText);

const compOnlyAppSample = buildRenderer.renderSampleCodeSnippet();
console.log('Code Snippet Output');
console.log('componentImports ');
console.log(compOnlyAppSample.importsText);
console.log('componentText ');
console.log(compOnlyAppSample.compText);
} catch (err) {
console.log(`${name} failed with error:`);
console.log(err);
}
});
14 changes: 14 additions & 0 deletions packages/test-generator/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export { default as BoxGolden } from './boxGolden.json';
export { default as BoxTest } from './boxTest.json';
export { default as ButtonGolden } from './buttonGolden.json';
export { default as CustomChild } from './customChild.json';
export { default as CustomTimeline } from './customTimeline.json';
export { default as DataBindingWithDataStore } from './dataBindingWithDataStore.json';
export { default as ExposedAsTest } from './exposedAsTest.json';
export { default as HeaderWithAction } from './headerWithAction.json';
export { default as PropertyListing } from './propertyListing.json';
export { default as RedBadge } from './redBadge.json';
export { default as SampleCodeSnippet } from './sampleCodeSnippet.json';
export { default as Studio } from './studio.json';
export { default as TextGolden } from './textGolden.json';
export { default as TextsCollection } from './textsCollection.json';
4 changes: 4 additions & 0 deletions packages/test-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"homepage": "https://code.amazon.com/packages/AmplifyUICodegen/packages/test-generator",
"license": "ISC",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"build:watch": "npm run build -- --watch"
},
"directories": {
"lib": "lib",
"test": "__tests__"
Expand Down

0 comments on commit 00215ae

Please sign in to comment.