From 270ebbdb7e63aae21cbc4c90a24bd69f315d31a6 Mon Sep 17 00:00:00 2001 From: Sergio Eduardo Castro Ceballos <72516762+SergioCasCeb@users.noreply.github.com> Date: Fri, 5 Jan 2024 06:30:40 +0100 Subject: [PATCH] Modify the playwright config file to work with the CI pipeline --- .github/workflows/visual-ci-new.yaml | 6 +- packages/web-new/package-lock.json | 92 +++++++++++++++++++++++++++ packages/web-new/package.json | 1 + packages/web-new/playwright.config.js | 38 ++++++++--- 4 files changed, 126 insertions(+), 11 deletions(-) diff --git a/.github/workflows/visual-ci-new.yaml b/.github/workflows/visual-ci-new.yaml index f9b443b43..bb017b706 100644 --- a/.github/workflows/visual-ci-new.yaml +++ b/.github/workflows/visual-ci-new.yaml @@ -16,10 +16,10 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Use Node.js 16 + - name: Use Node.js 18 uses: actions/setup-node@v3 with: - node-version: "16.x" + node-version: "18.x" - name: Use lerna run: npm install -g lerna@6.6.2 @@ -32,5 +32,5 @@ jobs: run: | cd ./packages/web-new npm install - npx playwright install + npx playwright install chromium firefox npm run test diff --git a/packages/web-new/package-lock.json b/packages/web-new/package-lock.json index 8785b8049..367b4630a 100644 --- a/packages/web-new/package-lock.json +++ b/packages/web-new/package-lock.json @@ -35,6 +35,7 @@ "nodemon": "^3.0.1", "sass": "^1.64.0", "sass-loader": "^13.3.2", + "serve-handler": "^6.1.5", "style-loader": "^3.3.3", "webpack": "^5.88.2", "webpack-bundle-analyzer": "^4.9.0", @@ -4130,6 +4131,21 @@ "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", "dev": true }, + "node_modules/fast-url-parser": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/fast-url-parser/-/fast-url-parser-1.1.3.tgz", + "integrity": "sha512-5jOCVXADYNuRkKFzNJ0dCCewsZiYo0dz8QNYljkOpFC6r2U4OBmKtvm/Tsuh4w1YYdDqDb31a8TVhBJ2OJKdqQ==", + "dev": true, + "dependencies": { + "punycode": "^1.3.2" + } + }, + "node_modules/fast-url-parser/node_modules/punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==", + "dev": true + }, "node_modules/fastest-levenshtein": { "version": "1.0.16", "resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.16.tgz", @@ -5906,6 +5922,12 @@ "node": ">=0.10.0" } }, + "node_modules/path-is-inside": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", + "integrity": "sha512-DUWJr3+ULp4zXmol/SZkFf3JGsS9/SIv+Y3Rt93/UjPpDpklB5f1er4O3POIbUuUJ3FXgqte2Q7SrU6zAqwk8w==", + "dev": true + }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -7065,6 +7087,76 @@ "randombytes": "^2.1.0" } }, + "node_modules/serve-handler": { + "version": "6.1.5", + "resolved": "https://registry.npmjs.org/serve-handler/-/serve-handler-6.1.5.tgz", + "integrity": "sha512-ijPFle6Hwe8zfmBxJdE+5fta53fdIY0lHISJvuikXB3VYFafRjMRpOffSPvCYsbKyBA7pvy9oYr/BT1O3EArlg==", + "dev": true, + "dependencies": { + "bytes": "3.0.0", + "content-disposition": "0.5.2", + "fast-url-parser": "1.1.3", + "mime-types": "2.1.18", + "minimatch": "3.1.2", + "path-is-inside": "1.0.2", + "path-to-regexp": "2.2.1", + "range-parser": "1.2.0" + } + }, + "node_modules/serve-handler/node_modules/bytes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", + "integrity": "sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/serve-handler/node_modules/content-disposition": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", + "integrity": "sha512-kRGRZw3bLlFISDBgwTSA1TMBFN6J6GWDeubmDE3AF+3+yXL8hTWv8r5rkLbqYXY4RjPk/EzHnClI3zQf1cFmHA==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/serve-handler/node_modules/mime-db": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz", + "integrity": "sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/serve-handler/node_modules/mime-types": { + "version": "2.1.18", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz", + "integrity": "sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==", + "dev": true, + "dependencies": { + "mime-db": "~1.33.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/serve-handler/node_modules/path-to-regexp": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-2.2.1.tgz", + "integrity": "sha512-gu9bD6Ta5bwGrrU8muHzVOBFFREpp2iRkVfhBJahwJ6p6Xw20SjT0MxLnwkjOibQmGSYhiUnf2FLe7k+jcFmGQ==", + "dev": true + }, + "node_modules/serve-handler/node_modules/range-parser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", + "integrity": "sha512-kA5WQoNVo4t9lNx2kQNFCxKeBl5IbbSNBl1M/tLkw9WCn+hxNBAW5Qh8gdhs63CJnhjJ2zQWFoqPJP2sK1AV5A==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/serve-index": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/serve-index/-/serve-index-1.9.1.tgz", diff --git a/packages/web-new/package.json b/packages/web-new/package.json index a40af23af..d47a7fe88 100644 --- a/packages/web-new/package.json +++ b/packages/web-new/package.json @@ -37,6 +37,7 @@ "nodemon": "^3.0.1", "sass": "^1.64.0", "sass-loader": "^13.3.2", + "serve-handler": "^6.1.5", "style-loader": "^3.3.3", "webpack": "^5.88.2", "webpack-bundle-analyzer": "^4.9.0", diff --git a/packages/web-new/playwright.config.js b/packages/web-new/playwright.config.js index 9e18e04c0..b8286bf99 100644 --- a/packages/web-new/playwright.config.js +++ b/packages/web-new/playwright.config.js @@ -14,8 +14,30 @@ ********************************************************************************/ // @ts-check const { defineConfig, devices } = require('@playwright/test'); +const handler = require("serve-handler"); +const http = require("http"); -// require('dotenv').config(); +const isCI = process.env.CI; +console.log(process.env); +console.log(isCI); + +if (isCI) { + const port = 3000; + const host = "http://localhost"; + const fullHost = host + ":" + port; + + const server = http.createServer((request, response) => { + // You pass two more arguments for config and middleware + // More details here: https://github.com/vercel/serve-handler#options + return handler(request, response); + }); + + /* ################### */ + /* MAIN */ + server.listen(port, () => { + console.log("Running siteTest at " + fullHost); + }); +} module.exports = defineConfig({ testDir: './tests', @@ -24,17 +46,17 @@ module.exports = defineConfig({ /* 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, + forbidOnly: !!isCI, /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, + retries: isCI ? 2 : 0, /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, + workers: isCI ? 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: { /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: 'http://127.0.0.1:5100', + baseURL: isCI ? 'http://localhost:3000' : 'http://127.0.0.1:5100', /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', @@ -66,8 +88,8 @@ module.exports = defineConfig({ /* Run your local dev server before starting the tests */ webServer: { - command: 'npm run serve', - url: 'http://127.0.0.1:5100', - reuseExistingServer: !process.env.CI, + command: isCI ? '' : 'npm run serve', + url: isCI ? 'http://localhost:3000' : 'http://127.0.0.1:5100', + reuseExistingServer: !isCI, }, });