From 0b5396c62061cb1270baeb06e7c00caaf459e2dc Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:02:46 +0000 Subject: [PATCH] feat(scripts): add test:e2e:legacy:preview --- package.json | 3 +- tests/e2e-legacy/getAllTags.mjs | 15 +++++++++ tests/e2e-legacy/getDirName.mjs | 4 +++ tests/e2e-legacy/getPackageTags.mjs | 5 +++ tests/e2e-legacy/index.js | 49 ----------------------------- tests/e2e-legacy/preview.mjs | 25 +++++++++++++++ tests/e2e-legacy/runTestForTags.mjs | 26 +++++++++++++++ tests/e2e-legacy/since-release.mjs | 25 +++++++++++++++ 8 files changed, 102 insertions(+), 50 deletions(-) create mode 100644 tests/e2e-legacy/getAllTags.mjs create mode 100644 tests/e2e-legacy/getDirName.mjs create mode 100644 tests/e2e-legacy/getPackageTags.mjs delete mode 100755 tests/e2e-legacy/index.js create mode 100755 tests/e2e-legacy/preview.mjs create mode 100644 tests/e2e-legacy/runTestForTags.mjs create mode 100755 tests/e2e-legacy/since-release.mjs diff --git a/package.json b/package.json index 4c2bc74643cbb..a5a023c1c02ed 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/e2e-legacy/getAllTags.mjs b/tests/e2e-legacy/getAllTags.mjs new file mode 100644 index 0000000000000..64bb97ea051e1 --- /dev/null +++ b/tests/e2e-legacy/getAllTags.mjs @@ -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); diff --git a/tests/e2e-legacy/getDirName.mjs b/tests/e2e-legacy/getDirName.mjs new file mode 100644 index 0000000000000..23750f15d8f31 --- /dev/null +++ b/tests/e2e-legacy/getDirName.mjs @@ -0,0 +1,4 @@ +import { dirname } from "path"; +import { fileURLToPath } from "url"; + +export const getDirName = () => dirname(fileURLToPath(import.meta.url)); diff --git a/tests/e2e-legacy/getPackageTags.mjs b/tests/e2e-legacy/getPackageTags.mjs new file mode 100644 index 0000000000000..cbc8f905f0ae5 --- /dev/null +++ b/tests/e2e-legacy/getPackageTags.mjs @@ -0,0 +1,5 @@ +export const getPackageTags = (packages) => + packages + .map((name) => name.replace("@aws-sdk/client-", "")) + .map((name) => name.replace("-")) + .map((name) => `@${name}`); diff --git a/tests/e2e-legacy/index.js b/tests/e2e-legacy/index.js deleted file mode 100755 index c16a9fb0d09f1..0000000000000 --- a/tests/e2e-legacy/index.js +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env node - -const { join, resolve } = require("path"); -const { execSync, spawn } = require("child_process"); - -const ROOT = resolve(join(__dirname, "..", "..")); -const FEATURES_FOLDER = join(ROOT, "features"); -const ROOT_BIN = join(ROOT, "node_modules", ".bin"); - -const execOptions = { - ...process, - cwd: __dirname, - encoding: "utf-8", -}; - -const allTags = execSync(`grep -h ^@ ${join(FEATURES_FOLDER, "**", "*.feature")}`, execOptions).split(/[\n ]/g); - -console.info(`Looking for changed clients that has the legacy e2e test tag: ${allTags}`); - -let changedPackages = []; -try { - changedPackages = execSync(`${join(ROOT_BIN, "lerna")} changed`, execOptions).split("\n"); -} catch (e) { - // Swallow error because Lerna throws if no package changes. -} -const changedPackageTags = changedPackages - .map((name) => name.replace("@aws-sdk/client-", "")) - .map((name) => name.replace("-")) - .map((name) => `@${name}`); - -const tagsToTest = changedPackageTags.filter((tag) => allTags.includes(tag)); - -if (tagsToTest.length === 0) { - console.info("No clients with integration test cases has changed since last release."); - 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 cucumber = spawn(command, args, { ...execOptions, cwd: ROOT, shell: true }); -cucumber.stdout.pipe(process.stdout); -cucumber.stderr.pipe(process.stderr); -cucumber.on("close", (code) => { - if (code === 0) process.exit(); - else process.exit(code); -}); diff --git a/tests/e2e-legacy/preview.mjs b/tests/e2e-legacy/preview.mjs new file mode 100755 index 0000000000000..eca4d185b83e2 --- /dev/null +++ b/tests/e2e-legacy/preview.mjs @@ -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"; +import conventionalCommitsParser from "conventional-commits-parser"; + +const __dirname = getDirName(); + +console.info(`Looking for updated client...`); +const execOptions = { ...process, cwd: __dirname, encoding: "utf-8" }; +const gitCommitMessage = execSync(`git show -s --format=%s`, execOptions); + +const { scope } = conventionalCommitsParser.sync(gitCommitMessage); +if (!scope) { + console.info(`Couldn't find scope in commit message '${gitCommitMessage}'`); + process.exit(1); +} + +const allTags = getAllTags(); +const changedPackageTags = getPackageTags([scope]); +const tagsToTest = changedPackageTags.filter((tag) => allTags.includes(tag)); +runTestForTags(tagsToTest); diff --git a/tests/e2e-legacy/runTestForTags.mjs b/tests/e2e-legacy/runTestForTags.mjs new file mode 100644 index 0000000000000..9d9377669db71 --- /dev/null +++ b/tests/e2e-legacy/runTestForTags.mjs @@ -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 integration 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 cucumber = spawn(command, args, { ...execOptions, cwd: ROOT, shell: true }); + cucumber.stdout.pipe(process.stdout); + cucumber.stderr.pipe(process.stderr); + cucumber.on("close", (code) => { + if (code === 0) process.exit(); + else process.exit(code); + }); +}; diff --git a/tests/e2e-legacy/since-release.mjs b/tests/e2e-legacy/since-release.mjs new file mode 100755 index 0000000000000..8ec007ed82f91 --- /dev/null +++ b/tests/e2e-legacy/since-release.mjs @@ -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. +} + +const allTags = getAllTags(); +const changedPackageTags = getPackageTags(changedPackages); +const tagsToTest = changedPackageTags.filter((tag) => allTags.includes(tag)); +runTestForTags(tagsToTest);