diff --git a/.github/workflows/playwright.yaml b/.github/workflows/playwright.yaml new file mode 100644 index 0000000..db2cec5 --- /dev/null +++ b/.github/workflows/playwright.yaml @@ -0,0 +1,71 @@ +# +# Copyright 2021-Present The Serverless Workflow Specification Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name: Playwright E2E Tests + +on: + push: + branches: [main] + pull_request: + branches: ["**"] + types: [opened, reopened, ready_for_review, synchronize] + +jobs: + e2e: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - name: Checkout repo + uses: actions/checkout@v6 + + - name: Setup Node + uses: actions/setup-node@v6 + with: + node-version: 24 + + - name: Setup pnpm + uses: pnpm/action-setup@v5 + with: + version: 10.31.0 + run_install: false + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build and test + run: pnpm build:prod + + - name: Install Playwright browsers (Linux) + if: matrix.os == 'ubuntu-latest' + run: pnpm --filter @serverlessworkflow/playwright exec playwright install --with-deps + + - name: Install Playwright browsers (macOS/Windows) + if: matrix.os != 'ubuntu-latest' + run: pnpm --filter @serverlessworkflow/playwright exec playwright install + + - name: Run Playwright tests + run: pnpm --filter @serverlessworkflow/playwright test + + - name: Upload Playwright Report + if: always() + uses: actions/upload-artifact@v4 + with: + name: playwright-report-${{ matrix.os }} + path: packages/playwright/playwright-report diff --git a/.gitignore b/.gitignore index a9e3937..37255c6 100644 --- a/.gitignore +++ b/.gitignore @@ -175,3 +175,8 @@ vite.config.ts.timestamp-* # Apache RAT .rat-reports + +# playwright test results +test-results/ +playwright-report/ +blob-report/ \ No newline at end of file diff --git a/packages/playwright/README.md b/packages/playwright/README.md new file mode 100644 index 0000000..a98c432 --- /dev/null +++ b/packages/playwright/README.md @@ -0,0 +1,37 @@ + + +# Playwright E2E Setup (Monorepo - pnpm) + +This document explains how to set up and run Playwright end-to-end (E2E) tests for packages inside this monorepo. + +--- + +## Configure Playwright + +- Configure Playwright in playwright.config.ts for the package which you want to write tests for. +- Add an endpoint for that package and make sure it is the same port where the package/app starts. +- Navigate to tests folder and create a file with the package name which you want to write tests for and write all the tests in it. + +## Steps for testing + +- Run the command for testing :- + - pnpm --filter @packageName test + - Eg- pnpm --filter @serverlessworkflow/playwright test + +- For testing it in UI :- + - pnpm --filter @packageName test:ui + - Eg- pnpm --filter @serverlessworkflow/playwright test:ui diff --git a/packages/playwright/package.json b/packages/playwright/package.json new file mode 100644 index 0000000..5f15c37 --- /dev/null +++ b/packages/playwright/package.json @@ -0,0 +1,17 @@ +{ + "name": "@serverlessworkflow/playwright", + "version": "1.0.0", + "description": "", + "keywords": [], + "license": "Apache-2.0", + "author": "", + "scripts": { + "test": "playwright test", + "test:ui": "playwright test --ui" + }, + "devDependencies": { + "@playwright/test": "^1.59.1", + "@types/node": "catalog:" + }, + "packageManager": "pnpm@10.31.0" +} diff --git a/packages/playwright/playwright.config.ts b/packages/playwright/playwright.config.ts new file mode 100644 index 0000000..8a4baae --- /dev/null +++ b/packages/playwright/playwright.config.ts @@ -0,0 +1,35 @@ +/* + * Copyright 2021-Present The Serverless Workflow Specification Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { defineConfig } from "@playwright/test"; + +export default defineConfig({ + testDir: "./tests", + + reporter: [["html", { open: "never" }]], + + use: { + baseURL: "http://localhost:6006", + headless: true, + }, + + webServer: { + command: "pnpm --filter @serverlessworkflow/diagram-editor start", + url: "http://localhost:6006", + reuseExistingServer: !process.env.CI, + timeout: 120 * 1000, + }, +}); diff --git a/packages/playwright/tests/diagram-editor.spec.ts b/packages/playwright/tests/diagram-editor.spec.ts new file mode 100644 index 0000000..7000827 --- /dev/null +++ b/packages/playwright/tests/diagram-editor.spec.ts @@ -0,0 +1,42 @@ +/* + * Copyright 2021-Present The Serverless Workflow Specification Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { test, expect } from "@playwright/test"; + +test("diagram editor renders correctly", async ({ page }) => { + await page.goto("/iframe.html?id=example-diagrameditor--component"); + + // Wait for main container + await expect(page.getByTestId("diagram-container")).toBeVisible(); + + // Check at least one specific node + await expect(page.getByTestId("rf__node-n1")).toBeVisible(); + + // Check total nodes + const nodes = page.locator('[data-testid^="rf__node-"]'); + await expect(nodes).toHaveCount(5); + + // Check total edges + const edges = page.locator('[data-testid^="rf__edge-"]'); + await expect(edges).toHaveCount(5); + + // Verify the diagram rendered at least one node and one edge + const nodesCount = page.locator('[data-testid^="rf__node-"]'); + await expect(await nodesCount.count()).toBeGreaterThan(0); + + const edgesCount = page.locator('[data-testid^="rf__edge-"]'); + await expect(await edgesCount.count()).toBeGreaterThan(0); +}); diff --git a/packages/playwright/tsconfig.json b/packages/playwright/tsconfig.json new file mode 100644 index 0000000..33576e6 --- /dev/null +++ b/packages/playwright/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "types": ["node"], + "baseUrl": ".", + "declaration": true, + "declarationMap": true, + "sourceMap": true + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 56ce466..08323b4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -160,6 +160,15 @@ importers: specifier: 'catalog:' version: 4.1.2(@types/node@25.5.0)(@vitest/ui@4.1.2)(jsdom@25.0.1)(vite@6.4.1(@types/node@25.5.0)(yaml@2.8.3)) + packages/playwright: + devDependencies: + '@playwright/test': + specifier: ^1.59.1 + version: 1.59.1 + '@types/node': + specifier: 'catalog:' + version: 25.5.0 + packages/serverless-workflow-diagram-editor: dependencies: '@serverlessworkflow/i18n': @@ -958,6 +967,11 @@ packages: cpu: [x64] os: [win32] + '@playwright/test@1.59.1': + resolution: {integrity: sha512-PG6q63nQg5c9rIi4/Z5lR5IVF7yU5MqmKaPOe0HSc0O2cX1fPi96sUQu5j7eo4gKCkB2AnNGoWt7y4/Xx3Kcqg==} + engines: {node: '>=18'} + hasBin: true + '@polka/url@1.0.0-next.29': resolution: {integrity: sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww==} @@ -1713,6 +1727,11 @@ packages: resolution: {integrity: sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==} engines: {node: '>= 6'} + fsevents@2.3.2: + resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + fsevents@2.3.3: resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} @@ -2009,6 +2028,16 @@ packages: resolution: {integrity: sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==} engines: {node: '>=12'} + playwright-core@1.59.1: + resolution: {integrity: sha512-HBV/RJg81z5BiiZ9yPzIiClYV/QMsDCKUyogwH9p3MCP6IYjUFu/MActgYAvK0oWyV9NlwM3GLBjADyWgydVyg==} + engines: {node: '>=18'} + hasBin: true + + playwright@1.59.1: + resolution: {integrity: sha512-C8oWjPR3F81yljW9o5OxcWzfh6avkVwDD2VYdwIGqTkl+OGFISgypqzfu7dOe4QNLL2aqcWBmI3PMtLIK233lw==} + engines: {node: '>=18'} + hasBin: true + postcss@8.5.8: resolution: {integrity: sha512-OW/rX8O/jXnm82Ey1k44pObPtdblfiuWnrd8X7GJ7emImCOstunGbXUpp7HdBrFQX6rJzn3sPT397Wp5aCwCHg==} engines: {node: ^10 || ^12 || >=14} @@ -2940,6 +2969,10 @@ snapshots: '@oxlint/binding-win32-x64-msvc@1.58.0': optional: true + '@playwright/test@1.59.1': + dependencies: + playwright: 1.59.1 + '@polka/url@1.0.0-next.29': {} '@rollup/pluginutils@5.3.0(rollup@4.60.1)': @@ -3678,6 +3711,9 @@ snapshots: hasown: 2.0.2 mime-types: 2.1.35 + fsevents@2.3.2: + optional: true + fsevents@2.3.3: optional: true @@ -4001,6 +4037,14 @@ snapshots: picomatch@4.0.4: {} + playwright-core@1.59.1: {} + + playwright@1.59.1: + dependencies: + playwright-core: 1.59.1 + optionalDependencies: + fsevents: 2.3.2 + postcss@8.5.8: dependencies: nanoid: 3.3.11