Skip to content
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 19 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .codebuild/e2e_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ batch:
debug-session: true
depend-on:
- publish_to_local_registry
- identifier: l_graphql_generator_gen2
buildspec: .codebuild/run_gen2_e2e_test.yml
env:
compute-type: BUILD_GENERAL1_LARGE
variables:
TEST_SUITE: src/__tests__/graphql-generator-gen2.test.ts
CLI_REGION: us-west-2
depend-on:
- publish_to_local_registry
- identifier: w_graphql_generator_gen2
buildspec: .codebuild/run_gen2_e2e_test_windows.yml
env:
compute-type: BUILD_GENERAL1_LARGE
image: $WINDOWS_IMAGE_2019
type: WINDOWS_SERVER_2019_CONTAINER
variables:
TEST_SUITE: src/__tests__/graphql-generator-gen2.test.ts
CLI_REGION: us-east-1
depend-on:
- publish_to_local_registry
- build_windows
- identifier: >-
l_add_codegen_ios_configure_codegen_android_configure_codegen_js_graphql_codegen_android
buildspec: .codebuild/run_e2e_tests.yml
Expand Down
21 changes: 21 additions & 0 deletions .codebuild/e2e_workflow_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,24 @@ batch:
debug-session: true
depend-on:
- publish_to_local_registry
- identifier: l_graphql_generator_gen2
buildspec: .codebuild/run_gen2_e2e_test.yml
env:
compute-type: BUILD_GENERAL1_LARGE
variables:
TEST_SUITE: src/__tests__/graphql-generator-gen2.test.ts
CLI_REGION: us-west-2
depend-on:
- publish_to_local_registry
- identifier: w_graphql_generator_gen2
buildspec: .codebuild/run_gen2_e2e_test_windows.yml
env:
compute-type: BUILD_GENERAL1_LARGE
image: $WINDOWS_IMAGE_2019
type: WINDOWS_SERVER_2019_CONTAINER
variables:
TEST_SUITE: src/__tests__/graphql-generator-gen2.test.ts
CLI_REGION: us-east-1
depend-on:
- publish_to_local_registry
- build_windows
23 changes: 23 additions & 0 deletions .codebuild/run_gen2_e2e_test.yml
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
21 changes: 21 additions & 0 deletions .codebuild/run_gen2_e2e_test_windows.yml
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
8 changes: 8 additions & 0 deletions .codebuild/scripts/gen2_e2e_test_windows.sh
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
1,074 changes: 782 additions & 292 deletions dependency_licenses.txt

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/amplify-codegen-e2e-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export function getCLIPath(testingWithLatestCodebase = false) {
return getCommandPath(commandName);
}

export function getScriptRunnerPath(testingWithLatestCodebase = false) {
if (!testingWithLatestCodebase) {
return process.platform === 'win32' ? 'node.exe' : 'exec';
}

// nodejs executable
return process.execPath;
}

export function isCI(): boolean {
return process.env.CI && process.env.CODEBUILD ? true : false;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/amplify-codegen-e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"private": true,
"scripts": {
"e2e": "npm run setup-profile && jest --verbose --forceExit",
"e2e-gen2": "jest --verbose --forceExit",
"setup-profile": "ts-node ./src/configure_tests.ts",
"clean-e2e-resources": "ts-node ./src/cleanup-e2e-resources.ts"
},
Expand All @@ -41,6 +42,7 @@
},
"devDependencies": {
"@types/jest": "^27.0.0",
"@aws-amplify/backend": "^1.0.0",
"graphql": "^15.8.0",
"ts-node": "^8.10.1"
},
Expand Down
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(),
};
};
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
};
};
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',
},
});
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
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
});
})
})
});
Loading
Loading