The Sawaka CI workflow (.github/workflows/ci.yml) runs Jest, Newman, and Playwright but was unstable or failing due to missing services, wrong assumptions about running servers, and absent steps (lint, docs, build).
- Issue:
products.test.jshitsGET /api/products, which usesProduct.find(). MongoDB is never connected in test/CI (index.jsskipsconnectMongowhenNODE_ENV=testorCI=true). Mongoose operations therefore fail or hang. - Evidence:
connectMongoreturns early in test/CI; no Jest setup connects Mongoose. - Fix: Use a MongoDB service container in GHA, add a Jest setup file that connects Mongoose to
MONGO_URIbefore tests, and run Jest with--runInBandso a single worker shares the connection.
- Issue: Newman runs against
{{base_url}}/api/productswithbase_url: http://localhost:5000. The API server is never started in CI, so Newman connects to nothing. - Evidence: Workflow has no “start API” step; Postman env points to localhost:5000.
- Fix: Start the backend API server in the background (with
MONGO_URIfrom the service container andJWT_SECRETset) before running Newman. Usewait-onor a simple poll to ensure the server is ready.
- Issue: Playwright uses
baseURL: http://localhost:3000and visits/. The Next.js dev server is never started, so Playwright hits nothing. - Evidence: No “start Next.js” step in the workflow;
homepage.spec.tsnavigates to/. - Fix: Start the Next.js dev server in the background before Playwright, then wait for
http://localhost:3000to be ready (e.g.wait-on) and run Playwright.
- Issue: Frontend has
npm run lint(Next.js lint), but the workflow does not run it. - Fix: Add a lint step (e.g.
npm run lintat repo root) and fix any lint failures.
- Issue: DoD requires “Application builds successfully”. The workflow does not run
npm run build. - Fix: Add a build step for the frontend (
npm run build) to ensure the app builds.
- Issue: “Docs generation” is in scope, but the workflow does not run it. Backend has no docs scripts in
package.json. - Fix: Add minimal docs generation (e.g. JSDoc or a no-op script) to the backend and a CI step that runs it, so “docs generation passes” without breaking CI.
- Issue:
MONGO_URIis taken fromsecrets.MONGO_URI_TEST. Using a service container makes CI self-contained and reproducible; we can use a fixedMONGO_URIfor the container instead of a secret. - Fix: Add a MongoDB service container, set
MONGO_URI(and optionallyJWT_SECRET) in the workflow env, and use these when running the API and Jest.
- Issue:
cache: 'npm'with a single lockfile path may not cache both root andbackend-apicorrectly. Workflow usesnpm install;npm ciis better for reproducible CI. - Fix: Use
npm ciwhere lockfiles exist, and align cache paths if we cache both root and backend.
- Current:
push/pull_requestonmainandqa. No issue. - No change needed to triggers.
| File | Change |
|---|---|
.github/workflows/ci.yml |
MongoDB service; env vars; install order (frontend first for wait-on/newman); combined API+Newman and Next+Playwright steps; lint; build; docs |
backend-api/jest.config.js |
setupFilesAfterEnv, testTimeout |
backend-api/jest.setup.js |
New. Connect Mongoose to MONGO_URI before tests, disconnect after |
backend-api/index.js |
Connect MongoDB when running as main module in CI (for Newman) if MONGO_URI set |
backend-api/package.json |
docs:generate script, jsdoc devDep, test script --runInBand |
backend-api/jsdoc.json |
New. Minimal JSDoc config for routes, models, middleware |
package.json |
wait-on, eslint-config-next devDeps |
.eslintrc.json |
New. extends: "next/core-web-vitals" for non-interactive lint |
app/acheteur/page.tsx |
Fix unescaped ' (lint) |
app/amelioration/page.tsx |
Fix unescaped ' (lint) |
app/components/home/HeroSection.tsx |
Fix unescaped ' (lint) |
.gitignore |
backend-api/docs |
- Jest passes (MongoDB service +
jest.setup.js+--runInBand) - Newman passes (API started with Mongo + env, then
wait-on+ Newman) - Playwright passes (Next.js
npm run start, thenwait-on+ Playwright) - Lint passes (
npm run lintwith.eslintrc.json+ fixes forreact/no-unescaped-entities) - Build passes (
npm run build) - Docs generation passes (
npm run docs:generatein backend-api)
- Use MongoDB service container (no external MongoDB secret required for CI).
- Use fixed
JWT_SECRETin CI. - Use
npm ciwhere lockfiles exist. - Run Jest with
--runInBandfor a single worker. - Start API and Next.js in CI, then run Newman and Playwright against them.