diff --git a/package.json b/package.json index 4c2bc74643cb..a5a023c1c02e 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 000000000000..64bb97ea051e --- /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 000000000000..23750f15d8f3 --- /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 000000000000..cbc8f905f0ae --- /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 c16a9fb0d09f..000000000000 --- 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 000000000000..eca4d185b83e --- /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 000000000000..9d9377669db7 --- /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 000000000000..8ec007ed82f9 --- /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);