From c3583241067d854b07d9689a1a45fc2cec536eb1 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Fri, 9 Dec 2022 17:50:24 +0000 Subject: [PATCH] chore(cli): integ test current version against all supported versions of TS (#23244) We currently only test against a single TS version as defined in the init-templates. This change will run these tests against all supported TS minor versions (currently `typescript@>=3.9`). A recent change on main that broke support for >=TS4.0 went undetected due to missing these tests. Tests are about 2min per TS version, with a total of 11 supported versions, these tests will now take 22min instead of 2min. Other actions in the same pipeline stage take 25min and over 50min (docs), so this shouldn't have an effect on total pipeline runtime. ~This PR is based off and tested with the last released version (v2.53.0), as `main` is currently not building.~ ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../integ/init/test-typescript-versions.sh | 29 +++++++++++++++++++ .../aws-cdk/test/integ/typescript-versions.ts | 10 +++++++ 2 files changed, 39 insertions(+) create mode 100755 packages/aws-cdk/test/integ/init/test-typescript-versions.sh create mode 100644 packages/aws-cdk/test/integ/typescript-versions.ts diff --git a/packages/aws-cdk/test/integ/init/test-typescript-versions.sh b/packages/aws-cdk/test/integ/init/test-typescript-versions.sh new file mode 100755 index 0000000000000..8df00129a7bff --- /dev/null +++ b/packages/aws-cdk/test/integ/init/test-typescript-versions.sh @@ -0,0 +1,29 @@ +#!/bin/bash +#------------------------------------------------------------------ +# setup +#------------------------------------------------------------------ +set -eu +scriptdir=$(cd $(dirname $0) && pwd) +integdir=$(dirname $scriptdir) +source ${scriptdir}/common.bash + +header TypeScript Versions + +#------------------------------------------------------------------ + +MIN_SUPPORTED_TS_VERSION=${1:-"3.9"} +SUPPORTED_TS_VERSIONS=$(node ${integdir}/typescript-versions.js ${MIN_SUPPORTED_TS_VERSION}) + +for version in $SUPPORTED_TS_VERSIONS; do + echo "Testing against TypeScript v$version" + + setup + + cdk init -l typescript sample-app --generate-only + npm pkg delete devDependencies + npm install --save-dev typescript@$version + npm prune && npm ls + rm test/* + npm run build + cdk synth +done diff --git a/packages/aws-cdk/test/integ/typescript-versions.ts b/packages/aws-cdk/test/integ/typescript-versions.ts new file mode 100644 index 0000000000000..cf86653b99793 --- /dev/null +++ b/packages/aws-cdk/test/integ/typescript-versions.ts @@ -0,0 +1,10 @@ +import { spawnSync } from 'child_process'; + +const minSupportedVersion = process.argv.slice(2, 3); + +const { stdout } = spawnSync('npm', ['--silent', 'view', `typescript@>=${minSupportedVersion}`, 'version', '--json']); + +const versions: string[] = JSON.parse(stdout); +const minorVersions = Array.from(new Set(versions.map(v => v.split('.').slice(0, 2).join('.')))); + +process.stdout.write(minorVersions.join(' '));