From 8112c736bad9e95980abe42b2960b61feccd81f3 Mon Sep 17 00:00:00 2001 From: Nigro Simone Date: Sun, 13 Sep 2026 09:53:03 +0200 Subject: [PATCH] ci: measure test coverage with nyc and publish it to Coveralls --- .github/workflows/ci.yml | 8 ++++++-- .gitignore | 3 +++ .nycrc | 14 ++++++++++++++ README.md | 1 + package.json | 3 +++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .nycrc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 551388fcc..665061af5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,7 +48,7 @@ jobs: - { node: '16', postgres: &stable_postgres '18' } - { node: '18', postgres: *stable_postgres } - { node: '20', postgres: *stable_postgres } - - { node: '22', postgres: *stable_postgres } + - { node: '22', postgres: *stable_postgres, coverage: true } - { node: '24', postgres: *stable_postgres } # Latest Node.js version tested against multiple PostgreSQL versions - { node: &latest_node '26', postgres: '13' } @@ -92,4 +92,8 @@ jobs: node-version: ${{ matrix.node }} cache: yarn - run: yarn install --frozen-lockfile - - run: yarn test + - run: yarn ${{ matrix.coverage && 'coverage' || 'test' }} + - uses: coverallsapp/github-action@v2 + if: ${{ matrix.coverage }} + with: + file: coverage/lcov.info diff --git a/.gitignore b/.gitignore index c6d5700ae..aecc1454f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ dist .vscode/ manually-test-on-heroku.js tsconfig.tsbuildinfo + +coverage/ +.nyc_output/ diff --git a/.nycrc b/.nycrc new file mode 100644 index 000000000..6e1d2f67e --- /dev/null +++ b/.nycrc @@ -0,0 +1,14 @@ +{ + "all": true, + "include": ["packages/*/index.js", "packages/*/lib/**", "packages/*/src/**", "packages/*/dist/**"], + "exclude": [ + "**/*.test.*", + "**/*.d.ts", + "**/test/**", + "**/testing/**", + "packages/pg-protocol/src/b.ts", + "packages/pg-esm-test/**", + "packages/pg-bundler-test/**" + ], + "reporter": ["text", "lcov"] +} diff --git a/README.md b/README.md index ecd94e792..2d7b3b5a1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # node-postgres ![Build Status](https://github.com/brianc/node-postgres/actions/workflows/ci.yml/badge.svg) +[![Coverage Status](https://coveralls.io/repos/github/brianc/node-postgres/badge.svg?branch=master)](https://coveralls.io/github/brianc/node-postgres?branch=master) NPM version NPM downloads diff --git a/package.json b/package.json index e30454007..59489327b 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,8 @@ "docs:build": "cd docs && yarn build", "docs:start": "cd docs && yarn dev", "pretest": "yarn build", + "precoverage": "yarn build", + "coverage": "nyc --silent lerna exec --concurrency 1 --ignore pg-connection-string -- yarn test && nyc --no-clean yarn workspace pg-connection-string mocha", "prepublish": "yarn build", "lint": "eslint --cache 'packages/**/*.{js,ts,tsx}'" }, @@ -29,6 +31,7 @@ "eslint-config-prettier": "^10.1.2", "eslint-plugin-prettier": "^5.1.2", "lerna": "^3.19.0", + "nyc": "^15", "prettier": "3.0.3", "typescript": "^6.0.3" },