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: add e2e tests #43

Merged
merged 51 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8743746
feat: initially add playwright
alexey-yarmosh Nov 1, 2024
50e22d0
test: add token creation test
alexey-yarmosh Nov 1, 2024
d676820
feat: add e2e seed data
alexey-yarmosh Nov 4, 2024
326035d
refactor: e2e tests
alexey-yarmosh Nov 4, 2024
f44a1fd
test: update e2e tests
alexey-yarmosh Nov 5, 2024
7027908
feat: auto run and stop containers/processes
alexey-yarmosh Nov 5, 2024
710ba88
feat: auto run and stop containers/processes
alexey-yarmosh Nov 5, 2024
c6eb539
feat: add non localhost check to init.sh
alexey-yarmosh Nov 6, 2024
f500dcb
fix: dash git clone script
alexey-yarmosh Nov 6, 2024
3d925f4
feat: start services only if there are no already running
alexey-yarmosh Nov 6, 2024
892235b
fix: e2e services start/stop
alexey-yarmosh Nov 6, 2024
8b5b167
feat: remove unused script
alexey-yarmosh Nov 6, 2024
270c6d9
fix: not restarting docker compose properly
alexey-yarmosh Nov 6, 2024
9483d03
feat: separate user for e2e
alexey-yarmosh Nov 6, 2024
89c0d5c
test: add credits e2e tests
alexey-yarmosh Nov 6, 2024
b34ec77
fix: credits e2e tests
alexey-yarmosh Nov 7, 2024
db0e08c
test: index e2e tests
alexey-yarmosh Nov 7, 2024
55b2c23
test: add probes e2e test
alexey-yarmosh Nov 7, 2024
2e50fba
test: add probe adoption test
alexey-yarmosh Nov 7, 2024
9205397
refactor: move e2e tests to the folder
alexey-yarmosh Nov 7, 2024
d18c981
refactor: move client from utils
alexey-yarmosh Nov 7, 2024
0fcda83
feat: pass ENABLE_E2E_MOCKS to e2e container
alexey-yarmosh Nov 7, 2024
5dbc67d
feat: update selectors & knexfile
alexey-yarmosh Nov 11, 2024
75905cd
feat: clean config file
alexey-yarmosh Nov 11, 2024
6523137
feat: remove seed dependency from e2e tests
alexey-yarmosh Nov 11, 2024
8f0b291
refactor: timeouts
alexey-yarmosh Nov 11, 2024
359e296
fix: use consts instead of env vars
alexey-yarmosh Nov 11, 2024
ca40042
feat: separate seed and e2e data
alexey-yarmosh Nov 12, 2024
d1de7e0
fix: relogin on every test
alexey-yarmosh Nov 12, 2024
9f4a857
feat: create user ids dynamically
alexey-yarmosh Nov 12, 2024
16a3497
feat: move generation of user to the fixture
alexey-yarmosh Nov 12, 2024
f4cd325
feat: generate random ips uuids and tokens
alexey-yarmosh Nov 12, 2024
5d97bfc
feat: add generate command
alexey-yarmosh Nov 12, 2024
352e2e2
feat: use 1 worker
alexey-yarmosh Nov 13, 2024
51954d8
feat: add ci workflow
alexey-yarmosh Nov 13, 2024
84a46bd
fix: fixes to run e2e on ubuntu
alexey-yarmosh Nov 15, 2024
707afd6
feat: move paths to .env files
alexey-yarmosh Nov 18, 2024
eee2d8d
misc: small fixes
alexey-yarmosh Nov 20, 2024
6de696f
misc: logging updates
alexey-yarmosh Nov 21, 2024
7a8b744
fix: reporter
alexey-yarmosh Nov 21, 2024
141bddd
fix: do not execute test generator during test running
alexey-yarmosh Nov 21, 2024
e638ff3
refactor: update ci yml files
alexey-yarmosh Nov 21, 2024
dc26903
fix: charset issue in e2e .env file
alexey-yarmosh Nov 21, 2024
f70d84e
misc: small fixes
alexey-yarmosh Nov 21, 2024
14a98e2
refactor: move utils from client.ts
alexey-yarmosh Nov 22, 2024
dfc9ccf
feat: add heading checks
alexey-yarmosh Nov 22, 2024
a67dd37
refactor: rename DASH_URL env var
alexey-yarmosh Nov 22, 2024
26a869a
feat: update probe adoption selector
alexey-yarmosh Nov 22, 2024
8a87c9a
feat: clone dash repo from master branch
alexey-yarmosh Nov 22, 2024
9234a1d
Merge branch 'master' into e2e
MartinKolarik Nov 26, 2024
697981c
fix: use npx instead of pnpm dlx
alexey-yarmosh Nov 28, 2024
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
2 changes: 1 addition & 1 deletion .env.development.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ AUTH_GITHUB_SCOPE=read:user,user:email
AUTH_GITHUB_FIRST_NAME_KEY=name
AUTH_GITHUB_LAST_NAME_KEY=login
AUTH_GITHUB_IDENTIFIER_KEY=id
AUTH_GITHUB_REDIRECT_ALLOW_LIST=http://localhost:13010
AUTH_GITHUB_REDIRECT_ALLOW_LIST=http://localhost:13010,http://localhost:13000

