Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scripts): add test:e2e:legacy:preview #6538

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"test:ci": "lerna run test --since origin/main",
"test:e2e": "node ./tests/e2e/index.js && node ./tests/canary/canary",
"test:e2e:legacy": "cucumber-js --fail-fast",
"test:e2e:legacy:since:release": "./tests/e2e-legacy/index.js",
"test:e2e:legacy:preview": "./tests/e2e-legacy/preview.mjs",
"test:e2e:legacy:since:release": "./tests/e2e-legacy/since-release.mjs",
"test:functional": "jest --passWithNoTests --config tests/functional/jest.config.js && lerna run test:unit --scope \"@aws-sdk/client-*\"",
"test:integration": "jest --config jest.config.integ.js --passWithNoTests",
"test:integration:legacy": "yarn test:e2e:legacy",
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e-legacy/getAllTags.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { join } from "path";
import { execSync } from "child_process";
import { getDirName } from "./getDirName.mjs";

const __dirname = getDirName();
const FEATURES_FOLDER = join(__dirname, "..", "..", "features");

const execOptions = {
...process,
cwd: __dirname,
encoding: "utf-8",
};

export const getAllTags = () =>
execSync(`grep -h ^@ ${join(FEATURES_FOLDER, "**", "*.feature")}`, execOptions).split(/[\n ]/g);
4 changes: 4 additions & 0 deletions tests/e2e-legacy/getDirName.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { dirname } from "path";
import { fileURLToPath } from "url";

export const getDirName = () => dirname(fileURLToPath(import.meta.url));
5 changes: 5 additions & 0 deletions tests/e2e-legacy/getPackageTags.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const getPackageTags = (packages) =>
packages
.map((name) => name.replace("@aws-sdk/client-", ""))
.map((name) => name.replace("-", ""))
.map((name) => `@${name}`);
49 changes: 0 additions & 49 deletions tests/e2e-legacy/index.js

This file was deleted.

25 changes: 25 additions & 0 deletions tests/e2e-legacy/preview.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node

import { execSync } from "child_process";
import { getDirName } from "./getDirName.mjs";
import { getAllTags } from "./getAllTags.mjs";
import { getPackageTags } from "./getPackageTags.mjs";
import { runTestForTags } from "./runTestForTags.mjs";

const __dirname = getDirName();

const execOptions = { ...process, cwd: __dirname, encoding: "utf-8" };
const commitMessage = execSync(`git show -s --format=%s`, execOptions);
const prefix = commitMessage.split(":")[0];
const scope = prefix.substring(prefix.indexOf("(") + 1, prefix.indexOf(")"));
console.info(`Updated scope: ${scope}`);

if (!scope) {
console.info(`Couldn't find scope in commit message '${commitMessage}'`);
process.exit(1);
}

const allTags = getAllTags();
const changedPackageTags = getPackageTags([`@aws-sdk/${scope}`]);
const tagsToTest = changedPackageTags.filter((tag) => allTags.includes(tag));
runTestForTags(tagsToTest);
26 changes: 26 additions & 0 deletions tests/e2e-legacy/runTestForTags.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { join, resolve } from "path";
import { spawn } from "child_process";
import { getDirName } from "./getDirName.mjs";

const __dirname = getDirName();
const ROOT = resolve(join(__dirname, "..", ".."));

export const runTestForTags = (tagsToTest) => {
if (tagsToTest.length === 0) {
console.info("No clients with e2e-legacy test cases have changed.");
return;
}

// Cucumber requires cwd to contain the test cases.
const command = `${join("node_modules", ".bin", "cucumber-js")}`;
const args = ["--fail-fast", "-t", `"${tagsToTest.join(" or ")}"`];
console.info(`Running cucumber test: \n${command} ${args.join(" ")}`);

const execOptions = { ...process, cwd: ROOT, encoding: "utf-8", shell: true };
const cucumber = spawn(command, args, execOptions);
cucumber.stdout.pipe(process.stdout);
cucumber.stderr.pipe(process.stderr);
cucumber.on("close", (code) => {
process.exit(code);
});
};
25 changes: 25 additions & 0 deletions tests/e2e-legacy/since-release.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node

import { join } from "path";
import { execSync } from "child_process";
import { getDirName } from "./getDirName.mjs";
import { getAllTags } from "./getAllTags.mjs";
import { getPackageTags } from "./getPackageTags.mjs";
import { runTestForTags } from "./runTestForTags.mjs";

const __dirname = getDirName();
const ROOT_BIN = join(__dirname, "..", "..", "node_modules", ".bin");

console.info(`Looking for changed packages...`);
let changedPackages = [];
try {
const execOptions = { ...process, cwd: __dirname, encoding: "utf-8" };
changedPackages = execSync(`${join(ROOT_BIN, "lerna")} changed`, execOptions).split("\n");
} catch (e) {
// Swallow error because Lerna throws if no package changes.
trivikr marked this conversation as resolved.
Show resolved Hide resolved
}

const allTags = getAllTags();
const changedPackageTags = getPackageTags(changedPackages);
const tagsToTest = changedPackageTags.filter((tag) => allTags.includes(tag));
runTestForTags(tagsToTest);
Loading