Skip to content

Commit

Permalink
test: remove old invoker shims from mock package
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle committed Feb 12, 2021
1 parent fa6fa8a commit ae1e138
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 149 deletions.
11 changes: 2 additions & 9 deletions packages/amplify-util-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,12 @@
},
"dependencies": {
"@hapi/topo": "^5.0.0",
<<<<<<< HEAD
"amplify-appsync-simulator": "1.25.2",
"amplify-category-function": "2.29.0",
"amplify-cli-core": "1.16.0",
"amplify-codegen": "2.21.1",
"amplify-dynamodb-simulator": "1.17.8",
=======
"amplify-appsync-simulator": "1.25.0",
"amplify-category-function": "2.28.4",
"amplify-cli-core": "1.14.1",
"amplify-codegen": "2.20.5",
"amplify-dynamodb-simulator": "1.17.6",
"amplify-provider-awscloudformation": "4.36.1",
>>>>>>> feat: load admin ui creds into lambda mock env vars
"amplify-provider-awscloudformation": "4.38.0",
"amplify-storage-simulator": "1.5.1",
"chokidar": "^3.3.1",
"detect-port": "^1.3.0",
Expand All @@ -57,6 +49,7 @@
"@types/semver": "^7.1.0",
"@types/which": "^1.3.2",
"amplify-function-plugin-interface": "1.6.0",
"amplify-nodejs-function-runtime-provider": "1.4.3",
"aws-appsync": "^2.0.2",
"aws-sdk": "^2.765.0",
"aws-sdk-mock": "^5.1.0",
Expand Down
11 changes: 8 additions & 3 deletions packages/amplify-util-mock/src/__e2e__/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import * as path from 'path';
import { v4 } from 'uuid';
import { processTransformerStacks } from '../../CFNParser/appsync-resource-processor';
import { configureDDBDataSource, createAndUpdateTable } from '../../utils/dynamo-db';
import { invoke } from '../../utils/lambda/invoke';
import { getFunctionDetails } from './lambda-helper';
import { DynamoDB } from 'aws-sdk';
import { functionRuntimeContributorFactory } from 'amplify-nodejs-function-runtime-provider';

const invoke = functionRuntimeContributorFactory({}).invoke;

jest.mock('amplify-cli-core', () => ({
pathManager: {
Expand Down Expand Up @@ -73,8 +75,11 @@ async function configureLambdaDataSource(config) {
d.invoke = payload => {
logDebug('Invoking lambda with config', lambdaConfig);
return invoke({
...lambdaConfig,
event: payload,
srcRoot: lambdaConfig.packageFolder,
env: 'test',
runtime: 'nodejs',
handler: `${functionName}.${lambdaConfig.handler}`,
event: JSON.stringify(payload),
});
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs-extra';

export function getFunctionDetails(fnName: string) {
const lambdaFolder = path.join(__dirname, 'lambda_functions');
if (!fs.existsSync(path.join(lambdaFolder, `${fnName}.js`))) {
if (!fs.existsSync(path.join(lambdaFolder, 'src', `${fnName}.js`))) {
throw new Error(`Can not find lambda function ${fnName}`);
}

Expand Down
1 change: 0 additions & 1 deletion packages/amplify-util-mock/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ export class APITest {
}

private async startDynamoDBLocalServer(context) {
const { projectPath } = context.amplify.getEnvInfo();
const dbPath = path.join(await getMockDataDirectory(context), 'dynamodb');
fs.ensureDirSync(dbPath);
const mockConfig = await getMockConfig(context);
Expand Down
105 changes: 0 additions & 105 deletions packages/amplify-util-mock/src/utils/lambda/execute.ts

This file was deleted.

24 changes: 0 additions & 24 deletions packages/amplify-util-mock/src/utils/lambda/invoke.ts

This file was deleted.

7 changes: 2 additions & 5 deletions packages/amplify-util-mock/src/utils/mock-config-file.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import * as path from 'path';
import * as fs from 'fs';
import { $TSAny, JSONUtilities } from 'amplify-cli-core';

export function getMockConfig(context) {
const { projectPath } = context.amplify.getEnvInfo();
const mockConfigPath = path.join(projectPath, 'amplify', 'mock.json');
if (fs.existsSync(mockConfigPath)) {
return JSON.parse(fs.readFileSync(mockConfigPath).toString('UTF-8'));
}
return {};
return JSONUtilities.readJson<$TSAny>(mockConfigPath, { throwIfNotExist: false }) ?? {};
}
3 changes: 2 additions & 1 deletion packages/amplify-util-mock/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{"path": "../amplify-category-function"},
{"path": "../amplify-cli-core"},
{"path": "../amplify-storage-simulator"},
{"path": "../amplify-provider-awscloudformation"}
{"path": "../amplify-provider-awscloudformation"},
{"path": "../amplify-nodejs-function-runtime-provider"}
],
}

0 comments on commit ae1e138

Please sign in to comment.