# GitHub API
# A classic token (not scoped), required permissions are: read:org, read:user
Expand Down
74 changes: 74 additions & 0 deletions .env.e2e.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# E2E specific
ENABLE_E2E_MOCKS=true

# DB
DB_CLIENT=mysql
# This is an ip of `host.docker.internal` on Linux
DB_HOST=172.17.0.1
DB_PORT=13306
DB_DATABASE=dashboard-globalping
DB_USER=directus
DB_PASSWORD=password
# Collation mapping from here: https://github.com/sidorares/node-mysql2/blob/bded4980065319e58a4f87d828cc355fb79f5bd3/lib/constants/charsets.js#L199
DB_CHARSET_NUMBER=224

# Directus
# https://docs.directus.io/self-hosted/config-options.html#general
PUBLIC_URL=http://127.0.0.1:18055
LOG_LEVEL=trace
CORS_ENABLED=true
CORS_ORIGIN=http://127.0.0.1:13000,http://127.0.0.1:13010
SESSION_COOKIE_NAME=dash_session_token
SESSION_COOKIE_SAME_SITE=lax
# Important: we assume all queries are unlimited by default
QUERY_LIMIT_DEFAULT=-1
# https://docs.directus.io/self-hosted/config-options.html#security
KEY=directus
SECRET=xxx
# https://docs.directus.io/self-hosted/config-options.html#sso-oauth2-and-openid
AUTH_GITHUB_CLIENT_ID=gh_client_id
AUTH_GITHUB_CLIENT_SECRET=gh_client_secret
# https://docs.directus.io/self-hosted/config-options.html#admin-account
[email protected]
ADMIN_PASSWORD=password

# Directus GitHub Auth
# https://docs.directus.io/self-hosted/config-options.html#sso-oauth2-and-openid
AUTH_PROVIDERS=github
AUTH_GITHUB_DRIVER=oauth2
AUTH_GITHUB_AUTHORIZE_URL=https://github.com/login/oauth/authorize
AUTH_GITHUB_ACCESS_URL=https://github.com/login/oauth/access_token
AUTH_GITHUB_PROFILE_URL=https://api.github.com/user
AUTH_GITHUB_ALLOW_PUBLIC_REGISTRATION=true
AUTH_GITHUB_SCOPE=read:user,user:email
AUTH_GITHUB_FIRST_NAME_KEY=name
AUTH_GITHUB_LAST_NAME_KEY=login
AUTH_GITHUB_IDENTIFIER_KEY=id
AUTH_GITHUB_REDIRECT_ALLOW_LIST=http://127.0.0.1:13010,http://127.0.0.1:13000

# GitHub API
# A classic token (not scoped), required permissions are: read:org, read:user
GITHUB_ACCESS_TOKEN=
# Generated during enabling of webhooks and passed to the app, to validate requests
# Create the webhook at https://github.com/sponsors/jsdelivr/globalping-dash-directus/webhooks/441768912/edit#deliveries
# See WEBHOOK_FLOW_ID in .env.example for the webhook URL
GITHUB_WEBHOOK_SECRET=

# Globalping API
GLOBALPING_URL=http://host.docker.internal:3000/v1
GP_SYSTEM_KEY=

# Geonames API
GEONAMES_USERNAME=

# App
CREDITS_PER_DOLLAR=2000
CREDITS_PER_ADOPTED_PROBE_DAY=150
ADOPTED_PROBES_CHECK_TIME_MAX_DEVIATION_MINS=5
# To trigger credits assignment probe need to be online >20 hours during the day. Current "Adopted probes status CRON" is "*/10 * * * *", which is 6 times an hour
# So required value is 20 * 6 = 120
ADOPTED_PROBES_REQUIRED_ONLINE_TIMES=120

# Are updated during `npm run init`
AUTH_GITHUB_DEFAULT_ROLE_ID=
AUTH_DISABLE_DEFAULT=false
14 changes: 12 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# File is used during execution of:
# - migrations
# - schema updates
# - host inits
# - e2e tests

