From 78b39c4fa914d1f1817f5a4e287eca7aa441715a Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 3 Jan 2025 10:41:19 -0400 Subject: [PATCH] Setup Playwright UI tests (#61) Signed-off-by: Juan Cruz Viotti --- .gitignore | 5 ++ Makefile | 10 +++- test/ui/.gitignore | 5 ++ test/ui/explorer.spec.js | 6 +++ test/ui/package-lock.json | 96 ++++++++++++++++++++++++++++++++++++ test/ui/package.json | 9 ++++ test/ui/playwright.config.js | 16 ++++++ 7 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 test/ui/.gitignore create mode 100644 test/ui/explorer.spec.js create mode 100644 test/ui/package-lock.json create mode 100644 test/ui/package.json create mode 100644 test/ui/playwright.config.js diff --git a/.gitignore b/.gitignore index 52425de..9d0e8ff 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,8 @@ _deps /build Brewfile.lock.json .DS_Store +test/ui/node_modules/ +test/ui/test-results/ +test/ui/playwright-report/ +test/ui/blob-report/ +test/ui/playwright/.cache/ diff --git a/Makefile b/Makefile index f67240e..2e97ca2 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,8 @@ HURL ?= hurl JSONSCHEMA ?= jsonschema DOCKER ?= docker SHELLCHECK ?= shellcheck +NPX ?= npx +NPM ?= npm # Options INDEX ?= ON @@ -76,6 +78,12 @@ test-e2e: $(HURL) --test \ --variable base=$(shell jq --raw-output '.url' < $(SANDBOX)/configuration.json) \ test/e2e/common/*.hurl test/e2e/$(EDITION)/*.hurl +ifeq ($(ENTERPRISE), ON) + $(NPM) --prefix test/ui install + $(NPX) --prefix test/ui playwright install --with-deps + env BASE_URL=$(shell jq --raw-output '.url' < $(SANDBOX)/configuration.json) \ + $(NPX) --prefix test/ui playwright test --config test/ui/playwright.config.js +endif .PHONY: sandbox sandbox: compile @@ -90,5 +98,5 @@ docker: .PHONY: clean clean: - $(CMAKE) -E rm -R -f build + $(CMAKE) -E rm -R -f build test/ui/node_modules test/ui/test-results $(DOCKER) system prune --force --all --volumes || true diff --git a/test/ui/.gitignore b/test/ui/.gitignore new file mode 100644 index 0000000..68c5d18 --- /dev/null +++ b/test/ui/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/test/ui/explorer.spec.js b/test/ui/explorer.spec.js new file mode 100644 index 0000000..d7b200e --- /dev/null +++ b/test/ui/explorer.spec.js @@ -0,0 +1,6 @@ +const { test, expect } = require('@playwright/test'); + +test('has title', async ({ page }) => { + await page.goto('/'); + await expect(page).toHaveTitle(/Sourcemeta/); +}); diff --git a/test/ui/package-lock.json b/test/ui/package-lock.json new file mode 100644 index 0000000..a4b4ef6 --- /dev/null +++ b/test/ui/package-lock.json @@ -0,0 +1,96 @@ +{ + "name": "@sourcemeta/registry", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@sourcemeta/registry", + "version": "0.0.0", + "devDependencies": { + "@playwright/test": "^1.49.1", + "@types/node": "^22.10.5" + } + }, + "node_modules/@playwright/test": { + "version": "1.49.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.49.1.tgz", + "integrity": "sha512-Ky+BVzPz8pL6PQxHqNRW1k3mIyv933LML7HktS8uik0bUXNCdPhoS/kLihiO1tMf/egaJb4IutXd7UywvXEW+g==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.49.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@types/node": { + "version": "22.10.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.5.tgz", + "integrity": "sha512-F8Q+SeGimwOo86fiovQh8qiXfFEh2/ocYv7tU5pJ3EXMSSxk1Joj5wefpFK2fHTf/N6HKGSxIDBT9f3gCxXPkQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.20.0" + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/playwright": { + "version": "1.49.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.49.1.tgz", + "integrity": "sha512-VYL8zLoNTBxVOrJBbDuRgDWa3i+mfQgDTrL8Ah9QXZ7ax4Dsj0MSq5bYgytRnDVVe+njoKnfsYkH3HzqVj5UZA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.49.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.49.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.49.1.tgz", + "integrity": "sha512-BzmpVcs4kE2CH15rWfzpjzVGhWERJfmnXmniSyKeRZUs9Ws65m+RGIi7mjJK/euCegfn3i7jvqWeWyHe9y3Vgg==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/undici-types": { + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", + "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/test/ui/package.json b/test/ui/package.json new file mode 100644 index 0000000..b79b73e --- /dev/null +++ b/test/ui/package.json @@ -0,0 +1,9 @@ +{ + "name": "@sourcemeta/registry", + "private": true, + "version": "0.0.0", + "devDependencies": { + "@playwright/test": "^1.49.1", + "@types/node": "^22.10.5" + } +} diff --git a/test/ui/playwright.config.js b/test/ui/playwright.config.js new file mode 100644 index 0000000..3152508 --- /dev/null +++ b/test/ui/playwright.config.js @@ -0,0 +1,16 @@ +const { defineConfig, devices } = require('@playwright/test'); + +// See https://playwright.dev/docs/test-configuration +module.exports = defineConfig({ + testDir: '.', + fullyParallel: true, + forbidOnly: !!process.env.CI, + retries: process.env.CI ? 2 : 0, + workers: process.env.CI ? 1 : undefined, + reporter: 'list', + use: { + baseURL: process.env.BASE_URL, + trace: 'on-first-retry' + } +}); +