|
| 1 | +const { execSync, spawn } = require("child_process"); |
| 2 | +const { join } = require("path"); |
| 3 | +const { readFileSync, existsSync } = require("fs"); |
| 4 | +const { spawnPromise } = require("./spawn-promise"); |
| 5 | + |
| 6 | +const hasE2Etest = (packagePath) => { |
| 7 | + const path = join(packagePath, "package.json"); |
| 8 | + if (!existsSync(path)) return false; |
| 9 | + const pkgJson = JSON.parse(readFileSync(path).toString()); |
| 10 | + return Boolean(pkgJson.scripts["test:e2e"]); |
| 11 | +}; |
| 12 | + |
| 13 | +exports.runE2ETests = async (resourcesEnv) => { |
| 14 | + /** |
| 15 | + * Example output: |
| 16 | + /path/to/package:@aws-sdk/client-accessanalyzer:1.0.0-gamma.3 |
| 17 | + /path/to/package:@aws-sdk/client-acm-pca:1.0.0-gamma.3 |
| 18 | + /path/to/package:@aws-sdk/client-acm:1.0.0-gamma.3 |
| 19 | + */ |
| 20 | + const changedPackagesRecord = execSync( |
| 21 | + "./node_modules/.bin/lerna changed --all --parseable --long --loglevel silent" |
| 22 | + ); |
| 23 | + // Get array for changed package's path |
| 24 | + const changedPackages = changedPackagesRecord |
| 25 | + .toString() |
| 26 | + .split("\n") |
| 27 | + .map((record) => record.split(":").slice(0, 2)); |
| 28 | + const packagesToTest = changedPackages.filter((changedPackage) => hasE2Etest(changedPackage[0])); |
| 29 | + console.log(`packages to run e2e test: |
| 30 | +${packagesToTest.map((package) => package[0]).join("\n")}`); |
| 31 | + await spawnPromise( |
| 32 | + "./node_modules/.bin/lerna", |
| 33 | + [ |
| 34 | + "run", |
| 35 | + "test:e2e", |
| 36 | + "--scope", |
| 37 | + `'{${packagesToTest.map((package) => package[1]).join(",")}}'`, // https://github.com/lerna/lerna/issues/1846#issuecomment-451172783 |
| 38 | + "--concurrency", |
| 39 | + "1", |
| 40 | + ], |
| 41 | + { |
| 42 | + env: { |
| 43 | + ...process.env, |
| 44 | + ...resourcesEnv, |
| 45 | + }, |
| 46 | + stdio: "inherit", |
| 47 | + } |
| 48 | + ); |
| 49 | +}; |
0 commit comments