DB_CLIENT=mysql
DB_HOST=localhost
DB_HOST=127.0.0.1
DB_PORT=13306
DB_DATABASE=dashboard-globalping
DB_USER=directus
Expand All @@ -11,7 +17,11 @@ MIGRATIONS_PATH=extensions/migrations
# ID that will be used for the flow. Any valid UUID.
# The final URL for the webhook is ${host}/flows/trigger/${WEBHOOK_FLOW_ID}
WEBHOOK_FLOW_ID=e8a4c2b2-3ed4-4ddc-b98e-34c1952c2323
DIRECTUS_URL=http://localhost:18055
DIRECTUS_URL=http://127.0.0.1:18055

# E2E
# Used during nuxt build of the globalping-dash repo.
DASH_URL=http://127.0.0.1:13010

[email protected]
ADMIN_PASSWORD=password
Expand Down
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"ignorePatterns": [
"**/dist",
"/extensions",
"**/shims.d.ts"
"**/shims.d.ts",
"test/e2e/globalping-dash",
"test-results"
],
"rules": {
"n/no-missing-import": [
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: E2E

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

jobs:
build:
name: Run e2e tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies
run: |
corepack enable
pnpm install
- name: Install Playwright browsers
run: |
pnpm exec playwright install --with-deps chromium
- name: Generate env files
run: |
cp .env.e2e.example .env.e2e
cp .env.example .env
- name: Build docker compose
run: |
pnpm run test:e2e:build:directus
- name: Build dashboard repo
run: |
pnpm run test:e2e:build:dash
- name: Run tests
run: |
pnpm run test:e2e:run
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ config/local*
.env*
!.env*.example
.vscode/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/test/e2e/globalping-dash/
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

## Prod first deploy

- copy `.env.example` to `.env` and fulfill all empty values except `ADMIN_ACCESS_TOKEN`
- copy `.env.production.example` to the env vars of the container and fulfill all empty values except `AUTH_GITHUB_DEFAULT_ROLE_ID` and `AUTH_DISABLE_DEFAULT`
- run the remote container
- `pnpm run init`
- copy `.env.example` to `.env` and fulfill all empty values except `ADMIN_ACCESS_TOKEN`.
- copy `.env.production.example` to the env vars of the container and fulfill all empty values except `AUTH_GITHUB_DEFAULT_ROLE_ID` and `AUTH_DISABLE_DEFAULT`.
- run the remote container.
- `pnpm run schema:apply`
- `pnpm run migrate`
- get default role id and set it to the `AUTH_GITHUB_DEFAULT_ROLE_ID` env var
- restart the container
- login using github. Re-login as admin and give github user admin rights. Then set that value `AUTH_DISABLE_DEFAULT=true`. Then restart the container
- Login using github. Generate a static access token for your user and save it to the local .env file as `ADMIN_ACCESS_TOKEN`

## Prod other deploys

Expand Down
30 changes: 30 additions & 0 deletions docker-compose.e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: e2e-globalping-dash-directus
version: '3'
services:
mariadb:
image: mariadb:10.11.5
environment:
- MARIADB_DATABASE=dashboard-globalping
- MARIADB_USER=directus
- MARIADB_PASSWORD=password
- MARIADB_ROOT_PASSWORD=root
ports:
- "13306:3306"
volumes:
- ./config/init.sql:/docker-entrypoint-initdb.d/init.sql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-u", "directus", "-ppassword"]
interval: 3s
timeout: 2s
retries: 10
directus:
depends_on:
mariadb:
condition: service_healthy
build:
context: .
dockerfile: Dockerfile
env_file:
- .env.e2e
ports:
- "18055:8055"
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: globalping-dash-directus
version: '3'
services:
mariadb:
Expand All @@ -16,7 +17,7 @@ services:
interval: 3s
timeout: 2s
retries: 10
globalping-dash-directus:
directus:
depends_on:
mariadb:
condition: service_healthy
Expand Down
60 changes: 36 additions & 24 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
import _ from 'lodash';

/**
* @typedef {import('knex').Knex.Config} KnexConfig
* @type {{ [key: string]: KnexConfig }}
*/
export default _.merge({}, ...[ 'development' ].map((environment) => {
return {
[environment]: {
client: 'mysql',
connection: {
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'directus',
password: process.env.DB_PASSWORD || 'password',
database: process.env.DB_DATABSE || 'dashboard-globalping',
port: process.env.DB_PORT || 13306,
},
pool: {
min: 0,
max: 10,
propagateCreateError: false,
},
acquireConnectionTimeout: 2000,
seeds: {
directory: `./seeds/${environment}`,
},
export default {
development: {
client: 'mysql',
connection: {
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'directus',
password: process.env.DB_PASSWORD || 'password',
database: process.env.DB_DATABSE || 'dashboard-globalping',
port: process.env.DB_PORT || 13306,
},
};
}));
pool: {
min: 0,
max: 10,
propagateCreateError: false,
},
acquireConnectionTimeout: 2000,
seeds: {
directory: `./seeds/development`,
},
},
e2e: {
client: 'mysql',
connection: {
host: process.env.DB_HOST || '127.0.0.1',
user: process.env.DB_USER || 'directus',
password: process.env.DB_PASSWORD || 'password',
database: process.env.DB_DATABSE || 'dashboard-globalping',
port: process.env.DB_PORT || 13306,
},
pool: {
min: 0,
max: 10,
propagateCreateError: false,
},
acquireConnectionTimeout: 2000,
},
};
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
},
"devDependencies": {
"@martin-kolarik/eslint-config": "^7.3.2",
"@playwright/test": "^1.48.2",
"@types/bluebird": "^3.5.42",
"@types/config": "^3.3.4",
"@types/eslint": "^8.56.11",
"@types/lodash": "^4.17.7",
"@types/mocha": "^10.0.7",
"@types/node": "^22.8.6",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"cross-env": "^7.0.3",
"dotenv": "^16.4.5",
"dotenv-cli": "^7.4.2",
"eslint": "^8.57.0",
"eslint-plugin-chai-expect": "^3.1.0",
Expand All @@ -29,21 +32,28 @@
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.6.0",
"eslint-plugin-vue": "^9.27.0",
"execa": "^9.5.1",
"husky": "^8.0.3",
"pm2": "^5.4.2",
"relative-day-utc": "^1.3.0",
"typescript": "~5.2.2"
},
"scripts": {
"lint": "eslint --cache .",
"lint:fix": "pnpm lint --fix",
"init": "./scripts/init.sh",
"init:dev": "./scripts/init.sh --dev",
"init:dev": "./scripts/init.sh development",
"init:e2e": "./scripts/init.sh e2e",
"docker:ls:update": "node ./scripts/docker-ls.js",
"migrate": "rm -rf ./extensions/migrations/* && mkdir -p ./extensions/migrations/ && cp -rp ./src/extensions/migrations/* ./extensions/migrations/ && cp -p ./src/extensions/migration-utils.js ./extensions/ && dotenv -- npx [email protected] database migrate:latest",
"seed": "NODE_ENV=development dotenv -- knex seed:run",
"schema:apply": "npx [email protected] schema apply --yes snapshots/collections-schema.yml",
"schema:snapshot": "npx [email protected] schema snapshot --yes snapshots/collections-schema.yml",
"prepare": "husky install || echo 'Failed to install husky'; rm -f .eslintcache",
"build:in-sequence": "grep -E 'AS builder-[0-9]+' Dockerfile | awk -F 'AS ' '{print $2}' | xargs -r -P 1 -I STAGE docker build --target STAGE ."
"test:e2e": "npm run test:e2e:build:directus && npm run test:e2e:build:dash && npm run test:e2e:run",
"test:e2e:build:directus": "docker compose -f docker-compose.e2e.yml up --build -d && pnpm run init:e2e && docker compose -f docker-compose.e2e.yml stop",
"test:e2e:build:dash": "git clone https://github.com/jsdelivr/globalping-dash.git test/e2e/globalping-dash; cd test/e2e/globalping-dash && git reset --hard origin/master && git pull --force && pnpm install --ignore-workspace && dotenv -e ../../../.env -- pnpm build; cd ../../../;",
"test:e2e:run": "pnpm exec playwright test --grep-invert='.*generate-test\\.spec\\.ts'",
"test:e2e:generate": "pnpm exec playwright test test/e2e/generate-test.spec.ts --headed"
},
"repository": {
"type": "git",
Expand Down
32 changes: 32 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { defineConfig, devices } from '@playwright/test';
import dotenv from 'dotenv';

dotenv.config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './test/e2e',
workers: 1,
use: {
baseURL: process.env.DASH_URL,
},
forbidOnly: !!process.env.CI,
reporter: 'list',
projects: [
{ name: 'setup', testMatch: /.*\.setup\.ts/ },

{
name: 'teardown', testMatch: /.*\.teardown\.ts/ },

{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
},
dependencies: [ 'setup' ],
teardown: 'teardown',
},
],
});
Loading