|
| 1 | +const fs = require("node:fs"); |
| 2 | +const path = require("node:path"); |
| 3 | +const { glob } = require("glob"); |
| 4 | +const { execSync } = require("node:child_process"); |
| 5 | + |
| 6 | +console.log("====", "canary runner", "===="); |
| 7 | + |
| 8 | +const root = path.join(__dirname, "..", ".."); |
| 9 | +const canaryPath = path.join(root, "..", "canary-aws-sdk-js-v3"); |
| 10 | + |
| 11 | +if (fs.existsSync(canaryPath)) { |
| 12 | + fs.rmSync(canaryPath, { recursive: true }); |
| 13 | +} |
| 14 | +fs.mkdirSync(canaryPath); |
| 15 | +fs.mkdirSync(path.join(canaryPath, "tests")); |
| 16 | + |
| 17 | +const e2eFiles = glob.sync("clients/**/test/*.e2e.spec.ts", { cwd: root }); |
| 18 | + |
| 19 | +const dependencies = new Set(); |
| 20 | + |
| 21 | +for (const file of e2eFiles) { |
| 22 | + const content = fs.readFileSync(path.join(root, file), "utf-8"); |
| 23 | + if ( |
| 24 | + !content.includes('from "./') && |
| 25 | + !content.includes('from "../') && |
| 26 | + !content.includes('from "@aws-sdk/aws-util-test/src"') |
| 27 | + ) { |
| 28 | + const dest = path.join(canaryPath, "tests", file); |
| 29 | + fs.mkdirSync(path.dirname(dest), { recursive: true }); |
| 30 | + fs.copyFileSync(path.join(root, file), dest); |
| 31 | + |
| 32 | + const importMatches = content.matchAll(/from ["']([^."'][^"']*)["']/g); |
| 33 | + for (const match of importMatches) { |
| 34 | + if (!match[1].startsWith("node:")) { |
| 35 | + const pkg = match[1].startsWith("@") ? match[1].split("/").slice(0, 2).join("/") : match[1].split("/")[0]; |
| 36 | + dependencies.add(pkg); |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +const packageJson = { |
| 43 | + name: "canary-aws-sdk-js-v3", |
| 44 | + private: true, |
| 45 | + scripts: { |
| 46 | + canary: "vitest run --retry=4 --test-timeout=60000", |
| 47 | + }, |
| 48 | + devDependencies: { |
| 49 | + ...Object.fromEntries([...dependencies].sort().map((dep) => [dep, "latest"])), |
| 50 | + "@aws-sdk/config": "latest", |
| 51 | + "happy-dom": "20.8.3", |
| 52 | + vitest: "^4.0.17", |
| 53 | + }, |
| 54 | +}; |
| 55 | + |
| 56 | +fs.writeFileSync(path.join(canaryPath, "package.json"), JSON.stringify(packageJson, null, 2)); |
| 57 | + |
| 58 | +const vitestConfig = `import { defineConfig } from "vitest/config"; |
| 59 | +
|
| 60 | +export default defineConfig({ |
| 61 | + resolve: { |
| 62 | + conditions: ["browser", "module", "import", "default"], |
| 63 | + mainFields: ["browser", "module", "main"], |
| 64 | + }, |
| 65 | + test: { |
| 66 | + include: ["**/*.e2e.spec.ts"], |
| 67 | + exclude: [ |
| 68 | + "**/*/node_modules/**/*.spec.ts", |
| 69 | + "node_modules", |
| 70 | + // doesn't support OPTIONS preflight. |
| 71 | + "tests/clients/client-data-pipeline/**/*.e2e.spec.ts", |
| 72 | + // requires .wav file. |
| 73 | + "tests/clients/client-transcribe-streaming/test/index.e2e.spec.ts", |
| 74 | + ], |
| 75 | + setupFiles: ["vitest.browser.setup.mts"], |
| 76 | + environment: "happy-dom", |
| 77 | + }, |
| 78 | +}); |
| 79 | +`; |
| 80 | + |
| 81 | +fs.writeFileSync(path.join(canaryPath, "vitest.config.mts"), vitestConfig); |
| 82 | +fs.copyFileSync(path.join(root, "vitest.nodejs.setup.mts"), path.join(canaryPath, "vitest.nodejs.setup.mts")); |
| 83 | + |
| 84 | +fs.mkdirSync(path.join(canaryPath, "scripts", "browser-testing"), { recursive: true }); |
| 85 | +fs.copyFileSync(path.join(root, "vitest.browser.setup.mts"), path.join(canaryPath, "vitest.browser.setup.mts")); |
| 86 | +fs.copyFileSync( |
| 87 | + path.join(root, "scripts", "browser-testing", "writeTestCredentials.mjs"), |
| 88 | + path.join(canaryPath, "scripts", "browser-testing", "writeTestCredentials.mjs") |
| 89 | +); |
| 90 | + |
| 91 | +fs.copyFileSync(path.join(__dirname, "canary-preinstall.js"), path.join(canaryPath, "canary-preinstall.js")); |
| 92 | +execSync("node canary-preinstall.js", { cwd: canaryPath, stdio: "inherit" }); |
| 93 | + |
| 94 | +try { |
| 95 | + console.info("attempting npm install"); |
| 96 | + execSync("npm install", { cwd: canaryPath, stdio: "inherit" }); |
| 97 | + console.info("npm install completed"); |
| 98 | +} catch (error) { |
| 99 | + // if npm installation fails, consider the issue transient. |
| 100 | + // It will be caught by a separate canary. |
| 101 | + console.error(error); |
| 102 | + console.info("letting npm installation error propagate to availability canary."); |
| 103 | + process.exit(0); |
| 104 | +} |
| 105 | + |
| 106 | +execSync("node ./scripts/browser-testing/writeTestCredentials.mjs", { cwd: canaryPath, stdio: "inherit" }); |
| 107 | +process.on("exit", () => { |
| 108 | + fs.rmSync(canaryPath, { recursive: true }); |
| 109 | +}); |
| 110 | + |
| 111 | +try { |
| 112 | + console.info("attempting npm run canary"); |
| 113 | + execSync("npm run canary", { cwd: canaryPath, stdio: "inherit" }); |
| 114 | + console.info("canary tests completed"); |
| 115 | + process.exit(0); |
| 116 | +} catch (error) { |
| 117 | + console.info("canary tests failed"); |
| 118 | + console.error(error); |
| 119 | + process.exit(error.status || 1); |
| 120 | +} |
0 commit comments