From 81ae72f497e5c4508ffb1f7c56795a1eff977d5e Mon Sep 17 00:00:00 2001
From: Peter
Date: Tue, 24 Oct 2023 16:49:55 +0200
Subject: [PATCH] Added shared playwright config
---
tests/playwright/playwright.react.config.ts | 74 ++------------------
tests/playwright/playwright.shared.config.ts | 63 +++++++++++++++++
tests/playwright/playwright.svelte.config.ts | 74 ++------------------
3 files changed, 72 insertions(+), 139 deletions(-)
create mode 100644 tests/playwright/playwright.shared.config.ts
diff --git a/tests/playwright/playwright.react.config.ts b/tests/playwright/playwright.react.config.ts
index fc8009ed..c8fa98ef 100644
--- a/tests/playwright/playwright.react.config.ts
+++ b/tests/playwright/playwright.react.config.ts
@@ -1,77 +1,13 @@
-import { defineConfig, devices } from '@playwright/test';
+import { defineConfig } from '@playwright/test';
+import { sharedConfigWithPort } from './playwright.shared.config';
-/**
- * Read environment variables from file.
- * https://github.com/motdotla/dotenv
- */
-// require('dotenv').config();
+const port = 3000;
-/**
- * See https://playwright.dev/docs/test-configuration.
- */
export default defineConfig({
- testDir: './e2e',
- /* 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: {
- /* Base URL to use in actions like `await page.goto('/')`. */
- baseURL: 'http://127.0.0.1:3000',
-
- /* 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'] },
- },
-
- {
- name: 'firefox',
- use: { ...devices['Desktop Firefox'] },
- },
-
- {
- name: 'webkit',
- use: { ...devices['Desktop Safari'] },
- },
-
- /* Test against mobile viewports. */
- // {
- // name: 'Mobile Chrome',
- // use: { ...devices['Pixel 5'] },
- // },
- // {
- // name: 'Mobile Safari',
- // use: { ...devices['iPhone 12'] },
- // },
-
- /* Test against branded browsers. */
- // {
- // name: 'Microsoft Edge',
- // use: { ...devices['Desktop Edge'], channel: 'msedge' },
- // },
- // {
- // name: 'Google Chrome',
- // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
- // },
- ],
-
- /* Run your local dev server before starting the tests */
+ ...sharedConfigWithPort(port),
webServer: {
command: 'cd ../../examples/react && pnpm run dev',
- url: 'http://127.0.0.1:3000',
+ port,
reuseExistingServer: !process.env.CI,
},
});
diff --git a/tests/playwright/playwright.shared.config.ts b/tests/playwright/playwright.shared.config.ts
new file mode 100644
index 00000000..828317a7
--- /dev/null
+++ b/tests/playwright/playwright.shared.config.ts
@@ -0,0 +1,63 @@
+import { PlaywrightTestConfig, devices } from '@playwright/test';
+
+export function sharedConfigWithPort(port: number): PlaywrightTestConfig {
+ return {
+ testDir: './e2e',
+ /* 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: {
+ /* Base URL to use in actions like `await page.goto('/')`. */
+ baseURL: `http://localhost:${port}/`,
+
+ /* 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'] },
+ },
+
+ {
+ name: 'firefox',
+ use: { ...devices['Desktop Firefox'] },
+ },
+
+ {
+ name: 'webkit',
+ use: { ...devices['Desktop Safari'] },
+ },
+
+ /* Test against mobile viewports. */
+ // {
+ // name: 'Mobile Chrome',
+ // use: { ...devices['Pixel 5'] },
+ // },
+ // {
+ // name: 'Mobile Safari',
+ // use: { ...devices['iPhone 12'] },
+ // },
+
+ /* Test against branded browsers. */
+ // {
+ // name: 'Microsoft Edge',
+ // use: { ...devices['Desktop Edge'], channel: 'msedge' },
+ // },
+ // {
+ // name: 'Google Chrome',
+ // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
+ // },
+ ],
+ };
+}
diff --git a/tests/playwright/playwright.svelte.config.ts b/tests/playwright/playwright.svelte.config.ts
index e1845f20..f92bd3dc 100644
--- a/tests/playwright/playwright.svelte.config.ts
+++ b/tests/playwright/playwright.svelte.config.ts
@@ -1,79 +1,13 @@
import { defineConfig, devices } from '@playwright/test';
+import { sharedConfigWithPort } from './playwright.shared.config';
-/**
- * Read environment variables from file.
- * https://github.com/motdotla/dotenv
- */
-// require('dotenv').config();
+const port = 5173;
-/**
- * See https://playwright.dev/docs/test-configuration.
- */
export default defineConfig({
- testDir: './e2e',
- /* 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: {
- /* Base URL to use in actions like `await page.goto('/')`. */
- 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'] },
- },
-
- {
- name: 'firefox',
- use: { ...devices['Desktop Firefox'] },
- },
-
- {
- name: 'webkit',
- use: { ...devices['Desktop Safari'] },
- },
-
- /* Test against mobile viewports. */
- // {
- // name: 'Mobile Chrome',
- // use: { ...devices['Pixel 5'] },
- // },
- // {
- // name: 'Mobile Safari',
- // use: { ...devices['iPhone 12'] },
- // },
-
- /* Test against branded browsers. */
- // {
- // name: 'Microsoft Edge',
- // use: { ...devices['Desktop Edge'], channel: 'msedge' },
- // },
- // {
- // name: 'Google Chrome',
- // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
- // },
- ],
-
- /* Run your local dev server before starting the tests */
+ ...sharedConfigWithPort(port),
webServer: {
command: 'cd ../../examples/svelte && pnpm run dev',
- // for some reason you need to use port otherwise it loads forever
- // url: 'http://127.0.0.1:5173',
- port: 5173,
+ port: port,
reuseExistingServer: !process.env.CI,
},
});