diff --git a/.gitignore b/.gitignore index ef08eecc..d2d1af67 100644 --- a/.gitignore +++ b/.gitignore @@ -3,13 +3,18 @@ .venv .idea .vscode + data/* data/nginx/ssl/* data/postres* data/redis/* + backend/data/production/* +backend/staticfiles/* +frontend/cypress/screenshots/* +frontend/cypress/videos/* /node_modules -backend/staticfiles/* + !data/nginx/ssl/.gitkeep diff --git a/frontend/.gitignore b/frontend/.gitignore index b0c253f8..7b0cca13 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -24,3 +24,7 @@ dist-ssr *.njsproj *.sln *.sw? + +# cypress +cypress/screenshots/* +cypress/videos/* diff --git a/frontend/.gitkeep b/frontend/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/frontend/cypress.config.ts b/frontend/cypress.config.ts index 37e25a71..8bd806de 100644 --- a/frontend/cypress.config.ts +++ b/frontend/cypress.config.ts @@ -1,8 +1,8 @@ import { defineConfig } from "cypress"; export default defineConfig({ - e2e: { - baseUrl: "https://localhost/", - specPattern: "src/test/e2e/**/*.cy.{js,jsx,ts,tsx}", - }, + e2e: { + baseUrl: "https://nginx", + specPattern: "src/test/e2e/**/*.cy.{js,jsx,ts,tsx}", + }, }); diff --git a/frontend/cypress/screenshots/login.cy.ts/login page -- routes to dashboard when pressing dashboard button (failed).png b/frontend/cypress/screenshots/login.cy.ts/login page -- routes to dashboard when pressing dashboard button (failed).png deleted file mode 100644 index 1651f20f..00000000 Binary files a/frontend/cypress/screenshots/login.cy.ts/login page -- routes to dashboard when pressing dashboard button (failed).png and /dev/null differ diff --git a/frontend/package.json b/frontend/package.json index 12635ca3..db0a21db 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,39 +1,39 @@ { - "name": "vite-vue-typescript-starter", - "private": true, - "version": "0.0.0", - "type": "module", - "scripts": { - "dev": "vite", - "host": "vite --host", - "build": "vue-tsc && vite build", - "preview": "vite preview", - "test": "vitest", - "cypress:open": "cypress open", - "cypress:test": "cypress run" - }, - "dependencies": { - "@vueuse/core": "^10.9.0", - "axios": "^1.6.8", - "js-cookie": "^3.0.5", - "moment": "^2.30.1", - "pinia": "^2.1.7", - "primeflex": "^3.3.1", - "primeicons": "^6.0.1", - "primevue": "^3.50.0", - "vue": "^3.4.18", - "vue-i18n": "^9.10.2", - "vue-router": "^4.3.0" - }, - "devDependencies": { - "@types/js-cookie": "^3.0.6", - "@types/node": "^20.11.30", - "@vitejs/plugin-vue": "^5.0.4", - "cypress": "^13.7.1", - "sass": "^1.72.0", - "typescript": "^5.2.2", - "vite": "^5.1.1", - "vitest": "^1.4.0", - "vue-tsc": "^1.8.27" - } + "name": "vite-vue-typescript-starter", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "host": "vite --host", + "build": "vue-tsc && vite build", + "preview": "vite preview", + "test": "vitest run", + "cypress:open": "cypress open", + "cypress:test": "cypress run" + }, + "dependencies": { + "@vueuse/core": "^10.9.0", + "axios": "^1.6.8", + "js-cookie": "^3.0.5", + "moment": "^2.30.1", + "pinia": "^2.1.7", + "primeflex": "^3.3.1", + "primeicons": "^6.0.1", + "primevue": "^3.50.0", + "vue": "^3.4.18", + "vue-i18n": "^9.10.2", + "vue-router": "^4.3.0" + }, + "devDependencies": { + "@types/js-cookie": "^3.0.6", + "@types/node": "^20.11.30", + "@vitejs/plugin-vue": "^5.0.4", + "cypress": "^13.7.1", + "sass": "^1.72.0", + "typescript": "^5.2.2", + "vite": "^5.1.1", + "vitest": "^1.4.0", + "vue-tsc": "^1.8.27" + } } diff --git a/test.sh b/test.sh index a70f382a..0a42e1b6 100755 --- a/test.sh +++ b/test.sh @@ -24,6 +24,10 @@ done echo "Checking environment file..." +if [ "$build" = true ]; then + rm .env > /dev/null 2>&1 +fi + if ! [ -f .env ]; then cp .dev.env .env sed -i "s/^DJANGO_SECRET_KEY=.*/DJANGO_SECRET_KEY=totally_random_key_string/" .env @@ -46,26 +50,64 @@ fi if [ "$build" = true ]; then echo "Building Docker images..." echo "This can take a while..." - docker-compose -f testing.yml build --no-cache -else - echo "$build" + docker-compose -f test.yml build --no-cache fi echo "Starting services..." -docker-compose -f testing.yml up -d +docker-compose -f test.yml up -d --scale cypress=0 + +cypress_exit=0 +vitest_exit=0 +django_exit=0 if [ "$frontend" = true ]; then echo "Running frontend tests..." - echo "Not implemented yet" + echo "Running Cypress tests..." + docker-compose -f test.yml up --exit-code-from cypress --abort-on-container-exit cypress + cypress_exit=$? + echo "Running Vitest tests..." + docker exec frontend npm run test + vitest_exit=$? +elif [ "$backend" = true ]; then + echo "Running backend tests..." + docker exec backend python manage.py test + django_exit=$? +else + echo "Running backend tests..." + docker exec backend python manage.py test + django_exit=$? + echo "Running frontend tests..." + echo "Running Cypress tests..." + docker-compose -f test.yml up --exit-code-from cypress --abort-on-container-exit cypress + cypress_exit=$? + echo "Running Vitest tests..." + docker exec frontend npm run test + vitest_exit=$? fi -if [ "$backend" = true ]; then - echo "Running backend tests..." - docker-compose -f testing.yml exec backend python manage.py test +echo "-----------------" +if [ $cypress_exit -ne 0 ] || [ $vitest_exit -ne 0 ] || [ $django_exit -ne 0 ]; then + echo "Tests failed:" + if [ $cypress_exit -ne 0 ]; then + echo " - Cypress" + fi + if [ $vitest_exit -ne 0 ]; then + echo " - Vitest" + fi + if [ $django_exit -ne 0 ]; then + echo " - Django" + fi + echo "-----------------" + exit 1 +else + echo "All tests passed!" fi +echo "-----------------" echo "Cleaning up..." -docker-compose -f testing.yml down +docker-compose -f test.yml down echo "Done." + +exit 0 diff --git a/test.yml b/test.yml new file mode 100644 index 00000000..a8acdc42 --- /dev/null +++ b/test.yml @@ -0,0 +1,107 @@ +version: "3.9" + +############################# NETWORKS + +networks: + selab_network: + name: selab_network + driver: bridge + ipam: + config: + - subnet: 192.168.90.0/24 + +############################# EXTENSIONS + +x-common-keys-selab: &common-keys-selab + networks: + - selab_network + security_opt: + - no-new-privileges:true + restart: unless-stopped + environment: + TZ: $TZ + PUID: $PUID + PGID: $PGID + env_file: + - .env + +############################# SERVICES + +services: + nginx: + <<: *common-keys-selab + image: nginx:latest + container_name: nginx + expose: + - 80 + - 443 + - 8080 + volumes: + - ${DATA_DIR}/nginx/nginx.dev.conf:/etc/nginx/nginx.conf:ro + - ${SSL_DIR}:/etc/nginx/ssl:ro + depends_on: + - backend + - frontend + + backend: + <<: *common-keys-selab + container_name: backend + build: + context: $BACKEND_DIR + dockerfile: Dockerfile.dev + command: /bin/bash -c "./setup.sh && python manage.py runsslserver 192.168.90.2:8080" + expose: + - 8080 + volumes: + - $BACKEND_DIR:/code + + celery: + <<: *common-keys-selab + container_name: celery + build: + context: $BACKEND_DIR + dockerfile: Dockerfile.dev + command: celery -A ypovoli worker -l DEBUG + volumes: + - $BACKEND_DIR:/code + depends_on: + - backend + - redis + + frontend: + <<: *common-keys-selab + container_name: frontend + build: + context: $FRONTEND_DIR + dockerfile: Dockerfile.dev + command: bash -c "npm install && npm run host" + expose: + - 5173 + volumes: + - $FRONTEND_DIR:/app + depends_on: + - backend + + redis: + <<: *common-keys-selab + container_name: redis + image: redis:latest + networks: + selab_network: + ipv4_address: $REDIS_IP + expose: + - $REDIS_PORT + entrypoint: redis-server --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru + volumes: + - ${DATA_DIR}/redis:/data + + cypress: + <<: *common-keys-selab + container_name: cypress + image: cypress/included:cypress-12.17.3-node-18.16.0-chrome-114.0.5735.133-1-ff-114.0.2-edge-114.0.1823.51-1 + restart: "no" + working_dir: /e2e + volumes: + - ${FRONTEND_DIR}:/e2e + extra_hosts: + - "host.docker.internal:host-gateway" diff --git a/testing.yml b/testing.yml deleted file mode 100644 index 1c6dbf00..00000000 --- a/testing.yml +++ /dev/null @@ -1,98 +0,0 @@ -version: "3.9" - -############################# NETWORKS - -networks: - selab_network: - name: selab_network - driver: bridge - ipam: - config: - - subnet: 192.168.90.0/24 - -############################# EXTENSIONS - -x-common-keys-selab: &common-keys-selab - networks: - - selab_network - security_opt: - - no-new-privileges:true - restart: unless-stopped - environment: - TZ: $TZ - PUID: $PUID - PGID: $PGID - env_file: - - .env - -############################# SERVICES - -services: - - nginx: - <<: *common-keys-selab - image: nginx:latest - container_name: nginx - expose: - - 80 - - 443 - - 8080 - volumes: - - ${DATA_DIR}/nginx/nginx.dev.conf:/etc/nginx/nginx.conf:ro - - ${SSL_DIR}:/etc/nginx/ssl:ro - depends_on: - - backend - - frontend - - backend: - <<: *common-keys-selab - container_name: backend - build: - context: $BACKEND_DIR - dockerfile: Dockerfile.dev - command: /bin/bash -c "./setup.sh && python manage.py runsslserver 192.168.90.2:8080" - expose: - - 8080 - volumes: - - $BACKEND_DIR:/code - - celery: - <<: *common-keys-selab - container_name: celery - build: - context: $BACKEND_DIR - dockerfile: Dockerfile.dev - command: celery -A ypovoli worker -l DEBUG - volumes: - - $BACKEND_DIR:/code - depends_on: - - backend - - redis - - frontend: - <<: *common-keys-selab - container_name: frontend - build: - context: $FRONTEND_DIR - dockerfile: Dockerfile.dev - command: bash -c "npm install && npm run host" - expose: - - 5173 - volumes: - - $FRONTEND_DIR:/app - depends_on: - - backend - - redis: - <<: *common-keys-selab - container_name: redis - image: redis:latest - networks: - selab_network: - ipv4_address: $REDIS_IP - expose: - - $REDIS_PORT - entrypoint: redis-server --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru - volumes: - - ${DATA_DIR}/redis:/data - \ No newline at end of file