From aaa304c256e6699cf02f05800625e2a7f9e3d93e Mon Sep 17 00:00:00 2001 From: Tiago Yamamoto Date: Fri, 26 Dec 2025 22:39:53 -0300 Subject: [PATCH] feat: add test/coverage and build verification options to start.sh - Option 7: Run tests with coverage (go test + vitest) - Option 8: Verify build for backend, marketplace, and backoffice - Also accessible via --test/-t and --build/-B CLI flags --- start.sh | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index bf1326b..bbf00cf 100755 --- a/start.sh +++ b/start.sh @@ -303,6 +303,121 @@ reset_db() { echo -e "${GREEN}✨ Concluído!${NC}\n" } +# Função para rodar testes e exibir cobertura +run_tests() { + echo -e "\n${BLUE}🧪 Executando Testes...${NC}\n" + + # Backend Go Tests + echo -e "${CYAN}━━━ Backend Go ━━━${NC}" + cd "$PROJECT_ROOT/backend" + + if [ -f ".env" ]; then + set -a + source .env + set +a + fi + + echo -e "${YELLOW} ⏳ Executando go test com cobertura...${NC}" + go test -coverprofile=coverage.out ./... 2>&1 + BACKEND_EXIT=$? + + if [ $BACKEND_EXIT -eq 0 ]; then + echo -e "${GREEN} ✓ Testes do backend passaram!${NC}" + echo -e "${CYAN} 📊 Cobertura:${NC}" + go tool cover -func=coverage.out | tail -1 + echo -e "\n${YELLOW} 💡 Para ver cobertura detalhada: cd backend && go tool cover -html=coverage.out${NC}" + else + echo -e "${RED} ✗ Alguns testes falharam${NC}" + fi + + echo "" + + # Marketplace Tests + echo -e "${CYAN}━━━ Marketplace React ━━━${NC}" + cd "$PROJECT_ROOT/marketplace" + + if [ -d "node_modules" ]; then + echo -e "${YELLOW} ⏳ Executando vitest...${NC}" + npm run test -- --coverage --run 2>&1 + MARKET_EXIT=$? + + if [ $MARKET_EXIT -eq 0 ]; then + echo -e "${GREEN} ✓ Testes do marketplace passaram!${NC}" + else + echo -e "${RED} ✗ Alguns testes falharam${NC}" + fi + else + echo -e "${YELLOW} ⚠ node_modules não encontrado. Execute: npm install${NC}" + fi + + echo -e "\n${GREEN}✨ Testes concluídos!${NC}\n" +} + +# Função para verificar build de todos os projetos +run_build_check() { + echo -e "\n${BLUE}🔨 Verificando Build...${NC}\n" + + ALL_OK=true + + # Backend Go Build + echo -e "${CYAN}━━━ Backend Go ━━━${NC}" + cd "$PROJECT_ROOT/backend" + echo -e "${YELLOW} ⏳ go build ./...${NC}" + + if go build ./... 2>&1; then + echo -e "${GREEN} ✓ Build OK${NC}" + else + echo -e "${RED} ✗ Build falhou${NC}" + ALL_OK=false + fi + echo "" + + # Marketplace Build + echo -e "${CYAN}━━━ Marketplace React ━━━${NC}" + cd "$PROJECT_ROOT/marketplace" + + if [ -d "node_modules" ]; then + echo -e "${YELLOW} ⏳ npm run build${NC}" + if npm run build 2>&1; then + echo -e "${GREEN} ✓ Build OK${NC}" + else + echo -e "${RED} ✗ Build falhou${NC}" + ALL_OK=false + fi + else + echo -e "${YELLOW} ⚠ node_modules não encontrado. Execute: npm install${NC}" + fi + echo "" + + # Backoffice Build (if exists) + if [ -d "$PROJECT_ROOT/backoffice" ]; then + echo -e "${CYAN}━━━ Backoffice NestJS ━━━${NC}" + cd "$PROJECT_ROOT/backoffice" + + if [ -d "node_modules" ]; then + PKG_MANAGER="npm" + command -v pnpm &>/dev/null && PKG_MANAGER="pnpm" + + echo -e "${YELLOW} ⏳ $PKG_MANAGER run build${NC}" + if $PKG_MANAGER run build 2>&1; then + echo -e "${GREEN} ✓ Build OK${NC}" + else + echo -e "${RED} ✗ Build falhou${NC}" + ALL_OK=false + fi + else + echo -e "${YELLOW} ⚠ node_modules não encontrado${NC}" + fi + echo "" + fi + + if [ "$ALL_OK" = true ]; then + echo -e "${GREEN}✨ Todos os builds passaram!${NC}\n" + else + echo -e "${RED}❌ Alguns builds falharam. Verifique os erros acima.${NC}\n" + fi +} + # Função para exibir o menu show_menu() { echo -e "\n${YELLOW}Selecione o serviço para iniciar:${NC}\n" @@ -311,10 +426,12 @@ show_menu() { echo -e " ${BLUE}3)${NC} Marketplace React ${CYAN}(porta 5173)${NC}" echo -e " ${BLUE}4)${NC} Website Fresh/Deno ${CYAN}(porta 8000)${NC}" echo -e "" - echo -e " ${PURPLE}6)${NC} Resetar DB (Seed) ${RED}(Destrutivo)${NC}" - echo -e "" echo -e " ${GREEN}5)${NC} Iniciar Todos os Serviços" echo -e "" + echo -e " ${PURPLE}6)${NC} Resetar DB (Seed) ${RED}(Destrutivo)${NC}" + echo -e " ${YELLOW}7)${NC} Rodar Testes ${CYAN}(com cobertura)${NC}" + echo -e " ${YELLOW}8)${NC} Verificar Build ${CYAN}(frontend + backend)${NC}" + echo -e "" echo -e " ${RED}0)${NC} Sair" echo -e "" } @@ -369,6 +486,16 @@ if [ $# -gt 0 ]; then start_all_services exit 0 ;; + --test|-t|7) + show_banner + run_tests + exit 0 + ;; + --build|-B|8) + show_banner + run_build_check + exit 0 + ;; --help|-h) show_banner echo "Uso: $0 [OPÇÃO]" @@ -380,6 +507,8 @@ if [ $# -gt 0 ]; then echo " --website, -w, 4 Iniciar Website Deno (porta 8000)" echo " --seed, -s, 6 Resetar DB e rodar Seed (com --force)" echo " --all, -a, 5 Iniciar todos os serviços" + echo " --test, -t, 7 Rodar testes com cobertura" + echo " --build, -B, 8 Verificar build de todos os projetos" echo " --help, -h Mostrar esta ajuda" echo "" exit 0 @@ -430,6 +559,14 @@ while true; do reset_db break ;; + 7) + run_tests + break + ;; + 8) + run_build_check + break + ;; 5) start_all_services break