Skip to content

Commit

Permalink
e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Mineev committed Aug 23, 2022
1 parent dc048ef commit 7dda793
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 4 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: frontend

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

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

jobs:
e2e:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16.15.1"

- name: Start containers
run: docker-compose -f compose-e2e-test.yml up -d --build

- name: Install pnpm
uses: pnpm/[email protected]
id: pnpm-install
with:
version: 7
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm i
working-directory: ./frontend/tests

- name: Install Playwright Browsers
run: npx playwright install --with-deps
working-directory: ./frontend/tests

- name: Run tests
run: pnpm test
working-directory: ./frontend/tests

- uses: actions/upload-artifact@v2
with:
name: playwright-report
path: playwright-report/
retention-days: 30
33 changes: 33 additions & 0 deletions compose-e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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"
hostname: "remark42"

ports:
- "8080:8080" # primary rest server
- "8084:8084" # local oauth2 server

environment:
- REMARK_URL=http://127.0.0.1:8080
- SECRET=12345
- DEBUG=true
- ADMIN_PASSWD=password
- AUTH_DEV=true # activate local oauth "dev"
- ADMIN_SHARED_ID=dev_user # set admin flag for default user on local oauth2
- POSITIVE_SCORE=false # restricts comment's score to be only positive
- EDIT_TIME=5m # edit window
- AUTH_ANON=true
- AUTH_EMAIL_ENABLE=true
volumes:
- ./var:/srv/var
8 changes: 4 additions & 4 deletions frontend/apps/remark42/app/utils/post-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ type AllMessages = ChildMessage & ParentMessage;
* @returns request success of fail
*/
export function postMessageToParent(data: ParentMessage): boolean {
if (!window.parent || window.parent === window) {
return false;
if (window.parent !== window) {
window.parent.postMessage(data, '*');
return true;
}

window.parent.postMessage(data, '*');
return true;
return false;
}

/**
Expand Down
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/
17 changes: 17 additions & 0 deletions frontend/e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@remark42/tests",
"version": "1.0.0",
"private": true,
"scripts": {
"test": "playwright test"
},
"author": "Paul Mineev <[email protected]>",
"license": "MIT",
"devDependencies": {
"@playwright/test": "^1.25.0",
"@types/node": "^18.7.8",
"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: 'http://localhost:3000',

/* 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;
21 changes: 21 additions & 0 deletions frontend/e2e/tests/post-comment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test } from "@playwright/test";

test.describe("Post comment", () => {
test.beforeEach(async ({ page }) => {
await page.goto("http://127.0.0.1:8080/web/");
});

test("as dev user", async ({ page }) => {
const iframe = page.frameLocator("iframe[name]");

await iframe.locator("text=Sign In").click();
await iframe.locator("[title='Sign In with Dev']").click();

const authPage = await page.waitForEvent("popup");

await authPage.locator("text=Authorize").click();
await page.locator("body").focus();
await iframe.locator("textarea").type("Hello World");
await iframe.locator("text=Send").click();
});
});
9 changes: 9 additions & 0 deletions frontend/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"],
"baseUrl": "."
},
"include": ["**/*.ts"]
}
73 changes: 73 additions & 0 deletions frontend/pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions frontend/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- "apps/*"
- "e2e"
- "packages/*"

0 comments on commit 7dda793

Please sign in to comment.