From b841096368e4e7a54c1139c4ce4e85e15f5b1e1d Mon Sep 17 00:00:00 2001 From: Andrea Gueugnaut Date: Tue, 10 Dec 2024 10:33:34 +0100 Subject: [PATCH 1/4] chore: add coverage to all the packages --- package.json | 3 ++- packages/draft/jest.config.json | 1 + packages/draft/package.json | 3 ++- packages/healthcheck/jest.config.json | 5 +++++ packages/healthcheck/package.json | 3 ++- packages/models/jest.config.json | 6 ++++++ packages/models/package.json | 1 + packages/schemas/jest.config.json | 1 + packages/schemas/package.json | 4 +++- packages/utils/jest.config.json | 5 +++++ packages/utils/package.json | 3 ++- server/jest.config.ts | 9 +++++++++ server/package.json | 1 + 13 files changed, 40 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cb97896aa..437c2a524 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "clean": "lerna run clean", "build": "lerna run build", "lint": "eslint .", - "test": "lerna run test" + "test": "lerna run test", + "coverage": "lerna run coverage" }, "keywords": [], "author": "", diff --git a/packages/draft/jest.config.json b/packages/draft/jest.config.json index 754023311..110b388cc 100644 --- a/packages/draft/jest.config.json +++ b/packages/draft/jest.config.json @@ -2,5 +2,6 @@ "preset": "ts-jest", "testEnvironment": "jsdom", "rootDir": "src", + "collectCoverageFrom": ["/pdf.ts"], "setupFilesAfterEnv": ["jest-extended/all", "/test/setup-tests.ts"] } diff --git a/packages/draft/package.json b/packages/draft/package.json index 0c4f8f70e..27b5ecd1c 100644 --- a/packages/draft/package.json +++ b/packages/draft/package.json @@ -8,7 +8,8 @@ "copy": "copyfiles -V -u 1 'src/**/*.css' 'src/**/*.hbs' dist", "build": "tsc -b tsconfig.build.json && yarn copy", "dev": "nodemon --watch src -e ts --exec 'yarn build'", - "test": "jest" + "test": "jest", + "coverage": "jest --coverage" }, "devDependencies": { "@testing-library/dom": "^10.4.0", diff --git a/packages/healthcheck/jest.config.json b/packages/healthcheck/jest.config.json index dd1464c28..27d3a9755 100644 --- a/packages/healthcheck/jest.config.json +++ b/packages/healthcheck/jest.config.json @@ -2,5 +2,10 @@ "preset": "ts-jest", "testEnvironment": "node", "rootDir": "src", + "collectCoverageFrom": [ + "/**/*.ts", + "!/**/test/*", + "!/**/index.ts" + ], "setupFilesAfterEnv": ["jest-extended/all", "/test/setup-tests.ts"] } diff --git a/packages/healthcheck/package.json b/packages/healthcheck/package.json index f0d397d60..79f125611 100644 --- a/packages/healthcheck/package.json +++ b/packages/healthcheck/package.json @@ -6,7 +6,8 @@ "scripts": { "clean": "rimraf dist tsconfig.build.tsbuildinfo", "build": "tsc -b tsconfig.build.json", - "test": "jest" + "test": "jest", + "coverage": "jest --coverage" }, "peerDependencies": { "express": "^4.20.0" diff --git a/packages/models/jest.config.json b/packages/models/jest.config.json index dd1464c28..fa7f0e3b4 100644 --- a/packages/models/jest.config.json +++ b/packages/models/jest.config.json @@ -1,6 +1,12 @@ { "preset": "ts-jest", "testEnvironment": "node", + "collectCoverageFrom": [ + "/**/*.ts", + "!/**/*.test.ts", + "!/index.ts", + "!/**/test/**" + ], "rootDir": "src", "setupFilesAfterEnv": ["jest-extended/all", "/test/setup-tests.ts"] } diff --git a/packages/models/package.json b/packages/models/package.json index 959d4e1b5..968afc3a0 100644 --- a/packages/models/package.json +++ b/packages/models/package.json @@ -17,6 +17,7 @@ "clean": "rimraf dist tsconfig.build.tsbuildinfo", "build": "tsc -b tsconfig.build.json", "test": "jest", + "coverage": "jest --coverage", "dev": "nodemon --watch src -e ts --exec 'yarn build'" }, "dependencies": { diff --git a/packages/schemas/jest.config.json b/packages/schemas/jest.config.json index dd1464c28..d3e800547 100644 --- a/packages/schemas/jest.config.json +++ b/packages/schemas/jest.config.json @@ -2,5 +2,6 @@ "preset": "ts-jest", "testEnvironment": "node", "rootDir": "src", + "collectCoverageFrom": ["/*.ts", "!/index.ts"], "setupFilesAfterEnv": ["jest-extended/all", "/test/setup-tests.ts"] } diff --git a/packages/schemas/package.json b/packages/schemas/package.json index f749238af..471bd69bd 100644 --- a/packages/schemas/package.json +++ b/packages/schemas/package.json @@ -5,7 +5,9 @@ "types": "dist/index.d.ts", "scripts": { "clean": "rimraf dist tsconfig.build.tsbuildinfo", - "build": "tsc -b tsconfig.build.json" + "build": "tsc -b tsconfig.build.json", + "test": "jest", + "coverage": "jest --coverage" }, "dependencies": { "@zerologementvacant/models": "workspace:*", diff --git a/packages/utils/jest.config.json b/packages/utils/jest.config.json index dd1464c28..27d3a9755 100644 --- a/packages/utils/jest.config.json +++ b/packages/utils/jest.config.json @@ -2,5 +2,10 @@ "preset": "ts-jest", "testEnvironment": "node", "rootDir": "src", + "collectCoverageFrom": [ + "/**/*.ts", + "!/**/test/*", + "!/**/index.ts" + ], "setupFilesAfterEnv": ["jest-extended/all", "/test/setup-tests.ts"] } diff --git a/packages/utils/package.json b/packages/utils/package.json index 86d3b1ea2..46251d3b8 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -18,7 +18,8 @@ "scripts": { "clean": "rimraf dist tsconfig.build.tsbuildinfo", "build": "tsc -b tsconfig.build.json", - "test": "jest" + "test": "jest", + "coverage": "jest --coverage" }, "dependencies": { "@aws-sdk/client-s3": "^3.658.1", diff --git a/server/jest.config.ts b/server/jest.config.ts index cfdaee9cf..5a1859a60 100644 --- a/server/jest.config.ts +++ b/server/jest.config.ts @@ -5,6 +5,15 @@ const tsconfig = require('./tsconfig.json'); const config: JestConfigWithTsJest = { preset: 'ts-jest', + // These files are used if `jest --coverage` is run + collectCoverageFrom: [ + '/src/**/*.ts', + '!/src/**/*.test.ts', + '!/src/infra/database/**', + '/src/infra/database/test/*.test.ts', + '!/src/**/index.ts', + '!/src/types' + ], testEnvironment: 'node', testTimeout: 30_000, forceExit: true, diff --git a/server/package.json b/server/package.json index 0b64a9b8b..f97075871 100644 --- a/server/package.json +++ b/server/package.json @@ -10,6 +10,7 @@ "start": "node dist/index.js", "test": "jest", "test:migrations": "jest -c database.jest.config.ts -i", + "coverage": "jest --coverage", "db": "knex --knexfile=src/infra/database/knexfile.ts", "migrate": "yarn db migrate:latest", "seed": "yarn db seed:run" From ba9411855f8a85a9156eee2b4a8f27a0e3b5d1b7 Mon Sep 17 00:00:00 2001 From: Andrea Gueugnaut Date: Tue, 10 Dec 2024 10:52:52 +0100 Subject: [PATCH 2/4] ci: compute coverage on the main branch and upload to codecov --- .github/workflows/main.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ebca9e32c..59c02569f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -71,11 +71,16 @@ jobs: run: yarn lint - name: Test - run: yarn test --parallel + run: yarn coverage --parallel env: LOG_LEVEL: fatal REACT_APP_API_URL: http://localhost:3001 + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + - name: Test database migrations run: yarn workspace @zerologementvacant/server run test:migrations --run-in-band From 9e38d0531be181bdef09934f9723e6e9c913c921 Mon Sep 17 00:00:00 2001 From: Andrea Gueugnaut Date: Wed, 11 Dec 2024 10:53:19 +0100 Subject: [PATCH 3/4] chore(frontend): compute coverage --- frontend/craco.config.js | 6 ++++++ frontend/package.json | 1 + 2 files changed, 7 insertions(+) diff --git a/frontend/craco.config.js b/frontend/craco.config.js index 867ce41cc..0e8a41280 100644 --- a/frontend/craco.config.js +++ b/frontend/craco.config.js @@ -24,6 +24,12 @@ module.exports = { 'jest-extended/all', '/src/setupTests.ts' ]; + config.collectCoverageFrom = [ + 'src/**/*.{ts,tsx}', + '!src/**/test/*', + '!src/components/_dsfr/*', + '!src/*' + ]; config.testTimeout = 30_000; config.transformIgnorePatterns = [ '/node_modules/(?!@codegouvfr)/.+\\.js$', diff --git a/frontend/package.json b/frontend/package.json index 4fce27ac7..0352e1950 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -7,6 +7,7 @@ "build": "yarn clean && yarn icons && tsc -b tsconfig.build.json && DISABLE_ESLINT_PLUGIN=true craco build", "dev": "yarn icons && DISABLE_ESLINT_PLUGIN=true craco start", "test": "DISABLE_ESLINT_PLUGIN=true craco test", + "coverage": "DISABLE_ESLINT_PLUGIN=true craco test --coverage", "postinstall": "copy-dsfr-to-public" }, "browserslist": { From d7524ee503c2e0616d7772a2a9b38b3d83faf709 Mon Sep 17 00:00:00 2001 From: Andrea Gueugnaut Date: Wed, 11 Dec 2024 10:53:42 +0100 Subject: [PATCH 4/4] ci: compute coverage from packages and upload them to codecov --- .github/workflows/main.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 59c02569f..504186cd3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -76,10 +76,28 @@ jobs: LOG_LEVEL: fatal REACT_APP_API_URL: http://localhost:3001 - - name: Upload coverage reports to Codecov + - name: Upload frontend coverage reports to Codecov uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} + disable_search: true + files: ./frontend/coverage/coverage-final.json + flags: frontend + + - name: Upload packages coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + directory: packages + flags: packages + + - name: Upload packages coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + disable_search: true + files: ./server/coverage/coverage-final.json + flags: server - name: Test database migrations run: yarn workspace @zerologementvacant/server run test:migrations --run-in-band