Skip to content

Commit

Permalink
add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Mineev authored and paskal committed Sep 10, 2022
1 parent 9ad3be2 commit 0f7ac51
Show file tree
Hide file tree
Showing 13 changed files with 353 additions and 3 deletions.
13 changes: 10 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
/logs/
/target/
/var/
/frontend/node_modules/
/frontend/apps/remark42/node_modules/
/frontend/apps/remark42/public/
/.vscode/
/.idea/
/bin/
/.git/

# frontend files not needed in docker image
/frontend/node_modules/
/frontend/apps/remark42/node_modules/
/frontend/apps/remark42/public/
# e2e tests arficats
/frontend/e2e/playwright-report/
/frontend/e2e/playwright/.cache/
/frontend/e2e/test-results/

# source files
docker-compose.yml
compose-dev-backend.yml
Expand All @@ -28,3 +34,4 @@ debug.test
*.test
remark42
/backend/var/
/playwright-report/
34 changes: 34 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: e2e

on:
push:
branches: [master]
paths:
- "frontend/apps/remark42/**"
- "frontend/e2e/**"

pull_request:
branches: [master]
paths:
- "frontend/apps/remark42/**"
- "frontend/e2e/**"

jobs:
tests:
name: Tests
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build & run containers
id: tests
run: COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose -f compose-e2e-test.yml up --build --quiet-pull --exit-code-from tests

- uses: actions/upload-artifact@v2
if: always()
with:
name: playwright-report
path: ./playwright-report/
retention-days: 30
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ compose-private-frontend.yml
compose-private.yml
/backend/_example/*/vendor
http-client.env.json
/playwright-report/
36 changes: 36 additions & 0 deletions compose-e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# compose for running e2e tests in CI
version: "2"

services:
remark42:
build:
context: .
dockerfile: Dockerfile
args:
- SKIP_BACKEND_TEST=true
- SKIP_FRONTEND_TEST=true

image: umputun/remark42:dev
container_name: "remark42"

environment:
# remark42 hostname used for proper dev auth work for tests container which connects to it
# using the such hostname (unlike local development where 127.0.0.1 is used)
- REMARK_URL=http://remark42:8080
- SECRET=12345
- DEBUG=true
- ADMIN_PASSWD=password
- AUTH_DEV=true # activate local OAuth "dev" listening on http://remark42:8084
- ADMIN_SHARED_ID=dev_user # set admin flag for default user on local oauth2
- AUTH_ANON=true
- AUTH_EMAIL_ENABLE=true
volumes:
- ./var:/srv/var

tests:
build:
context: ./frontend
dockerfile: Dockerfile.e2e
depends_on: [remark42]
volumes:
- ./playwright-report:/frontend/e2e/playwright-report
7 changes: 7 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.vscode/
/.idea/

# e2e tests arficats
/e2e/playwright-report/
/e2e/playwright/.cache/
/e2e/test-results/
15 changes: 15 additions & 0 deletions frontend/Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM mcr.microsoft.com/playwright:v1.25.0-focal

ENV CI true
WORKDIR /frontend

COPY ./package.json ./pnpm-workspace.yaml ./pnpm-lock.yaml /frontend/
COPY ./e2e/package.json /frontend/e2e/
RUN corepack enable pnpm && pnpm install

COPY ./e2e/playwright.config.ts /frontend/e2e/
COPY ./e2e/tests /frontend/e2e/tests/

WORKDIR /frontend/e2e

CMD pnpm test
4 changes: 4 additions & 0 deletions frontend/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
19 changes: 19 additions & 0 deletions frontend/e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@remark42/tests",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"test": "playwright test"
},
"author": "Paul Mineev <paul@mineev.me>",
"license": "MIT",
"devDependencies": {
"@playwright/test": "^1.25.0",
"@types/node": "^18.7.8",
"nanoid": "^4.0.0",
"playwright": "^1.25.0",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
}
}
107 changes: 107 additions & 0 deletions frontend/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import type { PlaywrightTestConfig } from '@playwright/test'
import { devices } from '@playwright/test'

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
const config: PlaywrightTestConfig = {
testDir: './tests',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000,
},
/* 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: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.CI ? 'http://remark42:8080' : 'http://127.0.0.1:8080',

/* 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: 'chromium',
use: {
...devices['Desktop Chrome'],
},
},

{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
},
},

{
name: 'webkit',
use: {
...devices['Desktop Safari'],
},
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: {
// ...devices['Pixel 5'],
// },
// },
// {
// name: 'Mobile Safari',
// use: {
// ...devices['iPhone 12'],
// },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: {
// channel: 'msedge',
// },
// },
// {
// name: 'Google Chrome',
// use: {
// channel: 'chrome',
// },
// },
],

/* Folder for test artifacts such as screenshots, videos, traces, etc. */
// outputDir: 'test-results/',

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// port: 3000,
// },
}

export default config
8 changes: 8 additions & 0 deletions frontend/e2e/prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('prettier').Config} */
module.exports = {
singleQuote: true,
semi: false,
arrowParens: 'always',
trailingComma: 'es5',
printWidth: 120,
}
30 changes: 30 additions & 0 deletions frontend/e2e/tests/post-comment.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { test } from '@playwright/test'
import { nanoid } from 'nanoid'
import * as path from 'path'

test.describe('Post comment', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/web/')
})

test('as dev user', async ({ page, browserName }) => {
const iframe = page.frameLocator('iframe[name]')
await iframe.locator('text=Sign In').click()
const [authPage] = await Promise.all([
page.waitForEvent('popup'),
iframe.locator("[title='Sign In with Dev']").click(),
])
await authPage.locator('text=Authorize').click()
// triggers tab visibility and enables widget to re-render with auth state
await page.press('iframe[name]', 'Tab')
await iframe.locator('textarea').click()
const message = `Hello world! ${nanoid()}`
await iframe.locator('textarea').type(message)
await iframe.locator('text=Send').click()
// checks if comment was posted
iframe.locator(`text=${message}`).first()
await page.reload()
// checks if saved comment is visible
iframe.locator(`text=${message}`).first()
})
})
Loading

0 comments on commit 0f7ac51

Please sign in to comment.