Skip to content

Commit c2b7b7d

Browse files
authored
chore: add command to e2e test changed packages (#1359)
* test: pick smock test region from env * chore: add global test:e2e script running e2e on changed pkgs
1 parent 97efeeb commit c2b7b7d

File tree

7 files changed

+105
-2
lines changed

7 files changed

+105
-2
lines changed

clients/client-cognito-identity/e2e/CognitoIdentity.ispec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { expect } from "chai";
77
import { CognitoIdentity } from "../index";
88
// There will be default values of defaultRegion, credentials, and isBrowser variable in browser tests.
99
// Define the values for Node.js tests
10-
const region: string | undefined = (globalThis as any).defaultRegion || undefined;
10+
const region: string | undefined = (globalThis as any).defaultRegion || process?.env?.AWS_SMOKE_TEST_REGION;
1111
const IdentityPoolId =
1212
(globalThis as any)?.window?.__env__?.AWS_SMOKE_TEST_IDENTITY_POOL_ID ||
1313
process?.env?.AWS_SMOKE_TEST_IDENTITY_POOL_ID;

clients/client-s3/e2e/S3.ispec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ chai.use(chaiAsPromised);
1212
const { expect } = chai;
1313
// There will be default values of defaultRegion, credentials, and isBrowser variable in browser tests.
1414
// Define the values for Node.js tests
15-
const region: string | undefined = (globalThis as any).defaultRegion || undefined;
15+
const region: string | undefined = (globalThis as any).defaultRegion || process?.env?.AWS_SMOKE_TEST_REGION;
1616
const credentials: Credentials | undefined = (globalThis as any).credentials || undefined;
1717
const isBrowser: boolean | undefined = (globalThis as any).isBrowser || false;
1818
const Bucket = (globalThis as any)?.window?.__env__?.AWS_SMOKE_TEST_BUCKET || process?.env?.AWS_SMOKE_TEST_BUCKET;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"test:integration-legacy": "cucumber-js --fail-fast",
2121
"test:integration": "jest --config jest.config.integ.js --passWithNoTests",
2222
"test:protocols": "yarn build:protocols && lerna run test --scope '@aws-sdk/aws-*'",
23+
"test:e2e": "node ./tests/e2e/index.js",
2324
"local-publish": "node ./scripts/verdaccio-publish/index.js"
2425
},
2526
"repository": {

tests/e2e/get-integ-test-resources.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { CloudFormationClient, DescribeStackResourcesCommand } = require("../../clients/client-cloudformation");
2+
3+
exports.getIntegTestResources = async () => {
4+
const client = new CloudFormationClient({});
5+
const region = await client.config.region();
6+
7+
const { StackResources: stackResources } = await client.send(
8+
new DescribeStackResourcesCommand({ StackName: "IntegTestResourcesStack" })
9+
);
10+
11+
const identityPoolId = stackResources.filter((resource) => resource.ResourceType === "AWS::Cognito::IdentityPool")[0]
12+
.PhysicalResourceId;
13+
14+
const bucketName = stackResources.filter(
15+
(resource) => resource.ResourceType === "AWS::S3::Bucket" && resource.LogicalResourceId.indexOf("IntegTest") === 0
16+
)[0].PhysicalResourceId;
17+
18+
return {
19+
AWS_SMOKE_TEST_REGION: region,
20+
AWS_SMOKE_TEST_IDENTITY_POOL_ID: identityPoolId,
21+
AWS_SMOKE_TEST_BUCKET: bucketName,
22+
};
23+
};

tests/e2e/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { getIntegTestResources } = require("./get-integ-test-resources");
2+
const { runE2ETests } = require("./run-e2e-tests");
3+
4+
const run = async () => {
5+
try {
6+
const integTestResourcesEnv = await getIntegTestResources();
7+
await runE2ETests(integTestResourcesEnv);
8+
} catch (e) {
9+
process.exit(1);
10+
}
11+
};
12+
13+
run();

tests/e2e/run-e2e-tests.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const { execSync, spawn } = require("child_process");
2+
const { join } = require("path");
3+
const { readFileSync, existsSync } = require("fs");
4+
const { spawnPromise } = require("./spawn-promise");
5+
6+
const hasE2Etest = (packagePath) => {
7+
const path = join(packagePath, "package.json");
8+
if (!existsSync(path)) return false;
9+
const pkgJson = JSON.parse(readFileSync(path).toString());
10+
return Boolean(pkgJson.scripts["test:e2e"]);
11+
};
12+
13+
exports.runE2ETests = async (resourcesEnv) => {
14+
/**
15+
* Example output:
16+
/path/to/package:@aws-sdk/client-accessanalyzer:1.0.0-gamma.3
17+
/path/to/package:@aws-sdk/client-acm-pca:1.0.0-gamma.3
18+
/path/to/package:@aws-sdk/client-acm:1.0.0-gamma.3
19+
*/
20+
const changedPackagesRecord = execSync(
21+
"./node_modules/.bin/lerna changed --all --parseable --long --loglevel silent"
22+
);
23+
// Get array for changed package's path
24+
const changedPackages = changedPackagesRecord
25+
.toString()
26+
.split("\n")
27+
.map((record) => record.split(":").slice(0, 2));
28+
const packagesToTest = changedPackages.filter((changedPackage) => hasE2Etest(changedPackage[0]));
29+
console.log(`packages to run e2e test:
30+
${packagesToTest.map((package) => package[0]).join("\n")}`);
31+
await spawnPromise(
32+
"./node_modules/.bin/lerna",
33+
[
34+
"run",
35+
"test:e2e",
36+
"--scope",
37+
`'{${packagesToTest.map((package) => package[1]).join(",")}}'`, // https://github.com/lerna/lerna/issues/1846#issuecomment-451172783
38+
"--concurrency",
39+
"1",
40+
],
41+
{
42+
env: {
43+
...process.env,
44+
...resourcesEnv,
45+
},
46+
stdio: "inherit",
47+
}
48+
);
49+
};

tests/e2e/spawn-promise.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { spawn } = require("child_process");
2+
3+
exports.spawnPromise = (command, options, spawnOptions) =>
4+
new Promise((resolve, reject) => {
5+
const ps = spawn(command, options, {
6+
stdio: "inherit",
7+
...spawnOptions,
8+
});
9+
ps.on("error", reject);
10+
ps.on("exit", (code) => {
11+
if (code !== 0) {
12+
reject(new Error(`Unexpected exit code [${code}]`));
13+
} else {
14+
resolve();
15+
}
16+
});
17+
});

0 commit comments

Comments
 (0)