Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable e2e in GH workflows #1497

Merged
merged 9 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
NODE_ENV=production

DATABASE_URL=postgresql://prisma:hilly-sand-pit@db:5432/prisma?schema=prisma-pg-test
NEXTAUTH_URL=http://localhost:3000
NEXT_PUBLIC_NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=ololo
ADMIN_EMAIL=test@taskany.org
ADMIN_PASSWORD=test
MAIL_USER=notify@taskany.org
SENTRY_DISABLED=1
SENTRY_IGNORE_API_RESOLUTION_ERROR=1
25 changes: 25 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Cypress testing

on:
pull_request:
branches:
- main
paths:
- '**/**.json'
- '**/**.js'
- '**/**.jsx'
- '**/**.ts'
- '**/**.tsx'

jobs:
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Docker
run: docker-compose -f docker-compose.ci.yml up -d
- name: Run specs
uses: cypress-io/github-action@v5
env:
CYPRESS_ADMIN_EMAIL: test@taskany.org
CYPRESS_ADMIN_PASSWORD: test
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
run: npm run lint
- name: Unit
run: npm run test
- name: Build
run: npm run build
- name: type-check
run: npm run type-check
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM node:18.12.0-alpine as build

WORKDIR /app
COPY . .
RUN npm ci
RUN npm ci --no-audit --progress=false
RUN npm run build

FROM node:18.12.0-alpine AS runner
Expand Down
30 changes: 30 additions & 0 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM node:18.12.0-alpine as build

WORKDIR /app
COPY . .
RUN mv .env.ci .env
RUN npm ci --no-audit --progress=false
RUN npx next telemetry disable
RUN npm run build

FROM node:18.12.0-alpine AS runner

WORKDIR /app
COPY --from=build /app/.env ./
COPY --from=build /app/app_run.ci.sh ./
COPY --from=build /app/src ./src
COPY --from=build /app/package*.json ./
COPY --from=build /app/prisma ./prisma
COPY --from=build /app/public ./public
COPY --from=build /app/version ./public/version.txt
COPY --from=build /app/.next ./.next
COPY --from=build /app/next.config.js ./
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/background ./background
COPY --from=build /app/node_modules ./node_modules

RUN npx prisma generate

EXPOSE 3000

CMD sh ./app_run.ci.sh
4 changes: 4 additions & 0 deletions app_run.ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
npx prisma migrate deploy
npx prisma db seed
node_modules/.bin/concurrently 'node background/worker/index.js' 'node server.js'
16 changes: 13 additions & 3 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
export default {
import { defineConfig } from 'cypress';
import * as dotenv from 'dotenv';

dotenv.config();

export default defineConfig({
env: {
ADMIN_EMAIL: process.env.ADMIN_EMAIL,
ADMIN_PASSWORD: process.env.ADMIN_PASSWORD,
},
e2e: {
baseUrl: `http://${process.env.CYPRESS_baseUrl || 'localhost'}:3000`,
baseUrl: 'http://localhost:3000',
supportFile: false,
},
};
video: false,
});
16 changes: 16 additions & 0 deletions cypress/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const exactUrl = (route: string) => `${Cypress.config('baseUrl')}${route}`;

describe('Dashboard', () => {
it('asks to sign in on fist visit', () => {
cy.visit('/');

cy.url().should('equal', exactUrl('/api/auth/signin'));

cy.get('input[name=email]').type(Cypress.env('ADMIN_EMAIL'));

// {enter} causes the form to submit
cy.get('input[name=password]').type(`${Cypress.env('ADMIN_PASSWORD')}{enter}`);

cy.url().should('equal', exactUrl('/'));
});
});
5 changes: 0 additions & 5 deletions cypress/e2e/home_page.cy.ts

This file was deleted.

13 changes: 1 addition & 12 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ services:
- 3000:3000
build:
context: .
dockerfile: Dockerfile.dev
dockerfile: Dockerfile.ci
depends_on:
- db
environment:
- DATABASE_URL=postgresql://prisma:hilly-sand-pit@db:5432/prisma?schema=prisma-pg-test
- NEXTAUTH_URL=http://localhost:3000
- NEXT_PUBLIC_NEXTAUTH_URL=http://localhost:3000
- NEXTAUTH_SECRET=ololo
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/api/auth/signin"]
interval: 1s
timeout: 10s
retries: 10
start_period: 3s
Loading
Loading