Skip to content

Commit

Permalink
Merge pull request #1039 from MTES-MCT/chore-add-coverage
Browse files Browse the repository at this point in the history
Add code coverage
  • Loading branch information
Falinor authored Dec 11, 2024
2 parents 64a103d + d7524ee commit 2c2d8ca
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 6 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,34 @@ 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 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

Expand Down
6 changes: 6 additions & 0 deletions frontend/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ module.exports = {
'jest-extended/all',
'<rootDir>/src/setupTests.ts'
];
config.collectCoverageFrom = [
'src/**/*.{ts,tsx}',
'!src/**/test/*',
'!src/components/_dsfr/*',
'!src/*'
];
config.testTimeout = 30_000;
config.transformIgnorePatterns = [
'<rootDir>/node_modules/(?!@codegouvfr)/.+\\.js$',
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
1 change: 1 addition & 0 deletions packages/draft/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"preset": "ts-jest",
"testEnvironment": "jsdom",
"rootDir": "src",
"collectCoverageFrom": ["<rootDir>/pdf.ts"],
"setupFilesAfterEnv": ["jest-extended/all", "<rootDir>/test/setup-tests.ts"]
}
3 changes: 2 additions & 1 deletion packages/draft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions packages/healthcheck/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"preset": "ts-jest",
"testEnvironment": "node",
"rootDir": "src",
"collectCoverageFrom": [
"<rootDir>/**/*.ts",
"!<rootDir>/**/test/*",
"!<rootDir>/**/index.ts"
],
"setupFilesAfterEnv": ["jest-extended/all", "<rootDir>/test/setup-tests.ts"]
}
3 changes: 2 additions & 1 deletion packages/healthcheck/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions packages/models/jest.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"collectCoverageFrom": [
"<rootDir>/**/*.ts",
"!<rootDir>/**/*.test.ts",
"!<rootDir>/index.ts",
"!<rootDir>/**/test/**"
],
"rootDir": "src",
"setupFilesAfterEnv": ["jest-extended/all", "<rootDir>/test/setup-tests.ts"]
}
1 change: 1 addition & 0 deletions packages/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions packages/schemas/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"preset": "ts-jest",
"testEnvironment": "node",
"rootDir": "src",
"collectCoverageFrom": ["<rootDir>/*.ts", "!<rootDir>/index.ts"],
"setupFilesAfterEnv": ["jest-extended/all", "<rootDir>/test/setup-tests.ts"]
}
4 changes: 3 additions & 1 deletion packages/schemas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
5 changes: 5 additions & 0 deletions packages/utils/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"preset": "ts-jest",
"testEnvironment": "node",
"rootDir": "src",
"collectCoverageFrom": [
"<rootDir>/**/*.ts",
"!<rootDir>/**/test/*",
"!<rootDir>/**/index.ts"
],
"setupFilesAfterEnv": ["jest-extended/all", "<rootDir>/test/setup-tests.ts"]
}
3 changes: 2 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions server/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
'<rootDir>/src/**/*.ts',
'!<rootDir>/src/**/*.test.ts',
'!<rootDir>/src/infra/database/**',
'<rootDir>/src/infra/database/test/*.test.ts',
'!<rootDir>/src/**/index.ts',
'!<rootDir>/src/types'
],
testEnvironment: 'node',
testTimeout: 30_000,
forceExit: true,
Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2c2d8ca

Please sign in to comment.