Skip to content

Commit fc778cb

Browse files
authored
Merge pull request #585 from aws-amplify/refactor-docgen-staging
BREAKING CHANGE: Full refactor of GraphQL documents generator package to be browser compatible and Amplify CLI agnostic BREAKING CHANGE!
2 parents a9470bd + dde0117 commit fc778cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+5947
-4630
lines changed

.circleci/config.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,15 @@ jobs:
541541
TEST_SUITE: src/__tests__/graphql-codegen-ios.test.ts
542542
CLI_REGION: ap-northeast-1
543543
SET_NPM_PREFIX: true
544+
graphql-documents-generator-e2e-test:
545+
working_directory: ~/repo
546+
parameters: *ref_0
547+
executor: << parameters.os >>
548+
steps: *ref_6
549+
environment:
550+
TEST_SUITE: src/__tests__/graphql-documents-generator.test.ts
551+
CLI_REGION: ap-southeast-1
552+
SET_NPM_PREFIX: true
544553
workflows:
545554
version: 2
546555
e2e_resource_cleanup:
@@ -623,6 +632,7 @@ workflows:
623632
- push-codegen-js-e2e-test
624633
- datastore-modelgen-flutter-e2e-test
625634
- feature-flags-e2e-test
635+
- graphql-documents-generator-e2e-test
626636
- pull-codegen-e2e-test
627637
- datastore-modelgen-ios-e2e-test
628638
- configure-codegen-ios-e2e-test
@@ -794,6 +804,13 @@ workflows:
794804
- publish_to_local_registry
795805
post-steps: *ref_9
796806
filters: *ref_10
807+
- graphql-documents-generator-e2e-test:
808+
context: *ref_8
809+
os: l
810+
requires:
811+
- publish_to_local_registry
812+
post-steps: *ref_9
813+
filters: *ref_10
797814
- pull-codegen-e2e-test:
798815
context: *ref_8
799816
os: l

