From 1c74de1cafdadd83f02162914dc1e22a1d4b6a5a Mon Sep 17 00:00:00 2001 From: Reguel Wermelinger Date: Wed, 10 Jan 2024 16:03:35 +0100 Subject: [PATCH 1/3] help nvm to auto-select our node version --- .nvmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..3c03207 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +18 From 1b97f21113a6d88122a5087cea06a5f93c1d6328 Mon Sep 17 00:00:00 2001 From: Reguel Wermelinger Date: Wed, 10 Jan 2024 16:26:59 +0100 Subject: [PATCH 2/3] simple test that the swagger-ui is rendered --- .github/workflows/playwright.yml | 24 ++++++ .gitignore | 4 + package-lock.json | 125 +++++++++++++++++++++++++++++++ package.json | 5 +- playwright.config.ts | 47 ++++++++++++ tests/swagger.spec.ts | 8 ++ 6 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/playwright.yml create mode 100644 playwright.config.ts create mode 100644 tests/swagger.spec.ts diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 0000000..dbf3a62 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,24 @@ +name: Playwright Tests +on: + push: +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Install dependencies + run: npm ci + - name: Install Playwright Browsers + run: npx playwright install --with-deps chromium + - name: Run Playwright tests + run: npx playwright test + - uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/.gitignore b/.gitignore index b1b96aa..d72e0c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ dist/ node_modules/ target/ +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/package-lock.json b/package-lock.json index 405026b..fdfb950 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,8 @@ "vite": "^5.0.11" }, "devDependencies": { + "@playwright/test": "^1.40.1", + "@types/node": "^20.10.8", "prettier": "^3.1.1" }, "engines": { @@ -384,6 +386,21 @@ "node": ">=14" } }, + "node_modules/@playwright/test": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.40.1.tgz", + "integrity": "sha512-EaaawMTOeEItCRvfmkI9v6rBkF1svM8wjl/YPRrg2N2Wmp+4qJYkWtJsbew1szfKKDm6fPLy4YAanBhIlf9dWw==", + "dev": true, + "dependencies": { + "playwright": "1.40.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/@rollup/rollup-android-arm-eabi": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.4.1.tgz", @@ -965,6 +982,15 @@ "hoist-non-react-statics": "^3.3.0" } }, + "node_modules/@types/node": { + "version": "20.10.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.8.tgz", + "integrity": "sha512-f8nQs3cLxbAFc00vEU59yf9UyGUftkPaLGfvbVOIDdx2i1b8epBqj2aNGyP19fiyXWvlmZ7qC1XLjAzw/OKIeA==", + "devOptional": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/@types/prop-types": { "version": "15.7.9", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.9.tgz", @@ -2234,6 +2260,50 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/playwright": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.1.tgz", + "integrity": "sha512-2eHI7IioIpQ0bS1Ovg/HszsN/XKNwEG1kbzSDDmADpclKc7CyqkHw7Mg2JCz/bbCxg25QUPcjksoMW7JcIFQmw==", + "dev": true, + "dependencies": { + "playwright-core": "1.40.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=16" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.1.tgz", + "integrity": "sha512-+hkOycxPiV534c4HhpfX6yrlawqVUzITRKwHAmYfmsVreltEl6fAZJ3DPfLMOODw0H3s1Itd6MDCWmP1fl/QvQ==", + "dev": true, + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/playwright/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, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/postcss": { "version": "8.4.32", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.32.tgz", @@ -3163,6 +3233,12 @@ "node": ">=14.0" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "devOptional": true + }, "node_modules/universalify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", @@ -3486,6 +3562,15 @@ "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.0.tgz", "integrity": "sha512-+KpH+QxZU7O4675t3mnkQKcZZg56u+K/Ct2K+N2AZYNVK8kyeo/bI18tI8aPm3tvNNRyTWfj6s5tnGNlcbQRsA==" }, + "@playwright/test": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.40.1.tgz", + "integrity": "sha512-EaaawMTOeEItCRvfmkI9v6rBkF1svM8wjl/YPRrg2N2Wmp+4qJYkWtJsbew1szfKKDm6fPLy4YAanBhIlf9dWw==", + "dev": true, + "requires": { + "playwright": "1.40.1" + } + }, "@rollup/rollup-android-arm-eabi": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.4.1.tgz", @@ -3989,6 +4074,15 @@ "hoist-non-react-statics": "^3.3.0" } }, + "@types/node": { + "version": "20.10.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.8.tgz", + "integrity": "sha512-f8nQs3cLxbAFc00vEU59yf9UyGUftkPaLGfvbVOIDdx2i1b8epBqj2aNGyP19fiyXWvlmZ7qC1XLjAzw/OKIeA==", + "devOptional": true, + "requires": { + "undici-types": "~5.26.4" + } + }, "@types/prop-types": { "version": "15.7.9", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.9.tgz", @@ -4880,6 +4974,31 @@ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" }, + "playwright": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.1.tgz", + "integrity": "sha512-2eHI7IioIpQ0bS1Ovg/HszsN/XKNwEG1kbzSDDmADpclKc7CyqkHw7Mg2JCz/bbCxg25QUPcjksoMW7JcIFQmw==", + "dev": true, + "requires": { + "fsevents": "2.3.2", + "playwright-core": "1.40.1" + }, + "dependencies": { + "fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "optional": true + } + } + }, + "playwright-core": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.1.tgz", + "integrity": "sha512-+hkOycxPiV534c4HhpfX6yrlawqVUzITRKwHAmYfmsVreltEl6fAZJ3DPfLMOODw0H3s1Itd6MDCWmP1fl/QvQ==", + "dev": true + }, "postcss": { "version": "8.4.32", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.32.tgz", @@ -5548,6 +5667,12 @@ "@fastify/busboy": "^2.0.0" } }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "devOptional": true + }, "universalify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", diff --git a/package.json b/package.json index 59b8aad..cc9f5b6 100644 --- a/package.json +++ b/package.json @@ -8,13 +8,16 @@ "type": "module", "scripts": { "start": "vite", - "build": "vite build" + "build": "vite build", + "test": "npx playwright test" }, "dependencies": { "swagger-ui": "^5.10.5", "vite": "^5.0.11" }, "devDependencies": { + "@playwright/test": "^1.40.1", + "@types/node": "^20.10.8", "prettier": "^3.1.1" } } \ No newline at end of file diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..214f9b5 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,47 @@ +import { defineConfig, devices } from '@playwright/test'; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir: './tests', + /* 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: { + baseURL: 'http://localhost:5173', + /* 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'] }, + }, + ], + + /* Run your local dev server before starting the tests */ + webServer: { + command: 'npm run start', + url: 'http://localhost:5173', + stdout: 'pipe', + stderr: 'pipe', + reuseExistingServer: !process.env.CI, + }, +}); diff --git a/tests/swagger.spec.ts b/tests/swagger.spec.ts new file mode 100644 index 0000000..2a85516 --- /dev/null +++ b/tests/swagger.spec.ts @@ -0,0 +1,8 @@ +import { test, expect } from '@playwright/test'; + +test('swagger ui renderer', async ({ page }) => { + await page.goto('/'); + + await expect(page).toHaveTitle(/API Browser/); + await expect(page.getByText('Authorize')).toBeVisible(); +}); From 33bfe740f4b41197e374b8a1ca46c692a23f079c Mon Sep 17 00:00:00 2001 From: Reguel Wermelinger Date: Thu, 11 Jan 2024 09:11:48 +0100 Subject: [PATCH 3/3] test --- .github/workflows/playwright.yml | 24 ------------------------ .gitignore | 3 --- build/Dockerfile | 8 +++++++- build/Jenkinsfile | 12 ++++++++++++ playwright.config.ts | 15 --------------- 5 files changed, 19 insertions(+), 43 deletions(-) delete mode 100644 .github/workflows/playwright.yml diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml deleted file mode 100644 index dbf3a62..0000000 --- a/.github/workflows/playwright.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Playwright Tests -on: - push: -jobs: - test: - timeout-minutes: 60 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - name: Install dependencies - run: npm ci - - name: Install Playwright Browsers - run: npx playwright install --with-deps chromium - - name: Run Playwright tests - run: npx playwright test - - uses: actions/upload-artifact@v3 - if: always() - with: - name: playwright-report - path: playwright-report/ - retention-days: 30 diff --git a/.gitignore b/.gitignore index d72e0c8..5d33c51 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ dist/ node_modules/ target/ -/test-results/ /playwright-report/ -/blob-report/ -/playwright/.cache/ diff --git a/build/Dockerfile b/build/Dockerfile index 128c63b..f8be148 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,3 +1,9 @@ -FROM node:18.17.1-bookworm +FROM mcr.microsoft.com/playwright:v1.40.1-jammy + +RUN apt-get update &&\ + apt-get install software-properties-common -y &&\ + apt-add-repository universe -y &&\ + apt-get update &&\ + apt-get install openjdk-17-jdk maven -y USER node diff --git a/build/Jenkinsfile b/build/Jenkinsfile index 80abc36..ed50638 100644 --- a/build/Jenkinsfile +++ b/build/Jenkinsfile @@ -23,6 +23,18 @@ pipeline { } } } + stage('NPM:test') { + steps { + script { + catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') { + docker.build('node', '-f build/Dockerfile .').inside { + sh 'npm run test' + } + } + archiveArtifacts artifacts: 'playwright-report/**', allowEmptyArchive: false + } + } + } stage('Deploy') { when { expression { isReleaseOrMasterBranch() && currentBuild.changeSets.size() > 0 } diff --git a/playwright.config.ts b/playwright.config.ts index 214f9b5..bd588f4 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,34 +1,20 @@ import { defineConfig, devices } from '@playwright/test'; -/** - * Read environment variables from file. - * https://github.com/motdotla/dotenv - */ -// require('dotenv').config(); - /** * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ testDir: './tests', - /* 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: { baseURL: 'http://localhost:5173', - /* 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', @@ -36,7 +22,6 @@ export default defineConfig({ }, ], - /* Run your local dev server before starting the tests */ webServer: { command: 'npm run start', url: 'http://localhost:5173',