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

Fix e2e tests #451

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ stories
.prettier*
LICENSE
README.md
__mocks__
test-results
.env.local.sample
dev
13 changes: 13 additions & 0 deletions .env.local.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
BASE_CANONICAL_URL=
API_HOST_CLIENT=
API_HOST_SERVER=
NEXT_PUBLIC_API_HOST_CLIENT=
COOKIE_SECRET=
ADS_SESSION_COOKIE_NAME=
SCIX_SESSION_COOKIE_NAME=
NEXT_PUBLIC_ORCID_CLIENT_ID=
NEXT_PUBLIC_ORCID_API_URL=
NEXT_PUBLIC_ORCID_REDIRECT_URI=
REDIS_HOST=
REDIS_PORT=
REDIS_PASSWORD=
VERIFIED_BOTS_ACCESS_TOKEN=
UNVERIFIABLE_BOTS_ACCESS_TOKEN=
MALICIOUS_BOTS_ACCESS_TOKEN=
NEXT_PUBLIC_GTM_ID=
NEXT_PUBLIC_RECAPTCHA_SITE_KEY=
MAILSLURP_API_TOKEN=
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: CI
on: [push, pull_request]

jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and Run Unit Tests
run: ./nectar.sh --unit

102 changes: 51 additions & 51 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,55 +69,55 @@ jobs:
name: codecov-nectar
path_to_write_report: ./coverage/codecov_report.txt
verbose: true

e2e-tests:
timeout-minutes: 60
runs-on: ubuntu-latest
env:
CI: true
BASE_CANONICAL_URL: ${{ vars.BASE_CANONICAL_URL }}
API_HOST_CLIENT: ${{ vars.API_HOST_CLIENT }}
API_HOST_SERVER: ${{ vars.API_HOST_SERVER }}
COOKIE_SECRET: ${{ vars.COOKIE_SECRET }}
strategy:
matrix:
node-version: [ 18 ]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
- uses: actions/cache@v3
name: restore/setup pnpm cache
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Install dependencies
if: steps.pnpm-cache.outputs.cache-hit != 'true'
run: pnpm install

- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps

- name: setup environment variables
run: |
touch .env.local
echo "CI=${{ env.CI }}" >> .env.local
echo "BASE_CANONICAL_URL=${{ env.BASE_CANONICAL_URL }}" >> .env.local
echo "API_HOST_CLIENT=${{ env.API_HOST_CLIENT }}" >> .env.local
echo "API_HOST_SERVER=${{ env.API_HOST_SERVER }}" >> .env.local
echo "COOKIE_SECRET=${{ env.COOKIE_SECRET }}" >> .env.local
- name: Run integration tests
run: pnpm integration

- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
# e2e-tests:
# timeout-minutes: 60
# runs-on: ubuntu-latest
# env:
# CI: true
# BASE_CANONICAL_URL: ${{ vars.BASE_CANONICAL_URL }}
# API_HOST_CLIENT: ${{ vars.API_HOST_CLIENT }}
# API_HOST_SERVER: ${{ vars.API_HOST_SERVER }}
# COOKIE_SECRET: ${{ vars.COOKIE_SECRET }}
# strategy:
# matrix:
# node-version: [ 18 ]
# steps:
# - uses: actions/checkout@v3
# - uses: pnpm/action-setup@v2
# name: Install pnpm
# id: pnpm-install
# with:
# version: 8
# run_install: false
# - uses: actions/cache@v3
# name: restore/setup pnpm cache
# with:
# path: ~/.pnpm-store
# key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
#
# - name: Install dependencies
# if: steps.pnpm-cache.outputs.cache-hit != 'true'
# run: pnpm install
#
# - name: Install Playwright Browsers
# run: pnpm exec playwright install --with-deps
#
# - name: setup environment variables
# run: |
# touch .env.local
# echo "CI=${{ env.CI }}" >> .env.local
# echo "BASE_CANONICAL_URL=${{ env.BASE_CANONICAL_URL }}" >> .env.local
# echo "API_HOST_CLIENT=${{ env.API_HOST_CLIENT }}" >> .env.local
# echo "API_HOST_SERVER=${{ env.API_HOST_SERVER }}" >> .env.local
# echo "COOKIE_SECRET=${{ env.COOKIE_SECRET }}" >> .env.local
#
# - name: Run integration tests
# run: pnpm integration
#
# - uses: actions/upload-artifact@v3
# if: always()
# with:
# name: playwright-report
# path: playwright-report/
# retention-days: 30
16 changes: 7 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,15 @@ dist
dev/
storybook-static/
.DS_Store
.idea
.idea/
.env.development
.env.production
/.vitest/
/.vitest-preview/
/test-results/
/playwright-report/
/playwright/.cache/

