Skip to content

Commit ec9a2ba

Browse files
committed
cb: enable basic e2e test coverage
1 parent b9556c6 commit ec9a2ba

File tree

6 files changed

+105
-11
lines changed

6 files changed

+105
-11
lines changed

.circleci/local_publish_helpers.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function unsetSudoNpmRegistryUrl {
153153
}
154154

155155
function changeNpmGlobalPath {
156-
mkdir -p ~/.npm-global
156+
mkdir -p ~/.npm-global/{bin,lib}
157157
npm config set prefix '~/.npm-global'
158158
export PATH=~/.npm-global/bin:$PATH
159159
}
@@ -269,14 +269,32 @@ function setAwsAccountCredentials {
269269
}
270270

271271
function runE2eTest {
272+
_setupCoverage
272273
FAILED_TEST_REGEX_FILE="./amplify-e2e-reports/amplify-e2e-failed-test.txt"
273274

274275
if [ -f $FAILED_TEST_REGEX_FILE ]; then
275276
# read the content of failed tests
276277
failedTests=$(<$FAILED_TEST_REGEX_FILE)
277-
yarn run e2e --forceExit --no-cache --maxWorkers=4 $TEST_SUITE -t "$failedTests"
278+
NODE_V8_COVERAGE=$E2E_TEST_COVERAGE_DIR yarn run e2e --forceExit --no-cache --maxWorkers=4 $TEST_SUITE -t "$failedTests"
278279
else
279-
yarn run e2e --forceExit --no-cache --maxWorkers=4 $TEST_SUITE
280+
NODE_V8_COVERAGE=$E2E_TEST_COVERAGE_DIR yarn run e2e --forceExit --no-cache --maxWorkers=4 $TEST_SUITE
281+
fi
282+
}
283+
284+
function _setupCoverage {
285+
_teardownCoverage
286+
echo "Setup Coverage ($E2E_TEST_COVERAGE_DIR)"
287+
if [ ! -d $E2E_TEST_COVERAGE_DIR ]
288+
then
289+
mkdir -p $E2E_TEST_COVERAGE_DIR
290+
fi
291+
}
292+
293+
function _teardownCoverage {
294+
if [ -d $E2E_TEST_COVERAGE_DIR ]
295+
then
296+
echo "Teardown Coverage ($E2E_TEST_COVERAGE_DIR)"
297+
rm -r $E2E_TEST_COVERAGE_DIR
280298
fi
281299
}
282300

codebuild_specs/e2e_workflow.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ batch:
100100
debug-session: true
101101
depend-on:
102102
- upload_pkg_binaries
103+
- identifier: run_coverage_linux
104+
buildspec: codebuild_specs/run_coverage_linux.yml
105+
env:
106+
compute-type: BUILD_GENERAL1_MEDIUM
107+
debug-session: true
108+
depend-on:
109+
- run_e2e_tests_linux
103110
- identifier: run_e2e_tests_windows
104111
buildspec: codebuild_specs/run_e2e_tests_windows.yml
105112
env:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: 0.2
2+
env:
3+
shell: bash
4+
variables:
5+
CLI_REGION: us-east-1
6+
E2E_TEST_COVERAGE_DIR: node_v8_coverage
7+
secrets-manager:
8+
CODECOV_TOKEN: arn:aws:secretsmanager:us-east-1:052112422291:secret:testing/codecov/token-OB8isC
9+
phases:
10+
build:
11+
commands:
12+
# you can provide a codebuild source version to use old cache and skip all other jobs :)
13+
- export CODEBUILD_SOURCE_VERSION=00f31ea25fc27aa865198398e5014ea4d6a126d9
14+
- export NODE_OPTIONS=--max-old-space-size=8096
15+
- export AMPLIFY_DIR=$CODEBUILD_SRC_DIR/out
16+
- export AMPLIFY_PATH=$CODEBUILD_SRC_DIR/out/amplify-pkg-linux-x64
17+
- echo $AMPLIFY_DIR
18+
- echo $AMPLIFY_PATH
19+
- echo "CODECOV_TOKEN=$CODECOV_TOKEN"
20+
- source ./shared-scripts.sh && _convertCoverage && _uploadCoverageLinux
21+
artifacts:
22+
files:
23+
- '**/*'
24+
base-directory: coverage
25+
26+
reports:
27+
aws-amplify-cli-e2e-coverage-report:
28+
files:
29+
- 'coverage/clover.xml'
30+
file-format: CLOVERXML

