feat: test-coverage (#4701)

This commit is contained in:
Piyush Gupta
2025-02-04 13:29:16 +05:30
committed by GitHub
parent b35cf14d32
commit 92ae4786f0
5 changed files with 1793 additions and 1773 deletions

View File

@@ -1,11 +1,11 @@
name: SonarQube
on:
workflow_dispatch:
# push:
# branches:
# - main
# pull_request:
# types: [opened, synchronize, reopened]
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
jobs:
@@ -16,6 +16,35 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup Node.js 20.x
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af
with:
node-version: 20.x
- name: Install pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2
- name: Install dependencies
run: pnpm install --config.platform=linux --config.architecture=x64
- name: create .env
run: cp .env.example .env
- name: Generate Random ENCRYPTION_KEY, CRON_SECRET & NEXTAUTH_SECRET and fill in .env
run: |
RANDOM_KEY=$(openssl rand -hex 32)
sed -i "s/ENCRYPTION_KEY=.*/ENCRYPTION_KEY=${RANDOM_KEY}/" .env
sed -i "s/CRON_SECRET=.*/CRON_SECRET=${RANDOM_KEY}/" .env
sed -i "s/NEXTAUTH_SECRET=.*/NEXTAUTH_SECRET=${RANDOM_KEY}/" .env
- name: Run tests with coverage
run: |
cd apps/web
pnpm test:coverage
cd ../../
# The Vitest coverage config is in your vite.config.mts
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@bfd4e558cda28cda6b5defafb9232d191be8c203
env:

View File

@@ -10,7 +10,8 @@
"build:dev": "next build",
"start": "next start",
"lint": "next lint",
"test": "dotenv -e ../../.env -- vitest run"
"test": "dotenv -e ../../.env -- vitest run",
"test:coverage": "dotenv -e ../../.env -- vitest run --coverage"
},
"dependencies": {
"@ai-sdk/azure": "1.0.10",
@@ -130,6 +131,7 @@
"@types/nodemailer": "6.4.17",
"@types/papaparse": "5.3.15",
"@types/qrcode": "1.5.5",
"@vitest/coverage-v8": "2.1.8",
"vite": "6.0.9",
"vitest": "2.1.8",
"vitest-mock-extended": "2.0.2"

View File

@@ -1,10 +1,18 @@
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vitest/config";
// vitest.config.ts
import tsconfigPaths from 'vite-tsconfig-paths';
import { loadEnv } from 'vite'
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
exclude: ["playwright/**", "node_modules/**"],
setupFiles: ["../../packages/lib/vitestSetup.ts"],
exclude: ['playwright/**', 'node_modules/**'],
setupFiles: ['../../packages/lib/vitestSetup.ts'],
env: loadEnv('', process.cwd(), ''),
coverage: {
provider: 'v8', // Use V8 as the coverage provider
reporter: ['text', 'html', 'lcov'], // Generate text summary and HTML reports
reportsDirectory: './coverage', // Output coverage reports to the coverage/ directory
},
},
plugins: [tsconfigPaths()],
});
});

3504
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
sonar.projectKey=formbricks_formbricks
sonar.organization=formbricks
sonar.javascript.lcov.reportPaths=./apps/web/coverage/lcov.info
# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=formbricks