Skip to content

Commit

Permalink
chore: fix regression tests (aws#8054)
Browse files Browse the repository at this point in the history
The new-style integ tests don't run under the current regression test
framework. 2 changes:

1. The regression tests were downloading the repository SOURCE from
GitHub. That was fine as long as the tests were bash scripts (because
source == artifact there), but now the tests are compiled, so we need to
get the built artifacts (i.e., NPM package).

(This is also more efficient as there will be less to download)

2. Because of the specific arguments to jest (all regexes instead of
relative paths) and how it was being run, `jest` was finding and running
multiple copies of the tests, but only one had been bootstrapped so for
the other copy, `aws-sdk` was not found and the tests would error.

Introduce a `jest.config.js` so that jest will treat the
`test/integ/cli` directory as the root for tests and won't search
elsewhere. Put as much config into it as possible if we've got it
anyway (notably: `--runInBand` seems not to be able to go in there).

Since the regression test are going to run the tests from the PREVIOUS
version (which still has the bug), hotpatch the new test runner
config over the old one (but be sure to leave the actual tests the
same).
  • Loading branch information
rix0rrr authored May 18, 2020
1 parent bf0113b commit 9f446ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/aws-cdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ cdk.context.json
# as the subdirs contain .js files that should be committed)
test/integ/cli/*.js
test/integ/cli/*.d.ts
!test/integ/cli/jest.config.js
11 changes: 11 additions & 0 deletions packages/aws-cdk/test/integ/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
moduleFileExtensions: [
"js",
],
testMatch: [
"**/*.integtest.js",
],
testEnvironment: "node",
bail: 1,
verbose: true,
};
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/integ/cli/test-jest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ if ! npx --no-install jest --version; then
npm install --prefix . jest aws-sdk
fi

npx jest --runInBand --testPathPattern 'test/integ/cli' --testMatch '**/*.integtest.js' --verbose "$@"
npx jest --runInBand --verbose "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,21 @@ function download_repo {

# we need to download the repo code from GitHub in order to extract
# the integration tests that were present in that version of the repo.
# TODO - consider switching this to 'npm install',
# apparently we publish the integ tests in the package.
version=$1
#
# Download just the CLI tarball, which contains the tests. We can't
# use 'npm pack' here to obtain the tarball, as 'npm' commands may
# be redirected to a local Verdaccio.
#
# Rather than introducing another level of indirection to work around
# that, just go to npmjs.com directly.

out="${temp_dir}/.repo.tar.gz"
# Strip off leading 'v'
version=${1#v}

curl -L -o ${out} "https://github.com/aws/aws-cdk/archive/${version}.tar.gz"
tar --strip-components=1 -zxf ${out} -C ${temp_dir}
echo ${temp_dir}
out="${temp_dir}/.repo.tar.gz"

curl -Ssf -L -o ${out} "https://registry.npmjs.org/aws-cdk/-/aws-cdk-${version}.tgz"
tar -zxf ${out} -C ${temp_dir}
}

# this allows injecting different versions to be treated as the baseline
Expand All @@ -59,7 +64,7 @@ VERSION_UNDER_TEST=${VERSION_UNDER_TEST:-$(get_latest_published_version)}
trap cleanup INT EXIT

echo "Downloading aws-cdk repo version ${VERSION_UNDER_TEST}"
temp_repo_dir="$(download_repo ${VERSION_UNDER_TEST})"
download_repo ${VERSION_UNDER_TEST}

# remove '/' that is prevelant in our branch names but causes
# bad behvaior when using it as directory names.
Expand All @@ -68,7 +73,11 @@ sanitized_version=$(sed 's/\//-/g' <<< "${VERSION_UNDER_TEST}")
integ_under_test=${integdir}/cli-backwards-tests-${sanitized_version}
rm -rf ${integ_under_test}
echo "Copying integration tests of version ${VERSION_UNDER_TEST} to ${integ_under_test} (dont worry, its gitignored)"
cp -r ${temp_dir}/packages/aws-cdk/test/integ/cli ${integ_under_test}
cp -r ${temp_dir}/package/test/integ/cli ${integ_under_test}

echo "Hotpatching the test runner (can be removed after release 1.40.0)" >&2
cp -r ${integdir}/cli/test-jest.sh ${integ_under_test}
cp -r ${integdir}/cli/jest.config.js ${integ_under_test}

echo "Running integration tests of version ${VERSION_UNDER_TEST} from ${integ_under_test}"
VERSION_UNDER_TEST=${VERSION_UNDER_TEST} ${integ_under_test}/test.sh

0 comments on commit 9f446ca

Please sign in to comment.