codebuild_specs/run_e2e_tests_linux.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ env:
33
shell: bash
44
variables:
55
CLI_REGION: us-east-1
6-
TEST_SUITE: src/__tests__/auth_2a.test.ts|src/__tests__/auth_2b.test.ts|src/__tests__/auth_2d.test.ts|src/__tests__/auth_2f.test.ts
6+
TEST_SUITE: src/__tests__/geo-add-b.test.ts
7+
E2E_TEST_COVERAGE_DIR: node_v8_coverage
78
CI: true
89
CIRCLECI: true
910
# mock values to test artifact scanning
@@ -26,19 +27,18 @@ phases:
2627
build:
2728
commands:
2829
# you can provide a codebuild source version to use old cache and skip all other jobs :)
30+
# - export CODEBUILD_SOURCE_VERSION=00f31ea25fc27aa865198398e5014ea4d6a126d9
2931
- export NODE_OPTIONS=--max-old-space-size=8096
30-
# - export CODEBUILD_SOURCE_VERSION=4610160556171f344780aeb2f0d01b7b20147b5d
3132
- export AMPLIFY_DIR=$CODEBUILD_SRC_DIR/out
3233
- export AMPLIFY_PATH=$CODEBUILD_SRC_DIR/out/amplify-pkg-linux-x64
3334
- echo $AMPLIFY_DIR
3435
- echo $AMPLIFY_PATH
3536
- source ./shared-scripts.sh && _runE2ETestsLinux
36-
- codebuild-breakpoint
3737
post_build:
3838
commands:
3939
- aws sts get-caller-identity
4040
- source ./shared-scripts.sh && _scanArtifacts
41-
4241
artifacts:
4342
files:
44-
- $CODEBUILD_SRC_DIR/packages/amplify-e2e-tests/amplify-e2e-reports/*
43+
- '**/*'
44+
base-directory: packages/amplify-e2e-tests/$E2E_TEST_COVERAGE_DIR

codecov.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ coverage:
1212
patch: off
1313
changes:
1414
default:
15-
target: 80%
1615
if_not_found: success

shared-scripts.sh

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,38 @@ function _install_packaged_cli_linux {
237237
export PATH=$AMPLIFY_DIR:$PATH
238238
cd $CODEBUILD_SRC_DIR
239239
}
240+
function _convertCoverage {
241+
echo Convert Coverage
242+
243+
source .circleci/local_publish_helpers.sh && startLocalRegistry "$CODEBUILD_SRC_DIR/.circleci/verdaccio.yaml"
244+
setNpmRegistryUrlToLocal
245+
changeNpmGlobalPath
246+
247+
# needs to pick up the new coverage directory
248+
# for reference, assuming e2e tests are run from the amplify-e2e-tests directory:
249+
# .../$NODE_V8_COVERAGE - generated with setting NODE_V8_COVERAGE env var
250+
# .../coverage/<reporter> - generated with c8 command above
251+
loadCache e2e-test-coverage-raw $E2E_TEST_COVERAGE_DIR
252+
npx c8 report --temp-directory $E2E_TEST_COVERAGE_DIR --all --src ./packages -x "**/node_modules/**" -x "**/__tests__/**" --exclude-after-remap "**/node_modules/**" -x "**/amplify-e2e-*/**" -x "**/.yarn/**" --allow-external --reporter clover
253+
}
254+
# https://docs.codecov.com/docs/codecov-uploader#integrity-checking-the-uploader
255+
function _uploadCoverageLinux {
256+
if [ -z ${CODECOV_TOKEN+x} ]
257+
then
258+
echo "CODECOV_TOKEN not set: No coverage will be uploaded."
259+
else
260+
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import # One-time step
261+
curl -Os https://uploader.codecov.io/latest/linux/codecov
262+
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
263+
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
264+
gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
265+
shasum -a 256 -c codecov.SHA256SUM
266+
267+
chmod +x codecov
268+
./codecov -t ${CODECOV_TOKEN}
269+
fi
270+
}
271+
# END COVERAGE FUNCTIONS
240272
function _runE2ETestsLinux {
241273
echo RUN E2E Tests Linux
242274

@@ -264,9 +296,17 @@ function _runE2ETestsLinux {
264296

265297
_loadTestAccountCredentials
266298

267-
retry runE2eTest
299+
#retry runE2eTest
300+
runE2eTest
301+
_unassumeTestAccountCredentials
302+
storeCache $E2E_TEST_COVERAGE_DIR e2e-test-coverage-raw
303+
}
304+
function _unassumeTestAccountCredentials {
305+
echo "Unassume Role"
306+
unset AWS_ACCESS_KEY_ID
307+
unset AWS_SECRET_ACCESS_KEY
308+
unset AWS_SESSION_TOKEN
268309
}
269-
270310

271311
function _scanArtifacts {
272312
if ! yarn ts-node .circleci/scan_artifacts_codebuild.ts; then

0 commit comments

Comments
 (0)