Skip to content

Commit

Permalink
feat: add android test
Browse files Browse the repository at this point in the history
  • Loading branch information
phani-srikar committed Jul 13, 2023
1 parent b435d50 commit dd635a0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
13 changes: 11 additions & 2 deletions .codebuild/e2e_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ batch:
variables:
TEST_SUITE: >-
src/__tests__/push-codegen-ios.test.ts|src/__tests__/push-codegen-android.test.ts|src/__tests__/graphql-documents-generator.test.ts|src/__tests__/push-codegen-js.test.ts
CLI_REGION: ap-northeast-1
CLI_REGION: ap-southeast-1
depend-on:
- publish_to_local_registry
- identifier: build_app_ts
Expand All @@ -109,7 +109,16 @@ batch:
compute-type: BUILD_GENERAL1_LARGE
variables:
TEST_SUITE: src/__tests__/build-app-ts.test.ts
CLI_REGION: ap-southeast-1
CLI_REGION: ap-southeast-2
depend-on:
- publish_to_local_registry
- identifier: build_app_android
buildspec: .codebuild/run_e2e_tests.yml
env:
compute-type: BUILD_GENERAL1_MEDIUM
variables:
TEST_SUITE: src/__tests__/build-app-android.test.ts
CLI_REGION: ap-northeast-1
depend-on:
- publish_to_local_registry
- identifier: cleanup_e2e_resources
Expand Down
35 changes: 14 additions & 21 deletions packages/amplify-codegen-e2e-core/src/categories/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { AmplifyFrontend } from '../utils';
import { getCLIPath, nspawn as spawn } from '..';

export function generateModels(cwd: string, outputDir?: string): Promise<void> {
export function generateModels(cwd: string, outputDir?: string, settings: { errMessage?: string } = {}): Promise<void> {
return new Promise((resolve, reject) => {
const params = ['codegen', 'models', ...(outputDir ? ['--output-dir', outputDir] : [])]
spawn(getCLIPath(), params, { cwd, stripColors: true })
.run((err: Error) => {
const chain = spawn(getCLIPath(), params, { cwd, stripColors: true });

if (settings?.errMessage) {
chain.wait(settings.errMessage);
}

chain.run((err: Error) => {
if (!err) {
resolve();
} else {
Expand Down Expand Up @@ -134,24 +139,13 @@ export function configureCodegen(cwd: string, settings: any = {}): Promise<void>
});
}

export function generateModelIntrospection(cwd: string, settings: { outputDir?: string} = {}): Promise<void> {
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['codegen', 'model-introspection', '--output-dir', settings.outputDir ?? ''], { cwd, stripColors: true })
.run((err: Error) => {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}

export function generateModelIntrospectionWithError(cwd: string, errMessage: string, settings: { outputDir?: string} = {}): Promise<void> {
export function generateModelIntrospection(cwd: string, settings: { outputDir?: string, errMessage?: string} = {}): Promise<void> {
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['codegen', 'model-introspection', '--output-dir', settings.outputDir ?? ''], { cwd, stripColors: true })
.wait(errMessage)
.run((err: Error) => {
const chain = spawn(getCLIPath(), ['codegen', 'model-introspection', '--output-dir', settings.outputDir ?? ''], { cwd, stripColors: true });
if (settings?.errMessage) {
chain.wait(settings.errMessage);
}
chain.run((err: Error) => {
if (!err) {
resolve();
} else {
Expand Down Expand Up @@ -188,4 +182,3 @@ export function addCodegenNonAmplifyJS(cwd: string): Promise<void> {
});
});
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('env codegen tests', () => {
await addEnvironment(projectRoot, { envName: 'envb' });
//update schema to a invalid one in envb and generate models
updateApiSchema(projectRoot, apiName, schemaWithError)
await expect(generateModels(projectRoot)).rejects.toThrowError();
await expect(generateModels(projectRoot, undefined, { errMessage: 'Unknown type' }));
//checkout back to enva and generate models
await checkoutEnvironment(projectRoot, { envName: 'enva', withRestore: true });
await expect(generateModels(projectRoot)).resolves.not.toThrow();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addApiWithoutSchema, createNewProjectDir, generateModelIntrospection, initJSProjectWithProfile, updateApiSchema, generateModelIntrospectionWithError } from "@aws-amplify/amplify-codegen-e2e-core";
import { addApiWithoutSchema, createNewProjectDir, generateModelIntrospection, initJSProjectWithProfile, updateApiSchema } from "@aws-amplify/amplify-codegen-e2e-core";
import { deleteAmplifyProject } from '../codegen-tests-base';
import { isNotEmptyDir } from "../utils";
import { join } from 'path';
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('Model Introspection Codegen test', () => {
await addApiWithoutSchema(projectRoot, { apiName });
await updateApiSchema(projectRoot, apiName, schema);
//generate introspection schema
await generateModelIntrospectionWithError(projectRoot, 'Expected --output-dir flag to be set');
await generateModelIntrospection(projectRoot, { errMessage: 'Expected --output-dir flag to be set'});
});

it('should throw error if the GraphQL schema is invalid', async () => {
Expand All @@ -46,7 +46,7 @@ describe('Model Introspection Codegen test', () => {
await updateApiSchema(projectRoot, apiName, invalidSchema);
const outputDir = 'output';
//generate introspection schema
await generateModelIntrospectionWithError(projectRoot, 'Unknown type', { outputDir });
await generateModelIntrospection(projectRoot,{ outputDir, errMessage: 'Unknown type'});
});

it(`should handle a schema with connected PK`, async () => {
Expand Down
5 changes: 3 additions & 2 deletions scripts/split-e2e-tests-codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ const REPO_ROOT = join(__dirname, '..');
const TEST_TIMINGS_PATH = join(REPO_ROOT, 'scripts', 'cci', 'test-timings.data.json');
const CODEBUILD_CONFIG_BASE_PATH = join(REPO_ROOT, '.codebuild', 'e2e_workflow_base.yml');
const CODEBUILD_GENERATE_CONFIG_PATH = join(REPO_ROOT, '.codebuild', 'e2e_workflow.yml');
const RUN_SOLO = [];
const RUN_SOLO = [
'src/__tests__/build-app-android.test.ts',
];
const EXCLUDE_TESTS = [
'src/__tests__/build-app-swift.test.ts',
'src/__tests__/build-app-android.test.ts',
];

export function loadConfigBase() {
Expand Down

0 comments on commit dd635a0

Please sign in to comment.