Skip to content

Commit

Permalink
SNOW-830950: Configuration of nyc - code coverage library (#519)
Browse files Browse the repository at this point in the history
SNOW-830950: Configure nyc - code coverage library and corresponding steps in jenkins steps #430
  • Loading branch information
sfc-gh-pmotacki authored Jul 10, 2023
1 parent 6762efd commit 17a9ec7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 33 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ __pycache__/
wss-*-agent.config
wss-unified-agent.jar
whitesource/

.nyc_output
29 changes: 2 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<br>
Note: git bash is the console used for installing the node connector, the nyc module, and running "npm test"

Package
======================================================================

Expand Down
1 change: 1 addition & 0 deletions ci/container/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 11 additions & 3 deletions ci/container/test_component.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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+=(
Expand Down
4 changes: 3 additions & 1 deletion ci/test_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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.",
Expand Down

0 comments on commit 17a9ec7

Please sign in to comment.