Skip to content

Commit

Permalink
chore: add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-greffe committed Mar 20, 2024
1 parent 77dc07e commit c19fe8d
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 69 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ jobs:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
run: bash ./scripts/run_tests.sh -n ${{ matrix.node }} -m ${{ matrix.mongo }}

build_e2e_tests:
name: Build e2e tests
if: ${{ contains(github.event.head_commit.message, 'e2e tests') }}
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: true
- name: Init runner
run: bash ./scripts/init_runner.sh ${{ github.job }}
- name: Setup workspace
env:
GITHUB_DEVELOPMENT_PAT: ${{ secrets.GH_DEVELOPMENT_PAT }}
run: bash ./scripts/setup_workspace.sh -k nokli
- name: Build e2e tests
run: bash ./scripts/build_e2e_tests.sh

build_app:
name: Build app
if: ${{ !contains(github.event.head_commit.message, 'skip app') }}
Expand Down
67 changes: 67 additions & 0 deletions scripts/build_e2e_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
set -euo pipefail
# set -x

THIS_FILE=$(readlink -f "${BASH_SOURCE[0]}")
THIS_DIR=$(dirname "$THIS_FILE")
ROOT_DIR=$(dirname "$THIS_DIR")

. "$THIS_DIR/kash/kash.sh"

## Parse options
##

PUBLISH=false
while getopts "p" option; do
case $option in
p) # defines mongo version
PUBLISH=true
;;
*)
;;
esac
done

## Init workspace
##

WORKSPACE_DIR="$(dirname "$ROOT_DIR")"
init_app_infos "$ROOT_DIR" "$WORKSPACE_DIR/development/workspaces/apps"

APP=$(get_app_name)
VERSION=$(get_app_version)
FLAVOR=$(get_app_flavor)

echo "About to build ${APP} v${VERSION}-$FLAVOR ..."

load_env_files "$WORKSPACE_DIR/development/common/kalisio_dockerhub.enc.env" "$WORKSPACE_DIR/development/common/SLACK_WEBHOOK_APPS.enc.env"
load_value_files "$WORKSPACE_DIR/development/common/KALISIO_DOCKERHUB_PASSWORD.enc.value"

## Build container
##

IMAGE_NAME="kalisio/$APP-e2e-tests"
IMAGE_TAG="$VERSION-$FLAVOR"

begin_group "Building container ..."

docker login --username "$KALISIO_DOCKERHUB_USERNAME" --password-stdin < "$KALISIO_DOCKERHUB_PASSWORD"
# DOCKER_BUILDKIT is here to be able to use Dockerfile specific dockerginore (app.Dockerfile.dockerignore)
DOCKER_BUILDKIT=1 docker build \
--build-arg APP="$APP" \
--build-arg NODE_APP_INSTANCE="$FLAVOR" \
--build-arg SUBDOMAIN="$FLAVOR.kalisio.xyz" \
--build-arg HEADLESS=true \
-f test.Dockerfile \
-t "$IMAGE_NAME:$IMAGE_TAG" \
"$WORKSPACE_DIR"
docker tag "$IMAGE_NAME:$IMAGE_TAG" "$IMAGE_NAME:$FLAVOR"

if [ "$PUBLISH" = true ]; then
docker push "$IMAGE_NAME:$IMAGE_TAG"
docker push "$IMAGE_NAME:$FLAVOR"
fi

docker logout

end_group "Building container ..."
72 changes: 72 additions & 0 deletions test.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## Use a builder
##

FROM node:16-bookworm-slim as Builder
LABEL maintainer="[email protected]"

COPY . /opt/kalisio

# Setup ENV
ARG APP
ARG NODE_APP_INSTANCE
ARG SUBDOMAIN
ARG HEADLESS

ENV APP=$APP
ENV NODE_APP_INSTANCE=$NODE_APP_INSTANCE
ENV SUBDOMAIN=$SUBDOMAIN
ENV HEADLESS=$HEADLESS

# Test environment configuration
WORKDIR /opt/kalisio/
RUN \
cd /opt/kalisio/kdk && yarn && yarn link --link-folder /opt/kalisio/yarn-links && \
cd /opt/kalisio/$APP && yarn && yarn link "@kalisio/kdk" --link-folder /opt/kalisio/yarn-links

## Copy to final container
##

FROM node:16-bookworm-slim
LABEL maintainer="[email protected]"

ENV APP=$APP
ENV NODE_APP_INSTANCE=$NODE_APP_INSTANCE
ENV SUBDOMAIN=$SUBDOMAIN
ENV HEADLESS=$HEADLESS

# Setup Puppeteer
# https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y \
google-chrome-stable \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-thai-tlwg \
fonts-kacst \
fonts-freefont-ttf \
libxss1 \
xorg \
xserver-xorg \
xvfb \
libx11-dev \
libxext-dev \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

# Copy Puppeteer cache from builder
COPY --from=Builder --chown=node:node /root/.cache/puppeteer /home/node/.cache/puppeteer

# Copy from builder
COPY --from=Builder --chown=node:node /opt/kalisio /opt/kalisio

# From now on, run stuff as 'node'
USER node

# Run tests
WORKDIR /opt/kalisio/$APP
CMD [ "yarn", "test:client" ]
16 changes: 16 additions & 0 deletions test.Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Ignore verything
*

# Except these
!kdk/*
!kapp/test/*
!kapp/package.json

# But ignore these anyway
**/node_modules
**/npm-debug.log
**/*Dockerfile
**/docker-compose*
**/*dockerignore
**/.git
**/.gitignore
4 changes: 4 additions & 0 deletions test/app.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ describe(suite, () => {
browser: {
args: ['--lang=fr'],
slowMo: 1
},
localStorage: {
'k-app-welcome': false,
'k-app-install': false
}
})
page = await runner.start()
Expand Down
4 changes: 4 additions & 0 deletions test/layout.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ describe(suite, () => {
browser: {
args: ['--lang=fr'],
slowMo: 2
},
localStorage: {
'k-app-welcome': false,
'k-app-install': false
}
})
page = await runner.start()
Expand Down
62 changes: 33 additions & 29 deletions test/misc.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,41 @@ import { core } from '@kalisio/kdk/test.client.js'
const suite = 'misc'

describe(suite, () => {
let runner
let page
let user
let runner
let page
let user

before(async () => {
runner = new core.Runner(suite, {
appName: 'kapp',
browser: {
args: ['--lang=fr'],
slowMo: 2
}
})
page = await runner.start()
user = {
email: '[email protected]',
password: 'Pass;word1'
}
await core.login(page, user)
before(async () => {
runner = new core.Runner(suite, {
appName: 'kapp',
browser: {
args: ['--lang=fr'],
slowMo: 2
},
localStorage: {
'k-app-welcome': false,
'k-app-install': false
}
})
page = await runner.start()
user = {
email: '[email protected]',
password: 'Pass;word1'
}
await core.login(page, user)
})

it('misc', async () => {
await page.click('#left-opener')
await page.waitForTimeout(1000)
await page.click('#miscellaneous')
await page.waitForTimeout(1000)
const match = await runner.captureAndMatch('misc')
expect(match).beTrue()
})
it('misc', async () => {
await page.click('#left-opener')
await page.waitForTimeout(1000)
await page.click('#miscellaneous')
await page.waitForTimeout(1000)
const match = await runner.captureAndMatch('misc')
expect(match).beTrue()
})

after(async () => {
await core.logout(page)
await runner.stop()
})
after(async () => {
await core.logout(page)
await runner.stop()
})
})
84 changes: 44 additions & 40 deletions test/webpush.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,53 @@ import { type, clickAction } from '@kalisio/kdk/test/client/core/utils.js';
const suite = 'webpush'

describe(suite, () => {
let runner
let page
let user
let runner
let page
let user

before(async () => {
runner = new core.Runner(suite, {
appName: 'kapp',
browser: {
args: ['--lang=fr'],
slowMo: 2
}
})
page = await runner.start()
user = {
email: '[email protected]',
password: 'Pass;word1'
}
await core.login(page, user)
before(async () => {
runner = new core.Runner(suite, {
appName: 'kapp',
browser: {
args: ['--lang=fr'],
slowMo: 2
},
localStorage: {
'k-app-welcome': false,
'k-app-install': false
}
})
page = await runner.start()
user = {
email: '[email protected]',
password: 'Pass;word1'
}
await core.login(page, user)
})

it('webpush', async () => {
await page.click('#left-opener')
await page.waitForTimeout(1000)
await page.click('#webpush')
await page.waitForTimeout(1000)
await type(page, '#title-field', 'Mon super titre')
await type(page, '#body-field', 'Mon magnifique contenu')
await type(page, '#icon-field', 'Ma fabuleuse icone')
await type(page, '#url-field', 'Ma merveilleuse URL')
await core.clickAction(page, 'push-btn')
await page.waitForTimeout(1000)
})
it('webpush', async () => {
await page.click('#left-opener')
await page.waitForTimeout(1000)
await page.click('#webpush')
await page.waitForTimeout(1000)
await type(page, '#title-field', 'Mon super titre')
await type(page, '#body-field', 'Mon magnifique contenu')
await type(page, '#icon-field', 'Ma fabuleuse icone')
await type(page, '#url-field', 'Ma merveilleuse URL')
await core.clickAction(page, 'push-btn')
await page.waitForTimeout(1000)
})

it('webpush-clean', async () => {
const cancelButtons = await page.$x('//button[contains(text(), "cancel")]');
for (const cancelButton of cancelButtons) {
await cancelButton.click();
}
await page.waitForTimeout(1000);
});
it('webpush-clean', async () => {
const cancelButtons = await page.$x('//button[contains(text(), "cancel")]')
for (const cancelButton of cancelButtons) {
await cancelButton.click()
}
await page.waitForTimeout(1000)
})

after(async () => {
await core.logout(page)
await runner.stop()
})
after(async () => {
await core.logout(page)
await runner.stop()
})
})

0 comments on commit c19fe8d

Please sign in to comment.