From 00767a0148456f57f8fa21e0cb0149cf849f3574 Mon Sep 17 00:00:00 2001 From: Joe Baker Date: Tue, 3 Dec 2024 12:36:05 +0000 Subject: [PATCH] feat: test coverage (#406) --- .github/workflows/test.yml | 13 ++++++++++++- apps/nextjs/jest.config.js | 2 ++ packages/aila/jest.config.js | 2 ++ packages/ingest/jest.config.js | 2 ++ sonar-project.properties | 3 ++- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cad1aa60e..149fec4e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,4 +43,15 @@ jobs: inject-env-vars: true - name: Run tests - run: pnpm turbo test --cache-dir=".turbo" -- --maxWorkers=33% + run: pnpm turbo test --cache-dir=".turbo" -- --maxWorkers=33% --coverage + + # Run only on production branch + - name: Report coverage to SonarCloud + if: ${{ github.event.pull_request.merged == true && github.base_ref == 'production' }} + uses: sonarsource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.javascript.lcov.reportPaths=packages/**/coverage/lcov.info,apps/nextjs/coverage/lcov.info diff --git a/apps/nextjs/jest.config.js b/apps/nextjs/jest.config.js index d35dc0cb3..cd0dc24f9 100644 --- a/apps/nextjs/jest.config.js +++ b/apps/nextjs/jest.config.js @@ -9,6 +9,7 @@ const config = { { tsconfig: "tsconfig.test.json", useESM: true, + isolatedModules: true, }, ], "^.+\\.svg$": "/jest.svgTransform.js", @@ -30,6 +31,7 @@ const config = { rootDir: ".", resetMocks: true, setupFilesAfterEnv: ["/jest.setup.js"], + collectCoverageFrom: ["src/**/*.{ts,tsx,js,jsx}"], collectCoverage: process.env.CI === "true" || process.env.COLLECT_TEST_COVERAGE === "true", coverageReporters: ["lcov", "text"], diff --git a/packages/aila/jest.config.js b/packages/aila/jest.config.js index 9d23cf9d6..e56bfce0b 100644 --- a/packages/aila/jest.config.js +++ b/packages/aila/jest.config.js @@ -9,6 +9,7 @@ const config = { { tsconfig: "tsconfig.test.json", useESM: true, + isolatedModules: true, }, ], }, @@ -26,6 +27,7 @@ const config = { collectCoverage: process.env.CI === "true" || process.env.COLLECT_TEST_COVERAGE === "true", coverageReporters: ["lcov", "text"], + collectCoverageFrom: ["src/**/*.{ts,tsx,js,jsx}"], coverageDirectory: "coverage", }; diff --git a/packages/ingest/jest.config.js b/packages/ingest/jest.config.js index 9d23cf9d6..e56bfce0b 100644 --- a/packages/ingest/jest.config.js +++ b/packages/ingest/jest.config.js @@ -9,6 +9,7 @@ const config = { { tsconfig: "tsconfig.test.json", useESM: true, + isolatedModules: true, }, ], }, @@ -26,6 +27,7 @@ const config = { collectCoverage: process.env.CI === "true" || process.env.COLLECT_TEST_COVERAGE === "true", coverageReporters: ["lcov", "text"], + collectCoverageFrom: ["src/**/*.{ts,tsx,js,jsx}"], coverageDirectory: "coverage", }; diff --git a/sonar-project.properties b/sonar-project.properties index 46fe3ecbf..2f5d65e8b 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -23,4 +23,5 @@ sonar.cpd.exclusions=\ sonar.tests=. sonar.test.inclusions=**/*.test.ts sonar.javascript.lcov.reportPaths=packages/**/coverage/lcov.info,apps/nextjs/coverage/lcov.info -sonar.language=ts,tsx,js,jsx,html,css \ No newline at end of file + +sonar.language=ts,tsx,js,jsx,html,css