From 363461d35fedf734c7f9a01a03312c362163ed90 Mon Sep 17 00:00:00 2001 From: Tobias Ortmayr Date: Thu, 22 Feb 2024 17:51:10 +0100 Subject: [PATCH] GLSP-1154 Add actions workflow for playwright testing - Add workflow for executing playwright tests for a dedicated GLSP component/project - Adapt playwright config to also report via `github-actions-repoter` when executed in a CI env - Adapt playwright config to consider the --project argument and only create projects relevant for the test execution. This avoids the need for a fully configured env if only running a certain test set. Part of https://github.com/eclipse-glsp/glsp/issues/1154 --- .../workflows/standalone-playwrigh-tests.yml | 56 +++++++++++++++++++ .../workflow-test/configs/project.config.ts | 14 +++++ examples/workflow-test/configs/utils.ts | 6 ++ .../workflow-test/configs/webserver.config.ts | 2 +- examples/workflow-test/package.json | 1 + examples/workflow-test/playwright.config.ts | 13 ++++- yarn.lock | 53 ++++++++++++++++++ 7 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/standalone-playwrigh-tests.yml diff --git a/.github/workflows/standalone-playwrigh-tests.yml b/.github/workflows/standalone-playwrigh-tests.yml new file mode 100644 index 0000000..b5135bf --- /dev/null +++ b/.github/workflows/standalone-playwrigh-tests.yml @@ -0,0 +1,56 @@ +name: Run GLSP Client Playwright Tests (Standalone) + +on: + workflow_dispatch: + inputs: + glspClientRef: + description: 'GLSP Client branch/commit/tag to checkout' + required: true + default: 'master' # Default branch if none is provided + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout playwright repository + uses: actions/checkout@v4 + with: + repository: 'eclipse-glsp/glsp-playwright' + path: 'glsp-playwright' + + - name: Checkout glsp-client at specified commit + uses: actions/checkout@v4 + with: + repository: 'eclipse-glsp/glsp-client' + ref: ${{ github.event.inputs.glspClientBranch }} + path: 'glsp-client' + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' # Specify the Node.js version you need + + - name: Start the standalone example + run: | + cd glsp-client + yarn + nohup yarn start:exampleServer > server.log 2>&1 & + while ! nc -z localhost 8081; do + sleep 1 # wait for 1 second before check again + done + + - name: Run Playwright tests + run: | + cd glsp-playwright + yarn + yarn test:standalone + env: + STANDALONE_URL: 'file://${{ github.workspace }}/glsp-client/examples/workflow-standalone/app/diagram.html' + GLSP_SERVER_PORT: '8081' + GLSP_SERVER_PLAYWRIGHT_MANAGED: false + + - name: Upload Playwright report + uses: actions/upload-artifact@v4 + with: + name: playwright-report + path: glsp-playwright/examples/workflow-test/playwright-report/ diff --git a/examples/workflow-test/configs/project.config.ts b/examples/workflow-test/configs/project.config.ts index 87760ad..99ee3ff 100644 --- a/examples/workflow-test/configs/project.config.ts +++ b/examples/workflow-test/configs/project.config.ts @@ -27,6 +27,9 @@ import { getEnv } from './utils'; const projectDevices = devices['Desktop Chrome']; export function createStandaloneProject(): Project[] { + if (!shouldCreateProject('standalone')) { + return []; + } const url = getEnv('STANDALONE_URL'); if (url === undefined) { @@ -52,6 +55,9 @@ export function createStandaloneProject(): Project[] { + if (!shouldCreateProject('theia')) { + return []; + } const url = getEnv('THEIA_URL'); if (url === undefined) { @@ -81,6 +87,9 @@ export function createTheiaProject(): Project[] { + if (!shouldCreateProject('vscode')) { + return []; + } const vsixId = getEnv('VSCODE_VSIX_ID'); const vsixPath = getEnv('VSCODE_VSIX_PATH'); @@ -116,3 +125,8 @@ export function createVSCodeProject(): Project a.startsWith(normalizedKey)); + return arg?.substring(normalizedKey.length); +} diff --git a/examples/workflow-test/configs/webserver.config.ts b/examples/workflow-test/configs/webserver.config.ts index 6075bec..2e874b5 100644 --- a/examples/workflow-test/configs/webserver.config.ts +++ b/examples/workflow-test/configs/webserver.config.ts @@ -46,7 +46,7 @@ export function createWebserver(): PlaywrightTestConfig['webServer'] { { command: `yarn start:server -w -p ${+port}`, port: +port, - reuseExistingServer: !process.env.CI, + reuseExistingServer: true, stdout: 'ignore' } ]; diff --git a/examples/workflow-test/package.json b/examples/workflow-test/package.json index 3cea89a..243b6d6 100644 --- a/examples/workflow-test/package.json +++ b/examples/workflow-test/package.json @@ -47,6 +47,7 @@ "devDependencies": { "@eclipse-glsp-examples/workflow-server-bundled": "~2.0.1", "@eclipse-glsp/glsp-playwright": "~2.0.0", + "@estruyf/github-actions-reporter": "1.5.0", "@playwright/test": "^1.40.1", "dotenv": "^16.0.3", "ts-dedent": "^2.2.0", diff --git a/examples/workflow-test/playwright.config.ts b/examples/workflow-test/playwright.config.ts index 2791d40..7b7d5bc 100644 --- a/examples/workflow-test/playwright.config.ts +++ b/examples/workflow-test/playwright.config.ts @@ -19,10 +19,20 @@ import type { GLSPPlaywrightOptions } from '@eclipse-glsp/glsp-playwright'; import type { PlaywrightTestConfig } from '@playwright/test'; import * as dotenv from 'dotenv'; import { createStandaloneProject, createTheiaProject, createVSCodeProject } from './configs/project.config'; +import { getArgValue } from './configs/utils'; import { createWebserver, hasRunningServer } from './configs/webserver.config'; dotenv.config(); +// Project restrictions can be set via environment variables or CLI arguments +// CLI arguments take precedence over environment variables +const project = getArgValue('project', false); +if (project) { + // If a project scope is provided via CLI arg, we set it as an environment variable + // so that worker processes can access it as well + process.env.PROJECT = project; +} + /** * See https://playwright.dev/docs/test-configuration. */ @@ -36,7 +46,8 @@ const config: PlaywrightTestConfig = { forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, workers: process.env.CI ? 1 : undefined, - reporter: [['html', { open: 'never' }]], + + reporter: process.env.CI ? [['html', { open: 'never' }], ['@estruyf/github-actions-reporter']] : [['html', { open: 'never' }]], use: { actionTimeout: 0, trace: 'on-first-retry' diff --git a/yarn.lock b/yarn.lock index 062a4de..59a62a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7,6 +7,22 @@ resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf" integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA== +"@actions/core@^1.10.0": + version "1.10.1" + resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.10.1.tgz#61108e7ac40acae95ee36da074fa5850ca4ced8a" + integrity sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g== + dependencies: + "@actions/http-client" "^2.0.1" + uuid "^8.3.2" + +"@actions/http-client@^2.0.1": + version "2.2.0" + resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-2.2.0.tgz#f8239f375be6185fcd07765efdcf0031ad5df1a0" + integrity sha512-q+epW0trjVUUHboliPb4UF9g2msf+w61b32tAkFEwL/IwP0DQWgbCMM0Hbe3e3WXSKz5VcUXbzJQgy8Hkra/Lg== + dependencies: + tunnel "^0.0.6" + undici "^5.25.4" + "@ampproject/remapping@^2.2.0": version "2.2.1" resolved "https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.2.1.tgz#99e8e11851128b8702cd57c33684f1d0f260b630" @@ -444,6 +460,19 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.52.0.tgz#78fe5f117840f69dc4a353adf9b9cd926353378c" integrity sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA== +"@estruyf/github-actions-reporter@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@estruyf/github-actions-reporter/-/github-actions-reporter-1.5.0.tgz#03f09537e46144ee2d710ced4f626bcdb808fcd3" + integrity sha512-jCSJK8QGDMnQSdTRlmIIqTrVs5vanp2djyiH86ulZ9WUiiFbmm3ua3OLTj1fW2uuyd3MYMPyIlUoJ8TTM1ggTA== + dependencies: + "@actions/core" "^1.10.0" + ansi-to-html "^0.7.2" + +"@fastify/busboy@^2.0.0": + version "2.1.0" + resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.0.tgz#0709e9f4cb252351c609c6e6d8d6779a8d25edff" + integrity sha512-+KpH+QxZU7O4675t3mnkQKcZZg56u+K/Ct2K+N2AZYNVK8kyeo/bI18tI8aPm3tvNNRyTWfj6s5tnGNlcbQRsA== + "@humanwhocodes/config-array@^0.11.13": version "0.11.13" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.13.tgz#075dc9684f40a531d9b26b0822153c1e832ee297" @@ -1347,6 +1376,13 @@ ansi-styles@^6.1.0: resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.2.1.tgz#0e62320cf99c21afff3b3012192546aacbfb05c5" integrity sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug== +ansi-to-html@^0.7.2: + version "0.7.2" + resolved "https://registry.yarnpkg.com/ansi-to-html/-/ansi-to-html-0.7.2.tgz#a92c149e4184b571eb29a0135ca001a8e2d710cb" + integrity sha512-v6MqmEpNlxF+POuyhKkidusCHWWkaLcGRURzivcU3I9tv7k4JVhFcnukrM5Rlk2rUywdZuzYAZ+kbZqWCnfN3g== + dependencies: + entities "^2.2.0" + anymatch@~3.1.2: version "3.1.3" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e" @@ -2342,6 +2378,11 @@ enquirer@~2.3.6: dependencies: ansi-colors "^4.1.1" +entities@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55" + integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A== + env-paths@^2.2.0: version "2.2.1" resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-2.2.1.tgz#420399d416ce1fbe9bc0a07c62fa68d67fd0f8f2" @@ -6394,6 +6435,11 @@ tuf-js@^1.1.7: debug "^4.3.4" make-fetch-happen "^11.1.1" +tunnel@^0.0.6: + version "0.0.6" + resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c" + integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg== + type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1" @@ -6507,6 +6553,13 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" +undici@^5.25.4: + version "5.28.3" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.3.tgz#a731e0eff2c3fcfd41c1169a869062be222d1e5b" + integrity sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA== + dependencies: + "@fastify/busboy" "^2.0.0" + unique-filename@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/unique-filename/-/unique-filename-3.0.0.tgz#48ba7a5a16849f5080d26c760c86cf5cf05770ea"