From 17a9ec73868e9bd5c4509b132f913b378b4b5e95 Mon Sep 17 00:00:00 2001 From: Przemyslaw Motacki Date: Mon, 10 Jul 2023 09:55:30 +0200 Subject: [PATCH] SNOW-830950: Configuration of nyc - code coverage library (#519) SNOW-830950: Configure nyc - code coverage library and corresponding steps in jenkins steps #430 --- .github/workflows/build-test.yml | 25 +++++++++++++++++++++++++ .gitignore | 2 +- README.md | 29 ++--------------------------- ci/container/package.json | 1 + ci/container/test_component.sh | 14 +++++++++++--- ci/test_mac.sh | 4 +++- package.json | 7 ++++++- 7 files changed, 49 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 5eb27ccc4..7af08f9b4 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -69,6 +69,10 @@ jobs: PARAMETERS_SECRET: ${{ secrets.PARAMETERS_SECRET }} CLOUD_PROVIDER: ${{ matrix.cloud }} run: /usr/local/bin/bash ./ci/test_mac.sh + - uses: actions/upload-artifact@master + with: + name: codeCoverage + path: .nyc_output test-windows-required: needs: build @@ -210,3 +214,24 @@ jobs: CLOUD_PROVIDER: ${{ matrix.cloud }} TARGET_DOCKER_TEST_IMAGE: ${{ matrix.image }} run: ./ci/test.sh + + display_code_coverage: + needs: test-mac-required + name: Display code coverage + runs-on: macos-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: '18.x' + - name: Download Build Artifacts + uses: actions/download-artifact@v1 + with: + name: artifacts + - uses: actions/download-artifact@master + with: + name: codeCoverage + path: .nyc_output + - name: Display code coverage + shell: bash + run: npx nyc report --reporter=text diff --git a/.gitignore b/.gitignore index 457e9de53..77d6b857b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ __pycache__/ wss-*-agent.config wss-unified-agent.jar whitesource/ - +.nyc_output diff --git a/README.md b/README.md index d98bdc5c2..d4b7bbb22 100644 --- a/README.md +++ b/README.md @@ -84,37 +84,12 @@ npm test:integration Getting the code coverage ---------------------------------------------------------------------- -1. Go to nodejs project directory -``` -cd snowflake-connector-nodejs -``` - -2. Install the node connector -``` -npm install . -``` - -3. Install the nyc module which displays the code coverage -``` -npm install nyc -``` - -4. Edit the package.json file and replace the specified test with the one below: -``` -"scripts": { - "test": "nyc mocha test/**/*.js" -}, -``` -5. Using git bash, run the "npm test" command and include the connection parameters in the same line: +Run tests and show code coverage report ``` -SNOWFLAKE_TEST_USER="user" SNOWFLAKE_TEST_PASSWORD="password" SNOWFLAKE_TEST_ACCOUNT="account" SNOWFLAKE_TEST_WAREHOUSE="warehouse" SNOWFLAKE_TEST_DATABASE="db" SNOWFLAKE_TEST_SCHEMA="schema" npm test +npm run test:ci:coverage ``` -6. The code coverage results will be displayed in the console when the test finishes executing -
-Note: git bash is the console used for installing the node connector, the nyc module, and running "npm test" - Package ====================================================================== diff --git a/ci/container/package.json b/ci/container/package.json index 9191bbb6b..d2072e8b0 100644 --- a/ci/container/package.json +++ b/ci/container/package.json @@ -13,6 +13,7 @@ "insert-module-globals": "^7.2.0", "mocha": "^5.2.0", "mock-require": "^3.0.3", + "nyc": "^15.1.0", "test-console": "^2.0.0", "vinyl-buffer": "^1.0.1", "vinyl-source-stream": "^1.1.2" diff --git a/ci/container/test_component.sh b/ci/container/test_component.sh index 8c805eccd..5c6b36640 100755 --- a/ci/container/test_component.sh +++ b/ci/container/test_component.sh @@ -66,9 +66,17 @@ env | grep SNOWFLAKE_ | grep -v PASS echo "[INFO] Starting hang_webserver.py 12345" python3 $THIS_DIR/hang_webserver.py 12345 > hang_webserver.out 2>&1 & -MOCHA_CMD=( - "mocha" "--timeout" "$TIMEOUT" "--recursive" "--full-trace" -) + +if [[ "$SHOULD_GENERATE_COVERAGE_REPORT" -eq "1" && "$CLOUD_PROVIDER" == "AWS" ]]; + then + MOCHA_CMD=( + "npx" "nyc" "mocha" "--exit" "--timeout" "$TIMEOUT" "--recursive" "--full-trace" + ) + else + MOCHA_CMD=( + "mocha" "--timeout" "$TIMEOUT" "--recursive" "--full-trace" + ) +fi if [[ -z "$GITHUB_ACTIONS" ]]; then MOCHA_CMD+=( diff --git a/ci/test_mac.sh b/ci/test_mac.sh index c846a1273..b20bd03d5 100755 --- a/ci/test_mac.sh +++ b/ci/test_mac.sh @@ -9,9 +9,11 @@ source $THIS_DIR/scripts/set_git_info.sh export WORKSPACE=$GITHUB_WORKSPACE export SOURCE_ROOT=$GITHUB_WORKSPACE +export SHOULD_GENERATE_COVERAGE_REPORT=1 + python3 --version python3 -m venv venv source venv/bin/activate pip3 install -U pip pip3 install -U snowflake-connector-python -$THIS_DIR/container/test_component.sh +$THIS_DIR/container/test_component.sh $SHOULD_GENERATE_COVERAGE_REPORT diff --git a/package.json b/package.json index 7c53a49c7..85907a602 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "eslint": "^8.41.0", "mocha": "^10.1.0", "mock-require": "^3.0.3", + "nyc": "^15.1.0", "test-console": "^2.0.0" }, "overrides": { @@ -63,7 +64,11 @@ "test:single": "mocha -timeout 180000 --full-trace", "test:system": "mocha -timeout 180000 --recursive --full-trace system_test/*.js", "test:unit": "mocha -timeout 180000 --recursive --full-trace test/unit/**/*.js test/unit/*.js", - "test:ci": "mocha -timeout 180000 --recursive --full-trace test/**/*.js system_test/*.js" + "test:unit:coverage": "nyc npm run test:unit", + "test:ci": "mocha -timeout 180000 --recursive --full-trace test/**/*.js", + "test:ci:coverage": "nyc npm run test:ci", + "test:ci:withSystemTests": "mocha -timeout 180000 --recursive --full-trace test/**/*.js system_test/*.js", + "test:ci:withSystemTests:coverage": "nyc npm run test:ci:withSystemTests" }, "author": { "name": "Snowflake Computing, Inc.",