From 17895aa4829c416673e46ba4b2e9af64ca90f2da Mon Sep 17 00:00:00 2001 From: "Diego Ferreira L.G.Oliveira" Date: Thu, 4 Jun 2026 15:51:47 -0300 Subject: [PATCH] =?UTF-8?q?fix(ci):=20separar=20testes=20unit=C3=A1rios=20?= =?UTF-8?q?e=20E2E=20e=20corrigir=20commitlint=20ESM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 236 +++++++----------- .github/workflows/commitlint.yml | 2 +- commitlint.config.js => commitlint.config.cjs | 2 +- 3 files changed, 94 insertions(+), 146 deletions(-) rename commitlint.config.js => commitlint.config.cjs (94%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1b0094..e4880b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,17 +1,5 @@ name: CI -# FASE: Desenvolvimento local -# -# Etapas ativas agora: -# ✅ lint — ESLint 10 sobre src/ -# ✅ typecheck — TypeScript 6 strict sem emissão -# ✅ testes — Vitest (passará vazio até os primeiros testes serem criados) -# -# Etapas pendentes (comentadas abaixo): -# ⏳ testes-integracao — precisa de MongoDB + Redis via Docker services -# ⏳ testes-e2e — precisa do servidor Fastify em execução -# ⏳ cobertura — habilitar após cobertura mínima atingida (80%) - on: push: branches: [main] @@ -21,7 +9,7 @@ on: permissions: {} jobs: - # Lint e Typecheck + # ─── Qualidade estática ──────────────────────────────────────────────────── qualidade: name: Lint e Typecheck runs-on: ubuntu-latest @@ -47,8 +35,8 @@ jobs: - name: Typecheck run: pnpm typecheck - # Testes unitários - testes: + # ─── Testes unitários (sem serviços externos) ───────────────────────────── + testes-unitarios: name: Testes Unitários runs-on: ubuntu-latest needs: qualidade @@ -69,132 +57,92 @@ jobs: run: pnpm install --frozen-lockfile - name: Testes unitários - run: pnpm test - - # Testes de integração - # ⏳ PENDENTE — habilitar quando os primeiros repositórios MongoDB/Redis - # estiverem implementados em src/modulos/*/infra/repositorios/ - # - # testes-integracao: - # name: Testes de Integração - # runs-on: ubuntu-latest - # needs: testes - # - # services: - # mongodb: - # image: mongo:8.0 - # env: - # MONGO_INITDB_ROOT_USERNAME: usuario - # MONGO_INITDB_ROOT_PASSWORD: senha - # ports: - # - 27017:27017 - # options: >- - # --health-cmd "mongosh --eval 'db.runCommand({ ping: 1 })'" - # --health-interval 10s - # --health-timeout 5s - # --health-retries 5 - # - # redis: - # image: redis:8 - # options: >- - # --health-cmd "redis-cli ping" - # --health-interval 10s - # --health-timeout 5s - # --health-retries 5 - # ports: - # - 6379:6379 - # - # env: - # MONGO_URI: mongodb://usuario:senha@localhost:27017/bem-vindo-test - # REDIS_URL: redis://localhost:6379 - # NODE_ENV: test - # - # steps: - # - uses: actions/checkout@v4 - # - uses: pnpm/action-setup@v4 - # - uses: actions/setup-node@v4 - # with: - # node-version: 22 - # cache: pnpm - # - name: Instalar dependências - # run: pnpm install --frozen-lockfile - # - name: Testes de integração - # run: pnpm exec vitest run src/testes/integracao - - # Testes E2E - # ⏳ PENDENTE — habilitar quando as rotas Fastify estiverem implementadas - # e os testes em src/testes/e2e/ criados. - # Requer os mesmos services de MongoDB e Redis acima. - # - # testes-e2e: - # name: Testes E2E - # runs-on: ubuntu-latest - # needs: testes-integracao - # - # services: - # mongodb: - # image: mongo:8.0 - # env: - # MONGO_INITDB_ROOT_USERNAME: usuario - # MONGO_INITDB_ROOT_PASSWORD: senha - # ports: - # - 27017:27017 - # options: >- - # --health-cmd "mongosh --eval 'db.runCommand({ ping: 1 })'" - # --health-interval 10s - # --health-timeout 5s - # --health-retries 5 - # - # redis: - # image: redis:8 - # options: >- - # --health-cmd "redis-cli ping" - # --health-interval 10s - # --health-timeout 5s - # --health-retries 5 - # ports: - # - 6379:6379 - # - # env: - # MONGO_URI: mongodb://usuario:senha@localhost:27017/bem-vindo-test - # REDIS_URL: redis://localhost:6379 - # NODE_ENV: test - # JWT_SECRETO: secreto-de-teste-minimo-32-caracteres-aqui - # - # steps: - # - uses: actions/checkout@v4 - # - uses: pnpm/action-setup@v4 - # - uses: actions/setup-node@v4 - # with: - # node-version: 22 - # cache: pnpm - # - name: Instalar dependências - # run: pnpm install --frozen-lockfile - # - name: Testes E2E - # run: pnpm exec vitest run src/testes/e2e - - # Cobertura - # ⏳ PENDENTE — habilitar após os testes unitários atingirem cobertura - # mínima de 80% (configurado em vitest.config.ts). - # - # cobertura: - # name: Cobertura de Testes - # runs-on: ubuntu-latest - # needs: testes - # - # steps: - # - uses: actions/checkout@v4 - # - uses: pnpm/action-setup@v4 - # - uses: actions/setup-node@v4 - # with: - # node-version: 22 - # cache: pnpm - # - name: Instalar dependências - # run: pnpm install --frozen-lockfile - # - name: Gerar relatório de cobertura - # run: pnpm test:coverage - # - name: Publicar cobertura - # uses: codecov/codecov-action@v4 - # with: - # files: ./coverage/lcov.info - # fail_ci_if_error: true + run: pnpm exec vitest run src/testes/unitarios + + # ─── Cobertura (unit only) ───────────────────────────────────────────────── + cobertura: + name: Cobertura de Testes + runs-on: ubuntu-latest + needs: testes-unitarios + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + + - name: Instalar dependências + run: pnpm install --frozen-lockfile + + - name: Gerar relatório de cobertura + run: pnpm exec vitest run --coverage src/testes/unitarios + + - name: Publicar cobertura + uses: codecov/codecov-action@v4 + with: + files: ./coverage/lcov.info + fail_ci_if_error: false + + # ─── Testes E2E (MongoDB + Redis) ───────────────────────────────────────── + testes-e2e: + name: Testes E2E + runs-on: ubuntu-latest + needs: testes-unitarios + permissions: + contents: read + + services: + mongodb: + image: mongo:8.0 + env: + MONGO_INITDB_ROOT_USERNAME: administrador + MONGO_INITDB_ROOT_PASSWORD: 1qaz2sx12 + ports: + - 27017:27017 + options: >- + --health-cmd "mongosh --eval 'db.runCommand({ ping: 1 })'" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + redis: + image: redis:8 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 6379:6379 + + env: + MONGO_URI: mongodb://administrador:1qaz2sx12@localhost:27017/bem-vindo-testes?authSource=admin + REDIS_URL: redis://localhost:6379 + NODE_ENV: test + JWT_SECRETO: jwt-secreto-de-teste-com-pelo-menos-32-chars + JWT_EXPIRACAO_ACCESS: 1h + JWT_EXPIRACAO_REFRESH: 7d + PORTA: 3000 + TZ: America/Sao_Paulo + + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + + - name: Instalar dependências + run: pnpm install --frozen-lockfile + + - name: Testes E2E + run: pnpm exec vitest run src/testes/e2e diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index 116a48c..4297aea 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -31,6 +31,6 @@ jobs: - name: Validar commits do PR uses: wagoid/commitlint-github-action@v6 with: - configFile: commitlint.config.js + configFile: commitlint.config.cjs failOnWarnings: false helpURL: https://github.com/${{ github.repository }}/blob/main/.claude/rules/core/03-convencoes-git.md diff --git a/commitlint.config.js b/commitlint.config.cjs similarity index 94% rename from commitlint.config.js rename to commitlint.config.cjs index 1892cee..c3c4301 100644 --- a/commitlint.config.js +++ b/commitlint.config.cjs @@ -1,5 +1,5 @@ /** @type {import('@commitlint/types').UserConfig} */ -export default { +module.exports = { extends: ['@commitlint/config-conventional'], rules: { 'type-enum': [