# Sentry Config File
.sentryclirc
.vitest/
.vitest-preview/
test-results/
playwright-report/
playwright/.cache/
playwright/.auth/

# Sentry Config File
.sentryclirc
120 changes: 75 additions & 45 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,63 +1,93 @@
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

ENV NODE_ENV=production

RUN npm install -g pnpm

# Files required by pnpm install
COPY .npmrc.* package.json pnpm-lock.yaml .pnpmfile.cjs.* ./

# install deps
RUN pnpm add sharp
RUN pnpm install --frozen-lockfile --ignore-scripts --no-optional

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

FROM node:20-slim AS base
ENV PNPM_HOME=/pnpm
ENV NEXT_TELEMETRY_DISABLED=1
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
ENV NODE_ENV=production

# Add the git commit hash to the environment variables
RUN export GIT_SHA=$(git rev-parse HEAD); echo "GIT_SHA=$GIT_SHA" >> .env.local

# ensure pnpm is available in the builder
RUN npm install -g pnpm
ENV PATH="$PNPM_HOME:/app/.bin:/app/node_modules/.bin:$PATH"
ARG GIT_SHA
ENV GIT_SHA="$GIT_SHA"
ENV PORT=8000
ENV SENTRYCLI_SKIP_DOWNLOAD=1
ENV HOSTNAME="0.0.0.0"

RUN corepack enable
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update && apt-get --no-install-recommends install -y libc6
USER $USER_ID
WORKDIR /app

RUN pnpm run build
FROM base as dev
COPY --link . /app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --ignore-scripts --no-optional
ENTRYPOINT ["pnpm", "run", "dev"]

FROM base as unit
COPY --link vitest.config.js /app
COPY --link vitest-setup.ts /app
COPY --link package.json /app
COPY --link tsconfig.json /app
COPY --link logger /app/logger
COPY --link src /app/src
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install vitest
ENTRYPOINT ["vitest"]

FROM base AS build_prod
COPY --link . /app
RUN mkdir -p /app/dist/cache
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --ignore-scripts --no-optional --prod
RUN --mount=type=cache,id=nextjs,target=/app/dist/cache pnpm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

FROM base AS prod
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public
COPY --from=builder /app/.env.local ./

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/dist/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/dist/static ./dist/static
COPY --link --from=build_prod --chown=nextjs:nodejs /app/dist/standalone /app
COPY --link --from=build_prod --chown=nextjs:nodejs /app/dist/static /app/dist/static
COPY --link --from=build_prod --chown=nextjs:nodejs /app/public /app/public
COPY --link --from=build_prod --chown=nextjs:nodejs --chmod=777 /app/dist/cache /app/dist/cache

USER nextjs

EXPOSE 8000
ENTRYPOINT ["node", "server.js"]

ENV PORT 8000

CMD ["node", "server.js"]
FROM mcr.microsoft.com/playwright:v1.42.1-jammy as e2e
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
ENV PNPM_HOME=/pnpm
ENV PATH="$PNPM_HOME:/app/node_modules/.bin:$PATH"
ARG USER_ID=1001
ARG GROUP_ID=1001
ARG GIT_SHA
ENV GIT_SHA="$GIT_SHA"
ENV PORT=8000
ENV HOSTNAME="0.0.0.0"

RUN usermod -u "$USER_ID" pwuser
RUN usermod -g "$GROUP_ID" pwuser

RUN corepack enable
WORKDIR /app

RUN mkdir /app/screenshots
RUN mkdir /app/test-results
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install @playwright/test playwright @faker-js/faker

# including src so that we can use the same tsconfig.json to reconcile imports (mostly for typings)
COPY --link src /app/src
COPY --link playwright.config.ts /app
COPY --link --chown="$USER_ID:$GROUP_ID" playwright /app/playwright
COPY --link e2e /app/e2e
COPY --link tsconfig.json /app
COPY --link --from=build_prod /app/dist/standalone /app
COPY --link --from=build_prod /app/dist/static /app/dist/static
COPY --link --from=build_prod /app/public /app/public
COPY --link --from=build_prod /app/dist/cache /app/dist/cache

ENTRYPOINT ["playwright"]
CMD ["test"]
Loading
Loading