Skip to content

Commit

Permalink
feat: adding gh workflow to test rendered goldens
Browse files Browse the repository at this point in the history
  • Loading branch information
alharris-at committed Oct 18, 2021
1 parent 12c9efb commit 17e0ca0
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'packages/amplify-ui-codegen-schema',
'ui-components',
'*.md',
'cypress',
],
extends: [
'plugin:@typescript-eslint/recommended',
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,43 @@ jobs:
- name: Test amplify-category-studio
working-directory: amplify-category-studio
run: npm test

test-generated-components-render:
runs-on: ubuntu-latest
steps:
- name: Checkout Studio Codegen
uses: actions/checkout@v2
with:
path: amplify-codegen-ui-staging
- name: Setup Node.js LTS
uses: actions/setup-node@v2
with:
node-version: lts/*
- name: Install amplify-codegen-ui-staging dependencies
working-directory: amplify-codegen-ui-staging
run: npm ci
- name: Lerna bootstrap amplify-codegen-ui-staging
working-directory: amplify-codegen-ui-staging
run: lerna bootstrap
- name: Build amplify-codegen-ui-staging
working-directory: amplify-codegen-ui-staging
run: npm run build
- name: Execute test-generator
working-directory: amplify-codegen-ui-staging/packages/test-generator
run: node .
- name: Create test app with dependencies
working-directory: .
run: |
npx create-react-app test-app --use-npm --template typescript
cp -r amplify-codegen-ui-staging/packages/test-generator/test-app-templates/* test-app
cd test-app
npm i aws-amplify @aws-amplify/ui-react@2.0.1-next.5
npm i cypress --save-dev
echo "Installed test-app to ${PWD}"
- name: Cypress run
uses: cypress-io/github-action@v2
with:
working-directory: test-app
build: npm run build
start: npm start
wait-on: 'http://localhost:3000'
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ReactThemeStudioTemplateRenderer extends StudioTemplateRenderer<
> {
protected importCollection = new ImportCollection();

fileName = 'theme.txs';
fileName = 'theme.tsx';

constructor(theme: StudioTheme, protected renderConfig: ReactRenderConfig) {
super(theme, new ReactOutputManager(), renderConfig);
Expand Down
2 changes: 1 addition & 1 deletion packages/test-generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const themeRendererFactory = new StudioTemplateRendererFactory(
(theme: StudioTheme) => new ReactThemeStudioTemplateRenderer(theme, renderConfig),
);

const outputPathDir = path.resolve(path.join(__dirname, '..', 'ui-components'));
const outputPathDir = path.resolve(path.join(__dirname, '..', 'test-app-templates', 'src', 'ui-components'));
const outputConfig: ReactOutputConfig = {
outputPathDir,
};
Expand Down
1 change: 1 addition & 0 deletions packages/test-generator/test-app-templates/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('My First Tests', () => {
it('Opens the test app', () => {
cy.visit('http://localhost:3000');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
34 changes: 34 additions & 0 deletions packages/test-generator/test-app-templates/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable import/extensions */
import React from 'react';
import BoxWithButton from './ui-components/BoxWithButton';
import BoxWithCustomButton from './ui-components/BoxWithCustomButton';
import CollectionOfCustomButtons from './ui-components/CollectionOfCustomButtons';
import ComponentWithDataBinding from './ui-components/ComponentWithDataBinding';
import CustomButton from './ui-components/CustomButton';
import CustomText from './ui-components/CustomText';
import ListingCardCollection from './ui-components/ListingCardCollection';
import Profile from './ui-components/Profile';
import SectionHeading from './ui-components/SectionHeading';
import SiteHeader from './ui-components/SiteHeader';
import Test from './ui-components/Test';
import TextWithDataBinding from './ui-components/TextWithDataBinding';
/* eslint-enable import/extensions */

const App = () => {
<>
<BoxWithButton></BoxWithButton>
<BoxWithCustomButton></BoxWithCustomButton>
<CollectionOfCustomButtons></CollectionOfCustomButtons>
<ComponentWithDataBinding></ComponentWithDataBinding>
<CustomButton></CustomButton>
<CustomText></CustomText>
<ListingCardCollection></ListingCardCollection>
<Profile></Profile>
<SectionHeading></SectionHeading>
<SiteHeader></SiteHeader>
<Test></Test>
<TextWithDataBinding></TextWithDataBinding>
</>;
};

export default App;

0 comments on commit 17e0ca0

Please sign in to comment.