Skip to content

Commit 9196552

Browse files
authored
feat(scripts): add test:e2e:legacy:preview (#6538)
1 parent 021f218 commit 9196552

8 files changed

+102
-50
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"test:ci": "lerna run test --since origin/main",
3737
"test:e2e": "node ./tests/e2e/index.js && node ./tests/canary/canary",
3838
"test:e2e:legacy": "cucumber-js --fail-fast",
39-
"test:e2e:legacy:since:release": "./tests/e2e-legacy/index.js",
39+
"test:e2e:legacy:preview": "./tests/e2e-legacy/preview.mjs",
40+
"test:e2e:legacy:since:release": "./tests/e2e-legacy/since-release.mjs",
4041
"test:functional": "jest --passWithNoTests --config tests/functional/jest.config.js && lerna run test:unit --scope \"@aws-sdk/client-*\"",
4142
"test:integration": "jest --config jest.config.integ.js --passWithNoTests",
4243
"test:integration:legacy": "yarn test:e2e:legacy",

tests/e2e-legacy/getAllTags.mjs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { join } from "path";
2+
import { execSync } from "child_process";
3+
import { getDirName } from "./getDirName.mjs";
4+
5+
const __dirname = getDirName();
6+
const FEATURES_FOLDER = join(__dirname, "..", "..", "features");
7+
8+
const execOptions = {
9+
...process,
10+
cwd: __dirname,
11+
encoding: "utf-8",
12+
};
13+
14+
export const getAllTags = () =>
15+
execSync(`grep -h ^@ ${join(FEATURES_FOLDER, "**", "*.feature")}`, execOptions).split(/[\n ]/g);

tests/e2e-legacy/getDirName.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { dirname } from "path";
2+
import { fileURLToPath } from "url";
3+
4+
export const getDirName = () => dirname(fileURLToPath(import.meta.url));

tests/e2e-legacy/getPackageTags.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const getPackageTags = (packages) =>
2+
packages
3+
.map((name) => name.replace("@aws-sdk/client-", ""))
4+
.map((name) => name.replace("-", ""))
5+
.map((name) => `@${name}`);

tests/e2e-legacy/index.js

-49
This file was deleted.

tests/e2e-legacy/preview.mjs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
3+
import { execSync } from "child_process";
4+
import { getDirName } from "./getDirName.mjs";
5+
import { getAllTags } from "./getAllTags.mjs";
6+
import { getPackageTags } from "./getPackageTags.mjs";
7+
import { runTestForTags } from "./runTestForTags.mjs";
8+
9+
const __dirname = getDirName();
10+
11+
const execOptions = { ...process, cwd: __dirname, encoding: "utf-8" };
12+
const commitMessage = execSync(`git show -s --format=%s`, execOptions);
13+
const prefix = commitMessage.split(":")[0];
14+
const scope = prefix.substring(prefix.indexOf("(") + 1, prefix.indexOf(")"));
15+
console.info(`Updated scope: ${scope}`);
16+
17+
if (!scope) {
18+
console.info(`Couldn't find scope in commit message '${commitMessage}'`);
19+
process.exit(1);
20+
}
21+
22+
const allTags = getAllTags();
23+
const changedPackageTags = getPackageTags([`@aws-sdk/${scope}`]);
24+
const tagsToTest = changedPackageTags.filter((tag) => allTags.includes(tag));
25+
runTestForTags(tagsToTest);

tests/e2e-legacy/runTestForTags.mjs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { join, resolve } from "path";
2+
import { spawn } from "child_process";
3+
import { getDirName } from "./getDirName.mjs";
4+
5+
const __dirname = getDirName();
6+
const ROOT = resolve(join(__dirname, "..", ".."));
7+
8+
export const runTestForTags = (tagsToTest) => {
9+
if (tagsToTest.length === 0) {
10+
console.info("No clients with e2e-legacy test cases have changed.");
11+
return;
12+
}
13+
14+
// Cucumber requires cwd to contain the test cases.
15+
const command = `${join("node_modules", ".bin", "cucumber-js")}`;
16+
const args = ["--fail-fast", "-t", `"${tagsToTest.join(" or ")}"`];
17+
console.info(`Running cucumber test: \n${command} ${args.join(" ")}`);
18+
19+
const execOptions = { ...process, cwd: ROOT, encoding: "utf-8", shell: true };
20+
const cucumber = spawn(command, args, execOptions);
21+
cucumber.stdout.pipe(process.stdout);
22+
cucumber.stderr.pipe(process.stderr);
23+
cucumber.on("close", (code) => {
24+
process.exit(code);
25+
});
26+
};

tests/e2e-legacy/since-release.mjs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
3+
import { join } from "path";
4+
import { execSync } from "child_process";
5+
import { getDirName } from "./getDirName.mjs";
6+
import { getAllTags } from "./getAllTags.mjs";
7+
import { getPackageTags } from "./getPackageTags.mjs";
8+
import { runTestForTags } from "./runTestForTags.mjs";
9+
10+
const __dirname = getDirName();
11+
const ROOT_BIN = join(__dirname, "..", "..", "node_modules", ".bin");
12+
13+
console.info(`Looking for changed packages...`);
14+
let changedPackages = [];
15+
try {
16+
const execOptions = { ...process, cwd: __dirname, encoding: "utf-8" };
17+
changedPackages = execSync(`${join(ROOT_BIN, "lerna")} changed`, execOptions).split("\n");
18+
} catch (e) {
19+
// Swallow error because Lerna throws if no package changes.
20+
}
21+
22+
const allTags = getAllTags();
23+
const changedPackageTags = getPackageTags(changedPackages);
24+
const tagsToTest = changedPackageTags.filter((tag) => allTags.includes(tag));
25+
runTestForTags(tagsToTest);

0 commit comments

Comments
 (0)