-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add gen2 e2e tests #833
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6d319c7
test: add gen2 e2e tests
AaronZyLee 2f37380
fix: test failure
AaronZyLee 58791f9
fix: windows test
AaronZyLee a2cc04a
chore: update options
AaronZyLee a15050f
fix: test
AaronZyLee 5bf04eb
fix: test
AaronZyLee d454c46
fix: windows test
AaronZyLee 9f48fbf
fix: rm return in ctrl c
AaronZyLee 8eaaf4d
fix: ampx path
AaronZyLee 3bd5708
fix: dependency license
AaronZyLee c1c0c39
fix: ampx path
AaronZyLee cce9f52
fix: ampx path
AaronZyLee 342ee7c
chore: rm unused package & refactor methods
AaronZyLee fce15a2
fix: lint
AaronZyLee 124f66d
test: add generate gen2 command
AaronZyLee 51fefab
test: add generate codegen commands
AaronZyLee e5d33db
test: add additional cases
AaronZyLee be9c205
chore: rm unused code
AaronZyLee 057bc64
chore: minor nits
phani-srikar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: 0.2 | ||
env: | ||
shell: bash | ||
variables: | ||
CI: true | ||
CODEBUILD: true | ||
NODE_OPTIONS: --max-old-space-size=8096 | ||
|
||
phases: | ||
build: | ||
commands: | ||
- source ./shared-scripts.sh && _setupGen2E2ETestsLinux | ||
- source ./shared-scripts.sh && _runGen2E2ETestsLinux | ||
post_build: | ||
commands: | ||
- source ./shared-scripts.sh && _unassumeTestAccountCredentials | ||
- aws sts get-caller-identity | ||
- source ./shared-scripts.sh && _scanArtifacts | ||
|
||
artifacts: | ||
files: | ||
- '**/*' | ||
base-directory: $CODEBUILD_SRC_DIR/packages/amplify-codegen-e2e-tests/amplify-e2e-reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: 0.2 | ||
env: | ||
shell: powershell.exe | ||
variables: | ||
CI: true | ||
CODEBUILD: true | ||
NODE_OPTIONS: --max-old-space-size=8096 | ||
phases: | ||
build: | ||
commands: | ||
# commands need to be run in stand-alone bash scripts so that bash can be used on windows | ||
- bash ./.codebuild/scripts/gen2_e2e_test_windows.sh | ||
post_build: | ||
commands: | ||
# commands need to be run in stand-alone bash scripts so that bash can be used on windows | ||
- bash ./.codebuild/scripts/post_e2e_test.sh | ||
|
||
artifacts: | ||
files: | ||
- '**/*' | ||
base-directory: $Env:CODEBUILD_SRC_DIR\packages\amplify-codegen-e2e-tests\amplify-e2e-reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
# set exit on error to true | ||
set -e | ||
|
||
source ./shared-scripts.sh && _setupGen2E2ETestsWindows | ||
codebuild-breakpoint | ||
source ./shared-scripts.sh && _runGen2E2ETestsWindows |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...lify-codegen-e2e-tests/src/__tests__/backends/graphql-generator-gen2/handlers/mutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Schema } from '../resource' | ||
|
||
export const handler: Schema["echoMutation"]["functionHandler"] = async (event, context) => { | ||
return { | ||
id: 'todo1', | ||
content: `Echoing content: ${event.arguments.requiredContent}`, | ||
status: 'COMPLETED', | ||
createdAt: performance.now().toString(), | ||
updatedAt: performance.now().toString(), | ||
}; | ||
}; |
9 changes: 9 additions & 0 deletions
9
...amplify-codegen-e2e-tests/src/__tests__/backends/graphql-generator-gen2/handlers/query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Schema } from '../resource' | ||
|
||
export const handler: Schema["echoQuery"]["functionHandler"] = async (event, context) => { | ||
const start = performance.now(); | ||
return { | ||
content: `Echoing content: ${event.arguments.content}`, | ||
executionDuration: performance.now() - start | ||
}; | ||
}; |
59 changes: 59 additions & 0 deletions
59
packages/amplify-codegen-e2e-tests/src/__tests__/backends/graphql-generator-gen2/resource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { type ClientSchema, a, defineData, defineFunction } from '@aws-amplify/backend'; | ||
|
||
const echoQueryHandler = defineFunction({ | ||
entry: './handlers/query.ts' | ||
}); | ||
const echoMutationHandler = defineFunction({ | ||
entry: './handlers/mutation.ts' | ||
}); | ||
|
||
const schema = a.schema({ | ||
// Model type | ||
Todo: a | ||
.model({ | ||
content: a.string(), | ||
status: a.ref('Status'), | ||
}) | ||
.authorization((allow) => [allow.guest()]), | ||
// Enum Type | ||
Status: a.enum([ | ||
'PROGRESS', | ||
'COMPLETED', | ||
]), | ||
EchoQueryStatus: a.enum([ | ||
'PROGRESS', | ||
'COMPLETED', | ||
]), | ||
// Non model type | ||
EchoResponse: a.customType({ | ||
content: a.string(), | ||
executionDuration: a.float() | ||
}), | ||
// Custom query and mutation | ||
echoQuery: a | ||
.query() | ||
.arguments({ | ||
content: a.string(), | ||
status: a.enum(['PROGRESS', 'COMPLETED']), | ||
}) | ||
.returns(a.ref('EchoResponse')) | ||
.authorization(allow => [allow.authenticated()]) | ||
.handler(a.handler.function(echoQueryHandler)), | ||
echoMutation: a | ||
.mutation() | ||
.arguments({ | ||
requiredContent: a.string().required() | ||
}) | ||
.returns(a.ref('Todo').required()) | ||
.authorization(allow => [allow.authenticated()]) | ||
.handler(a.handler.function(echoMutationHandler)), | ||
}); | ||
|
||
export type Schema = ClientSchema<typeof schema>; | ||
|
||
export const data = defineData({ | ||
schema, | ||
authorizationModes: { | ||
defaultAuthorizationMode: 'iam', | ||
}, | ||
}); |
65 changes: 65 additions & 0 deletions
65
packages/amplify-codegen-e2e-tests/src/__tests__/graphql-generator-gen2.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as path from 'path'; | ||
import { createNewProjectDir, deleteProjectDir } from "@aws-amplify/amplify-codegen-e2e-core"; | ||
import { GraphqlCodegenConfig, IntrospectionCodegenConfig, ModelgenConfig, deleteSandbox, generateForms, generateOutputs, initGen2Project, sandboxDeploy, testGraphqlClientCodegen } from "../gen2-codegen-tests-base/"; | ||
|
||
describe('GraphQL generator for Gen2 e2e tests', () => { | ||
let projRoot: string; | ||
let projFolderName: string; | ||
|
||
beforeAll(async () => { | ||
projFolderName = 'graphqlGeneratorGen2'; | ||
projRoot = await createNewProjectDir(projFolderName); | ||
const template = path.resolve(path.join(__dirname, 'backends', 'graphql-generator-gen2')) | ||
await initGen2Project(projRoot, template); | ||
await sandboxDeploy(projRoot); | ||
}); | ||
|
||
afterAll(async () => { | ||
await deleteSandbox(projRoot); | ||
deleteProjectDir(projRoot); | ||
}); | ||
|
||
it('should not throw error when generating outputs', async () => { | ||
await expect(generateOutputs(projRoot)).resolves.not.toThrow(); | ||
}); | ||
|
||
it('should not throw error when generating forms', async () => { | ||
await expect(generateForms(projRoot)).resolves.not.toThrow(); | ||
}); | ||
describe('Graphql client codegen', () => { | ||
// introspection | ||
const introspectionCodegenConfigs: IntrospectionCodegenConfig[] = [ | ||
{ outDir: 'codegen', format: 'introspection' } | ||
]; | ||
introspectionCodegenConfigs.forEach(config => { | ||
it(`should not throw error when generating GraphQL client code in format ${config.format}`, async () => { | ||
await testGraphqlClientCodegen(projRoot, config); | ||
}); | ||
}); | ||
// modelgen | ||
const modelTargets = ['java', 'swift', 'javascript', 'typescript', 'dart'] | ||
const modelgenConfigs: ModelgenConfig[] = modelTargets.map(target => { | ||
return { outDir: 'codegen', format: 'modelgen', modelTarget: target }; | ||
}) | ||
modelgenConfigs.forEach(config => { | ||
it(`should not throw error when generating GraphQL client code in format ${config.format} with target ${config.modelTarget}`, async () => { | ||
await testGraphqlClientCodegen(projRoot, config); | ||
}); | ||
}); | ||
// graphql codegen | ||
const statementTargets = ['javascript', 'graphql', 'flow', 'typescript', 'angular']; | ||
const typeTargets = ['json', 'swift', 'typescript', 'flow', 'scala', 'flow-modern', 'angular']; | ||
const typeTargetConfigs = typeTargets.map(tt => { return { outDir: 'codegen', format: 'graphql-codegen', typeTarget: tt }}); | ||
const graphqlCodegenConfigs: GraphqlCodegenConfig[] = statementTargets.map(st => { | ||
return typeTargetConfigs.map(config => { | ||
return { ...config, statementTarget: st } as GraphqlCodegenConfig | ||
}); | ||
}).flat(); | ||
graphqlCodegenConfigs.forEach(config => { | ||
// TODO: skip these tests as it will fail due to the duplicate graphql module. Will enable them once the issue is resolved | ||
it.skip(`should not throw error when generating GraphQL client code in format ${config.format} with type ${config.typeTarget} and statement ${config.statementTarget}`, async () => { | ||
await testGraphqlClientCodegen(projRoot, config); | ||
}); | ||
}) | ||
}) | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests fail due to the duplicate graphql module detected. Will explore if there are any workarounds before going to the verdaccio registry. This will be addressed in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a follow-up task for this