Skip to content

Commit 9982796

Browse files
authored
Add tests for named require with local name (#339)
1 parent c42722f commit 9982796

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { CLIENTS_TO_TEST, LOCAL_NAME_SUFFIX } from "./config";
2+
import { getV2ClientsNewExpressionCode } from "./getV2ClientsNewExpressionCode";
3+
4+
export const getServiceRequireWithNameInput = (codegenComment: string) => {
5+
let serviceRequireInputContent = `${codegenComment}\n`;
6+
7+
serviceRequireInputContent += `const { \n${CLIENTS_TO_TEST.map(
8+
(clientName) => ` ${clientName}: ${clientName}${LOCAL_NAME_SUFFIX}`
9+
).join(`,\n`)}\n} = require("aws-sdk");\n`;
10+
serviceRequireInputContent += `\n`;
11+
serviceRequireInputContent += getV2ClientsNewExpressionCode(
12+
CLIENTS_TO_TEST.map((clientName) => `${clientName}${LOCAL_NAME_SUFFIX}`)
13+
);
14+
15+
return serviceRequireInputContent;
16+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { CLIENT_NAMES_MAP, CLIENT_PACKAGE_NAMES_MAP } from "../../src/transforms/v2-to-v3/config";
2+
import { CLIENTS_TO_TEST, LOCAL_NAME_SUFFIX } from "./config";
3+
import { getClientNamesSortedByPackageName } from "./getClientNamesSortedByPackageName";
4+
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
5+
6+
export const getServiceRequireWithNameOutput = (codegenComment: string) => {
7+
let globalRequireOutputContent = `${codegenComment}\n`;
8+
9+
const sortedClientNames = getClientNamesSortedByPackageName(CLIENTS_TO_TEST);
10+
globalRequireOutputContent += `const `;
11+
for (const v2ClientName of sortedClientNames) {
12+
const v3ClientName = CLIENT_NAMES_MAP[v2ClientName];
13+
const v3ClientPackageName = `@aws-sdk/${CLIENT_PACKAGE_NAMES_MAP[v2ClientName]}`;
14+
const v3ClientLocalName = `${v2ClientName}${LOCAL_NAME_SUFFIX}`;
15+
const v3RequireKeyValuePair =
16+
v3ClientName === v3ClientLocalName ? v3ClientName : `${v3ClientName}: ${v3ClientLocalName}`;
17+
globalRequireOutputContent +=
18+
`{\n` +
19+
` ${v3RequireKeyValuePair}\n` +
20+
` } = require("${v3ClientPackageName}"),\n` +
21+
` `;
22+
}
23+
globalRequireOutputContent = globalRequireOutputContent.replace(/,\n {6}$/, ";\n\n");
24+
globalRequireOutputContent += getV3ClientsNewExpressionCode(
25+
CLIENTS_TO_TEST.map((clientName) => `${clientName}${LOCAL_NAME_SUFFIX}`)
26+
);
27+
28+
return globalRequireOutputContent;
29+
};

scripts/generateNewClientTests/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { getServiceRequireDeepInput } from "./getServiceRequireDeepInput";
2121
import { getServiceRequireDeepOutput } from "./getServiceRequireDeepOutput";
2222
import { getServiceRequireInput } from "./getServiceRequireInput";
2323
import { getServiceRequireOutput } from "./getServiceRequireOutput";
24+
import { getServiceRequireWithNameInput } from "./getServiceRequireWithNameInput";
25+
import { getServiceRequireWithNameOutput } from "./getServiceRequireWithNameOutput";
2426

2527
// The "use strict" directive is added to so that comments can be attached to it.
2628
// Recast removes the comments while removing import/require.
@@ -52,6 +54,8 @@ const newClientTestsPath = join(__dirname, "..", "..", newClientsTestsFolder);
5254
["service-require.output.js", getServiceRequireOutput],
5355
["service-require-deep.input.js", getServiceRequireDeepInput],
5456
["service-require-deep.output.js", getServiceRequireDeepOutput],
57+
["service-require-with-name.input.js", getServiceRequireWithNameInput],
58+
["service-require-with-name.output.js", getServiceRequireWithNameOutput],
5559
] as [string, (comment: string) => string][]) {
5660
const filePath = join(newClientTestsPath, fileName);
5761
await writeFile(filePath, getFileContent(codegenComment));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This file is generated by scripts/generateNewClientTests/index.ts
2+
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.
3+
"use strict";
4+
const {
5+
ACM: ACMClient,
6+
AccessAnalyzer: AccessAnalyzerClient,
7+
Discovery: DiscoveryClient
8+
} = require("aws-sdk");
9+
10+
new ACMClient();
11+
new AccessAnalyzerClient();
12+
new DiscoveryClient();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file is generated by scripts/generateNewClientTests/index.ts
2+
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.
3+
"use strict";
4+
const {
5+
AccessAnalyzer: AccessAnalyzerClient
6+
} = require("@aws-sdk/client-accessanalyzer"),
7+
{
8+
ACM: ACMClient
9+
} = require("@aws-sdk/client-acm"),
10+
{
11+
ApplicationDiscoveryService: DiscoveryClient
12+
} = require("@aws-sdk/client-application-discovery-service");
13+
14+
new ACMClient();
15+
new AccessAnalyzerClient();
16+
new DiscoveryClient();

0 commit comments

Comments
 (0)