From b50d3e861ba451d335262c4eecf61760f2209838 Mon Sep 17 00:00:00 2001 From: developomp Date: Sat, 29 Jul 2023 10:57:53 +0900 Subject: [PATCH] refactor: create sharable playwright config --- apps/blog/package.json | 1 + apps/blog/playwright.config.ts | 66 ++----------------------- apps/main/package.json | 1 + apps/main/playwright.config.ts | 66 ++----------------------- apps/portfolio/package.json | 1 + apps/portfolio/playwright.config.ts | 66 ++----------------------- packages/playwright-config/index.ts | 66 +++++++++++++++++++++++++ packages/playwright-config/package.json | 8 +++ pnpm-lock.yaml | 15 ++++++ 9 files changed, 104 insertions(+), 186 deletions(-) create mode 100644 packages/playwright-config/index.ts create mode 100644 packages/playwright-config/package.json diff --git a/apps/blog/package.json b/apps/blog/package.json index afea5c9..f038779 100644 --- a/apps/blog/package.json +++ b/apps/blog/package.json @@ -13,6 +13,7 @@ "devDependencies": { "@developomp-site/content": "workspace:*", "@developomp-site/eslint-config": "workspace:*", + "@developomp-site/playwright-config": "workspace:*", "@developomp-site/prettier-config": "workspace:*", "@developomp-site/tailwind-config": "workspace:*", "@fontsource/noto-sans-kr": "^5.0.5", diff --git a/apps/blog/playwright.config.ts b/apps/blog/playwright.config.ts index ca0f378..b43422a 100644 --- a/apps/blog/playwright.config.ts +++ b/apps/blog/playwright.config.ts @@ -1,63 +1,5 @@ -import { devices, PlaywrightTestConfig } from "@playwright/test" +import { createConfig } from "@developomp-site/playwright-config" -const baseURL = "http://localhost:3000" - -// Reference: https://playwright.dev/docs/test-configuration -const config: PlaywrightTestConfig = { - // Timeout per test - timeout: 30 * 1000, - - // Test directory - testDir: "e2e", - - // Artifacts folder where screenshots, videos, and traces are stored. - outputDir: "test-results/", - - // Run your local dev server before starting the tests: - // https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests - webServer: { - command: "pnpm serve", - url: baseURL, - timeout: 120 * 1000, - // eslint-disable-next-line turbo/no-undeclared-env-vars - reuseExistingServer: !process.env.CI, - }, - - use: { - // Use baseURL so to make navigations relative. - // More information: https://playwright.dev/docs/api/class-testoptions#test-options-base-url - baseURL, - - // Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc. - // More information: https://playwright.dev/docs/trace-viewer - trace: "retry-with-trace", - - // All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context - // contextOptions: { - // ignoreHTTPSErrors: true, - // }, - }, - - projects: [ - { - name: "Desktop Chrome", - use: { - ...devices["Desktop Chrome"], - }, - }, - { - name: "Desktop Firefox", - use: { - ...devices["Desktop Firefox"], - }, - }, - { - name: "Mobile Chrome", - use: { - ...devices["Pixel 5"], - }, - }, - ], -} - -export default config +export default createConfig({ + port: 3000, +}) diff --git a/apps/main/package.json b/apps/main/package.json index e75aea4..5f8f1fa 100644 --- a/apps/main/package.json +++ b/apps/main/package.json @@ -15,6 +15,7 @@ "devDependencies": { "@developomp-site/content": "workspace:*", "@developomp-site/eslint-config": "workspace:*", + "@developomp-site/playwright-config": "workspace:*", "@developomp-site/prettier-config": "workspace:*", "@developomp-site/tailwind-config": "workspace:*", "@fontsource/noto-sans-kr": "^5.0.5", diff --git a/apps/main/playwright.config.ts b/apps/main/playwright.config.ts index 2b90b6e..d3228a0 100644 --- a/apps/main/playwright.config.ts +++ b/apps/main/playwright.config.ts @@ -1,63 +1,5 @@ -import { devices, PlaywrightTestConfig } from "@playwright/test" +import { createConfig } from "@developomp-site/playwright-config" -const baseURL = "http://localhost:5173" - -// Reference: https://playwright.dev/docs/test-configuration -const config: PlaywrightTestConfig = { - // Timeout per test - timeout: 30 * 1000, - - // Test directory - testDir: "e2e", - - // Artifacts folder where screenshots, videos, and traces are stored. - outputDir: "test-results/", - - // Run your local dev server before starting the tests: - // https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests - webServer: { - command: "pnpm serve", - url: baseURL, - timeout: 120 * 1000, - // eslint-disable-next-line turbo/no-undeclared-env-vars - reuseExistingServer: !process.env.CI, - }, - - use: { - // Use baseURL so to make navigations relative. - // More information: https://playwright.dev/docs/api/class-testoptions#test-options-base-url - baseURL, - - // Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc. - // More information: https://playwright.dev/docs/trace-viewer - trace: "retry-with-trace", - - // All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context - // contextOptions: { - // ignoreHTTPSErrors: true, - // }, - }, - - projects: [ - { - name: "Desktop Chrome", - use: { - ...devices["Desktop Chrome"], - }, - }, - { - name: "Desktop Firefox", - use: { - ...devices["Desktop Firefox"], - }, - }, - { - name: "Mobile Chrome", - use: { - ...devices["Pixel 5"], - }, - }, - ], -} - -export default config +export default createConfig({ + port: 5173, +}) diff --git a/apps/portfolio/package.json b/apps/portfolio/package.json index a3cc05a..a168ad9 100644 --- a/apps/portfolio/package.json +++ b/apps/portfolio/package.json @@ -14,6 +14,7 @@ "@developomp-site/blog": "workspace:*", "@developomp-site/content": "workspace:*", "@developomp-site/eslint-config": "workspace:*", + "@developomp-site/playwright-config": "workspace:*", "@developomp-site/prettier-config": "workspace:*", "@developomp-site/tailwind-config": "workspace:*", "@fontsource/noto-sans-kr": "^5.0.5", diff --git a/apps/portfolio/playwright.config.ts b/apps/portfolio/playwright.config.ts index b353e15..0766427 100644 --- a/apps/portfolio/playwright.config.ts +++ b/apps/portfolio/playwright.config.ts @@ -1,63 +1,5 @@ -import { devices, PlaywrightTestConfig } from "@playwright/test" +import { createConfig } from "@developomp-site/playwright-config" -const baseURL = "http://localhost:5174" - -// Reference: https://playwright.dev/docs/test-configuration -const config: PlaywrightTestConfig = { - // Timeout per test - timeout: 30 * 1000, - - // Test directory - testDir: "e2e", - - // Artifacts folder where screenshots, videos, and traces are stored. - outputDir: "test-results/", - - // Run your local dev server before starting the tests: - // https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests - webServer: { - command: "pnpm serve", - url: baseURL, - timeout: 120 * 1000, - // eslint-disable-next-line turbo/no-undeclared-env-vars - reuseExistingServer: !process.env.CI, - }, - - use: { - // Use baseURL so to make navigations relative. - // More information: https://playwright.dev/docs/api/class-testoptions#test-options-base-url - baseURL, - - // Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc. - // More information: https://playwright.dev/docs/trace-viewer - trace: "retry-with-trace", - - // All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context - // contextOptions: { - // ignoreHTTPSErrors: true, - // }, - }, - - projects: [ - { - name: "Desktop Chrome", - use: { - ...devices["Desktop Chrome"], - }, - }, - { - name: "Desktop Firefox", - use: { - ...devices["Desktop Firefox"], - }, - }, - { - name: "Mobile Chrome", - use: { - ...devices["Pixel 5"], - }, - }, - ], -} - -export default config +export default createConfig({ + port: 5174, +}) diff --git a/packages/playwright-config/index.ts b/packages/playwright-config/index.ts new file mode 100644 index 0000000..a2de09e --- /dev/null +++ b/packages/playwright-config/index.ts @@ -0,0 +1,66 @@ +import { devices, type PlaywrightTestConfig } from "@playwright/test" + +export interface Config { + port: number +} + +export function createConfig(config: Config): PlaywrightTestConfig { + const baseURL = `http://localhost:${config.port}` + + return { + // Timeout per test + timeout: 30 * 1000, + + // Test directory + testDir: "e2e", + + // Artifacts folder where screenshots, videos, and traces are stored. + outputDir: "test-results/", + + // Run your local dev server before starting the tests: + // https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests + webServer: { + command: "pnpm serve", + url: baseURL, + timeout: 120 * 1000, + // eslint-disable-next-line turbo/no-undeclared-env-vars + reuseExistingServer: !process.env.CI, + }, + + use: { + // Use baseURL so to make navigations relative. + // More information: https://playwright.dev/docs/api/class-testoptions#test-options-base-url + baseURL, + + // Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc. + // More information: https://playwright.dev/docs/trace-viewer + trace: "retry-with-trace", + + // All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context + // contextOptions: { + // ignoreHTTPSErrors: true, + // }, + }, + + projects: [ + { + name: "Desktop Chrome", + use: { + ...devices["Desktop Chrome"], + }, + }, + { + name: "Desktop Firefox", + use: { + ...devices["Desktop Firefox"], + }, + }, + { + name: "Mobile Chrome", + use: { + ...devices["Pixel 5"], + }, + }, + ], + } +} diff --git a/packages/playwright-config/package.json b/packages/playwright-config/package.json new file mode 100644 index 0000000..554fe96 --- /dev/null +++ b/packages/playwright-config/package.json @@ -0,0 +1,8 @@ +{ + "name": "@developomp-site/playwright-config", + "version": "0.0.0", + "main": "index.ts", + "devDependencies": { + "@playwright/test": "^1.36.2" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7feb2b0..9d1d515 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,6 +35,9 @@ importers: '@developomp-site/eslint-config': specifier: workspace:* version: link:../../packages/eslint-config + '@developomp-site/playwright-config': + specifier: workspace:* + version: link:../../packages/playwright-config '@developomp-site/prettier-config': specifier: workspace:* version: link:../../packages/prettier-config @@ -143,6 +146,9 @@ importers: '@developomp-site/eslint-config': specifier: workspace:* version: link:../../packages/eslint-config + '@developomp-site/playwright-config': + specifier: workspace:* + version: link:../../packages/playwright-config '@developomp-site/prettier-config': specifier: workspace:* version: link:../../packages/prettier-config @@ -230,6 +236,9 @@ importers: '@developomp-site/eslint-config': specifier: workspace:* version: link:../../packages/eslint-config + '@developomp-site/playwright-config': + specifier: workspace:* + version: link:../../packages/playwright-config '@developomp-site/prettier-config': specifier: workspace:* version: link:../../packages/prettier-config @@ -492,6 +501,12 @@ importers: specifier: ^5.1.6 version: 5.1.6 + packages/playwright-config: + devDependencies: + '@playwright/test': + specifier: ^1.36.2 + version: 1.36.2 + packages/prettier-config: {} packages/tailwind-config: