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

Feat/e2e #31

Merged
merged 9 commits into from
Jun 16, 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
14 changes: 14 additions & 0 deletions .ddev/commands/playwright/playwright
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
tyrann0us marked this conversation as resolved.
Show resolved Hide resolved
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
cd /var/www/html || exit 1
cd "${PLAYWRIGHT_TEST_DIR}" || exit 1

export PLAYWRIGHT_BROWSERS_PATH=0
PRE="sudo -u pwuser PLAYWRIGHT_BROWSERS_PATH=0 "

$PRE yarn playwright "$@"
17 changes: 17 additions & 0 deletions .ddev/commands/playwright/playwright-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
cd /var/www/html || exit 1
cd "${PLAYWRIGHT_TEST_DIR}" || exit 1

export PLAYWRIGHT_BROWSERS_PATH=0
PRE="sudo -u pwuser PLAYWRIGHT_BROWSERS_PATH=0 "

$PRE yarn install
$PRE yarn playwright install --with-deps
# Conditionally copy an .env file if an example file exists
[ -f .env.example ] && [ ! -f .env ] && $PRE cp -n .env.example .env; exit 0
5 changes: 3 additions & 2 deletions .ddev/commands/web/orchestrate
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

mkdir -p "${DDEV_DOCROOT}"
pushd "${DDEV_DOCROOT}"
PLUGIN_FOLDER="${DDEV_DOCROOT}/wp-content/mu-plugins/${PLUGIN_NAME:-$DDEV_PROJECT}"
MUPLUGIN_FOLDER="${DDEV_DOCROOT}/wp-content/mu-plugins/${PLUGIN_NAME:-$DDEV_PROJECT}"
TEST_PLUGIN_FOLDER="${DDEV_DOCROOT}/wp-content/plugins/wp-stash-test-plugin"
VALID_ARGS=$(getopt -o fp: --long force,plugin: -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
Expand All @@ -19,7 +20,7 @@ while [ : ]; do
shift
export RECREATE_ENV=1;
popd
find "${DDEV_DOCROOT}" -mindepth 1 ! -regex "^${PLUGIN_FOLDER}\(/.*\)?" -delete
find "${DDEV_DOCROOT}" -mindepth 1 ! -regex "^${MUPLUGIN_FOLDER}\(/.*\)?" ! -regex "^${TEST_PLUGIN_FOLDER}\(/.*\)?" -delete
pushd "${DDEV_DOCROOT}"
;;
--) shift;
Expand Down
12 changes: 12 additions & 0 deletions .ddev/commands/web/orchestrate.d/35_activate_test_plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

pushd "${DDEV_DOCROOT}" || exit

flags=""
if [ "${WP_MULTISITE}" = "true" ]; then
flags+=" --network"
fi

wp plugin activate wp-stash-test-plugin $flags

popd
2 changes: 1 addition & 1 deletion .ddev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ php_version: "8.0"
webserver_type: nginx-fpm
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: true
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
database:
Expand Down
38 changes: 38 additions & 0 deletions .ddev/docker-compose.playwright.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
services:
playwright:
build:
context: playwright-build
container_name: ddev-${DDEV_SITENAME}-playwright
hostname: ${DDEV_SITENAME}-playwright
# These labels ensure this service is discoverable by ddev.
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
environment:
# Modify the PLAYWRIGHT_TEST_DIR folder path to suit your needs
- PLAYWRIGHT_TEST_DIR=tests/Playwright
- NETWORK_IFACE=eth0
- DISPLAY=:1
- VIRTUAL_HOST=$DDEV_HOSTNAME
- HTTP_EXPOSE=8443:8444,9322:9323
- HTTPS_EXPOSE=8444:8444,9323:9323
- DDEV_UID=${DDEV_UID}
- DDEV_GID=${DDEV_GID}
expose:
- "8444"
- "9323"
depends_on:
- web
volumes:
- .:/mnt/ddev_config
- ddev-global-cache:/mnt/ddev-global-cache
- ../:/var/www/html:rw
external_links:
- ddev-router:${DDEV_HOSTNAME}
working_dir: /var/www/html
57 changes: 57 additions & 0 deletions .ddev/playwright-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
# If on arm64 machine, edit to use mcr.microsoft.com/playwright:focal-arm64
FROM mcr.microsoft.com/playwright:focal

# Debian images by default disable apt caching, so turn it on until we finish
# the build.
RUN mv /etc/apt/apt.conf.d/docker-clean /etc/apt/docker-clean-disabled

USER root

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& apt-get install -y sudo libnss3-tools

# Give the pwuser user full `sudo` privileges
RUN echo "pwuser ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/pwuser \
&& chmod 0440 /etc/sudoers.d/pwuser

# CAROOT for `mkcert` to use, has the CA config
ENV CAROOT=/mnt/ddev-global-cache/mkcert

# Install the correct architecture binary of `mkcert`
RUN export TARGETPLATFORM=linux/$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') && mkdir -p /usr/local/bin && curl --fail -JL -s -o /usr/local/bin/mkcert "https://dl.filippo.io/mkcert/latest?for=${TARGETPLATFORM}"
RUN chmod +x /usr/local/bin/mkcert


# Install a window manager.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& apt-get install -y icewm xauth

# Install kasmvnc for remote access.
RUN /bin/bash -c 'if [ $(arch) == "aarch64" ]; then KASM_ARCH=arm64; else KASM_ARCH=amd64; fi; wget https://github.com/kasmtech/KasmVNC/releases/download/v1.1.0/kasmvncserver_bullseye_1.1.0_${KASM_ARCH}.deb'
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get install -y ./kasmvncserver*.deb

# We're done with apt so disable caching again for the final image.
RUN mv /etc/apt/docker-clean-disabled /etc/apt/apt.conf.d/docker-clean

# prepare KasmVNC
RUN sudo -u pwuser mkdir /home/pwuser/.vnc
COPY kasmvnc.yaml xstartup /home/pwuser/.vnc/
RUN chown pwuser:pwuser /home/pwuser/.vnc/*
RUN sudo -u pwuser touch /home/pwuser/.vnc/.de-was-selected
RUN sudo -u pwuser /bin/bash -c 'echo -e "secret\nsecret\n" | kasmvncpasswd -wo -u pwuser' # We actually disable auth, but KASM complains without it


COPY entrypoint.sh /root/entrypoint.sh
ENTRYPOINT "/root/entrypoint.sh"
18 changes: 18 additions & 0 deletions .ddev/playwright-build/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#

# Change pwuser IDs to the host IDs supplied by DDEV
usermod -u ${DDEV_UID} pwuser
groupmod -g ${DDEV_GID} pwuser
usermod -a -G ssl-cert pwuser

# Install DDEV certificate
sudo -u pwuser mkcert -install

# Run CMD from parameters as pwuser
sudo -u pwuser vncserver -fg -disableBasicAuth
14 changes: 14 additions & 0 deletions .ddev/playwright-build/kasmvnc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#
logging:
log_writer_name: all
log_dest: syslog
level: 100

network:
ssl:
require_ssl: false
32 changes: 32 additions & 0 deletions .ddev/playwright-build/xstartup
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get julienloizelet/ddev-playwright
#
# This file comes from https://github.com/julienloizelet/ddev-playwright
#

export DISPLAY=:1

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
OS=`uname -s`
if [ $OS = 'Linux' ]; then
case "$WINDOWMANAGER" in
*gnome*)
if [ -e /etc/SuSE-release ]; then
PATH=$PATH:/opt/gnome/bin
export PATH
fi
;;
esac
fi
if [ -x /etc/X11/xinit/xinitrc ]; then
exec /etc/X11/xinit/xinitrc
fi
if [ -f /etc/X11/xinit/xinitrc ]; then
exec sh /etc/X11/xinit/xinitrc
fi
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
icewm-session
13 changes: 13 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Run Playwright tests via DDEV
on:
push:
workflow_dispatch:
jobs:
ddev-playwright:
uses: inpsyde/reusable-workflows/.github/workflows/ddev-playwright.yml@feature/ddev-playwright
secrets:
COMPOSER_AUTH_JSON: ${{ secrets.PACKAGIST_AUTH_JSON }}
with:
DDEV_ORCHESTRATE_CMD: ddev orchestrate
PLAYWRIGHT_INSTALL_CMD: ddev playwright-install
PLAYWRIGHT_RUN_CMD: ddev playwright test
6 changes: 6 additions & 0 deletions .idea/WP-Stash.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/phpunit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/Playwright/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BASEURL="https://wp-stash.ddev.site"

PAGE_URL="/"
5 changes: 5 additions & 0 deletions tests/Playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
11 changes: 11 additions & 0 deletions tests/Playwright/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "playwright",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@playwright/test": "^1.34.2",
"dotenv": "^16.0.3"
},
"scripts": {}
}
40 changes: 40 additions & 0 deletions tests/Playwright/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @ts-check
const { defineConfig, devices } = require('@playwright/test');

require('dotenv').config({ path: '.env' });

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
//workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
[process.env.CI ? 'github' : 'list'],
['html', {open: 'never'}],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.BASEURL,
ignoreHTTPSErrors: true,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
}
]
});
26 changes: 26 additions & 0 deletions tests/Playwright/tests/helper-plugin.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const {test, expect} = require('@playwright/test');

const {
PAGE_URL,
} = process.env;
[
'Using object cache',
'Using WP-Stash',
'Get unset key',
'Set single',
'Delete single',
'Get unset group',
'Set multiple',
'Delete multiple',
].forEach((testName) => {
test(testName, async({page}) => {
await page.goto(PAGE_URL);

console.log('Opened ' + page.url())

const locator = await page.getByText(testName)

await expect(locator).toHaveClass('pass')
});

})
Loading