Skip to content

Commit

Permalink
GLSP-1154 Add actions workflow for playwright testing
Browse files Browse the repository at this point in the history
- 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 eclipse-glsp/glsp#1154
  • Loading branch information
tortmayr committed Mar 2, 2024
1 parent 3e54bf5 commit dbe7efd
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 2 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/standalone-playwrigh-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Run GLSP Client Playwright Tests (Standalone)

on:
push:
branches:
- testci
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/
14 changes: 14 additions & 0 deletions examples/workflow-test/configs/project.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import { getEnv } from './utils';
const projectDevices = devices['Desktop Chrome'];

export function createStandaloneProject(): Project<PlaywrightTestOptions & GLSPPlaywrightOptions, PlaywrightWorkerArgs>[] {
if (!shouldCreateProject('standalone')) {
return [];
}
const url = getEnv('STANDALONE_URL');

if (url === undefined) {
Expand All @@ -52,6 +55,9 @@ export function createStandaloneProject(): Project<PlaywrightTestOptions & GLSPP
}

export function createTheiaProject(): Project<PlaywrightTestOptions & GLSPPlaywrightOptions, PlaywrightWorkerOptions>[] {
if (!shouldCreateProject('theia')) {
return [];
}
const url = getEnv('THEIA_URL');

if (url === undefined) {
Expand Down Expand Up @@ -81,6 +87,9 @@ export function createTheiaProject(): Project<PlaywrightTestOptions & GLSPPlaywr
}

export function createVSCodeProject(): Project<PlaywrightTestOptions & GLSPPlaywrightOptions, PlaywrightWorkerOptions>[] {
if (!shouldCreateProject('vscode')) {
return [];
}
const vsixId = getEnv('VSCODE_VSIX_ID');
const vsixPath = getEnv('VSCODE_VSIX_PATH');

Expand Down Expand Up @@ -116,3 +125,8 @@ export function createVSCodeProject(): Project<PlaywrightTestOptions & GLSPPlayw
}
];
}

export function shouldCreateProject(name: string): boolean {
const projectName = getEnv('PROJECT', false);
return projectName ? projectName === name : true;
}
6 changes: 6 additions & 0 deletions examples/workflow-test/configs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ export function getEnv(parameter: string, log: boolean = true): string | undefin
}
return val;
}

export function getArgValue(argKey: string, log: boolean = true): string | undefined {
const normalizedKey = `--${argKey.replace('--', '').replace('=', '')}=`;
const arg = process.argv.find(a => a.startsWith(normalizedKey));
return arg?.substring(normalizedKey.length);
}
2 changes: 1 addition & 1 deletion examples/workflow-test/configs/webserver.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
];
Expand Down
1 change: 1 addition & 0 deletions examples/workflow-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 12 additions & 1 deletion examples/workflow-test/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -36,7 +46,8 @@ const config: PlaywrightTestConfig<GLSPPlaywrightOptions> = {
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'
Expand Down
53 changes: 53 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -444,6 +460,19 @@
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.52.0.tgz#78fe5f117840f69dc4a353adf9b9cd926353378c"
integrity sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA==

"@estruyf/[email protected]":
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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit dbe7efd

Please sign in to comment.