packages/amplify-codegen-e2e-core/src/init/cra.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,22 @@ export function craBuild(cwd: string, settings: Object = {}): Promise<void> {
3434
});
3535
});
3636
}
37+
38+
export function cypressRun(cwd: string, settings: any = {}): Promise<void> {
39+
return new Promise((resolve, reject) => {
40+
const s = { ...defaultSettings, ...settings };
41+
const args = ['cypress', 'run'];
42+
if (s?.componentsTesting) {
43+
args.push('--component');
44+
};
45+
const chain = spawn('npx', args, { cwd, stripColors: true, disableCIDetection: s.disableCIDetection });
46+
47+
chain.run((err: Error) => {
48+
if (err) {
49+
reject(err);
50+
} else {
51+
resolve();
52+
}
53+
});
54+
});
55+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
initProjectWithProfile,
3+
DEFAULT_JS_CONFIG,
4+
addApiWithBlankSchema,
5+
updateApiSchemaWithText,
6+
craInstall,
7+
craBuild,
8+
amplifyPush,
9+
cypressRun,
10+
deleteProject
11+
} from '@aws-amplify/amplify-codegen-e2e-core';
12+
import { readdirSync, rmSync } from 'fs';
13+
import { readFileSync } from 'fs-extra';
14+
import path from 'path';
15+
16+
describe('GraphQL documents generator e2e tests', () => {
17+
let apiName: string;
18+
const projectRoot = path.resolve('test-apps', 'docsgen-react-app');
19+
const config = DEFAULT_JS_CONFIG;
20+
21+
beforeAll(async () => {
22+
await initProjectWithProfile(projectRoot, { ...config });
23+
await addApiWithBlankSchema(projectRoot);
24+
await craInstall(projectRoot, { ...config });
25+
apiName = readdirSync(path.join(projectRoot, 'amplify', 'backend', 'api'))[0];
26+
});
27+
28+
afterAll(async () => {
29+
await deleteProject(projectRoot);
30+
await rmSync(path.join(projectRoot, 'amplify'), { recursive: true, force: true });
31+
});
32+
33+
const schemaFileName = 'schema.graphql';
34+
it('generates valid GraphQL documents for given schema', async () => {
35+
const schemaPath = path.resolve('test-apps', 'docsgen-react-app', 'public', schemaFileName);
36+
const schemaText = readFileSync(schemaPath, { encoding: 'utf8'});
37+
updateApiSchemaWithText(projectRoot, apiName, schemaText);
38+
await amplifyPush(projectRoot);
39+
40+
// Build and run the cypress e2e tests
41+
await craBuild(projectRoot, { ...config });
42+
await cypressRun(projectRoot, { componentsTesting: true });
43+
});
44+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
#amplify-do-not-edit-begin
26+
amplify/\#current-cloud-backend
27+
amplify/.config/local-*
28+
amplify/logs
29+
amplify/mock-data
30+
amplify/mock-api-resources
31+
amplify/backend/amplify-meta.json
32+
amplify/backend/.temp
33+
build/
34+
dist/
35+
node_modules/
36+
aws-exports.js
37+
awsconfiguration.json
38+
amplifyconfiguration.json
39+
amplifyconfiguration.dart
40+
amplify-build-config.json
41+
amplify-gradle-config.json
42+
amplifytools.xcconfig
43+
.secret-*
44+
**.sample
45+
#amplify-do-not-edit-end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
This is a test React application.
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `npm start`
8+
9+
Runs the app in the development mode.\
10+
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
11+
12+
The page will reload when you make changes.\
13+
You may also see any lint errors in the console.
14+
15+
### `npm run build`
16+
17+
Builds the app for production to the `build` folder.\
18+
It correctly bundles React in production mode and optimizes the build for the best performance.
19+
20+
The build is minified and the filenames include the hashes.\
21+
Your app is ready to be deployed!
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { defineConfig } = require("cypress");
2+
3+
module.exports = defineConfig({
4+
component: {
5+
devServer: {
6+
framework: "create-react-app",
7+
bundler: "webpack",
8+
},
9+
},
10+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>Components App</title>
8+
</head>
9+
<body>
10+
<div data-cy-root></div>
11+
</body>
12+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { mount } from 'cypress/react18';
2+
3+
Cypress.Commands.add('mount', mount);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "docsgen-react-app",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@aws-amplify/graphql-docs-generator": "file:../../../graphql-docs-generator",
7+
"@testing-library/jest-dom": "^5.16.5",
8+
"@testing-library/react": "^13.4.0",
9+
"@testing-library/user-event": "^13.5.0",
10+
"aws-amplify": "^5.0.25",
11+
"react": "^18.2.0",
12+
"react-dom": "^18.2.0",
13+
"react-scripts": "5.0.1",
14+
"web-vitals": "^2.1.4"
15+
},
16+
"scripts": {
17+
"start": "react-scripts start",
18+
"build": "react-scripts build",
19+
"test": "react-scripts test",
20+
"eject": "react-scripts eject"
21+
},
22+
"eslintConfig": {
23+
"extends": [
24+
"react-app",
25+
"react-app/jest"
26+
]
27+
},
28+
"browserslist": {
29+
"production": [
30+
">0.2%",
31+
"not dead",
32+
"not op_mini all"
33+
],
34+
"development": [
35+
"last 1 chrome version",
36+
"last 1 firefox version",
37+
"last 1 safari version"
38+
]
39+
},
40+
"devDependencies": {
41+
"cypress": "^12.9.0"
42+
}
43+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<meta name="theme-color" content="#000000" />
7+
<meta
8+
name="description"
9+
content="Web site created using create-react-app for e2e testing"
10+
/>
11+
<title>React App</title>
12+
</head>
13+
<body>
14+
<noscript>You need to enable JavaScript to run this app.</noscript>
15+
<div id="root"></div>
16+
</body>
17+
</html>

0 commit comments

Comments
 (0)