-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scripts): add test:e2e:legacy:preview (#6538)
- Loading branch information
Showing
8 changed files
with
102 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
|
||
const allTags = getAllTags(); | ||
const changedPackageTags = getPackageTags(changedPackages); | ||
const tagsToTest = changedPackageTags.filter((tag) => allTags.includes(tag)); | ||
runTestForTags(tagsToTest); |