diff --git a/app-playwright/playwright.config.ts b/app-playwright/playwright.config.ts index 857bfd3c..8302e56e 100644 --- a/app-playwright/playwright.config.ts +++ b/app-playwright/playwright.config.ts @@ -76,11 +76,22 @@ export default defineConfig({ ], /* Run your local dev server before starting the tests */ - webServer: { - command: 'pnpm previewTest', - cwd: '../app', - url: baseURL, - ignoreHTTPSErrors: true, - reuseExistingServer: false, // always use a new server because tests require a prod build due to plugins. - }, + webServer: [ + { + command: 'pnpm previewTest', + cwd: '../app', + url: baseURL, + ignoreHTTPSErrors: true, + reuseExistingServer: !isCI, + }, + { + command: 'pnpm previewTest', + cwd: '../app-ugc', + url: isCI + ? 'http://localhost:3045' + : 'https://app-user-generated-content-pentive.localhost:3045', + ignoreHTTPSErrors: true, + reuseExistingServer: !isCI, + }, + ], }) diff --git a/app-ugc/.gitignore b/app-ugc/.gitignore index 78fdd4d7..a673b3ce 100644 --- a/app-ugc/.gitignore +++ b/app-ugc/.gitignore @@ -2,6 +2,7 @@ node_modules dev-dist dist distDev +distTest lib .cert env.sh diff --git a/app-ugc/package.json b/app-ugc/package.json index 8b010369..2d575749 100644 --- a/app-ugc/package.json +++ b/app-ugc/package.json @@ -4,13 +4,14 @@ "type": "module", "sideEffects": false, "scripts": { - "start": "vite", "dev": "vite", "deploy": "./deploy.sh", "build": "vite build", "build-watch": "vite build --watch", - "buildDev": "vite build --mode development --outDir distDev", - "previewDev": "vite preview --mode development", + "buildDev": "vite build --outDir distDev --mode development", + "buildTest": "vite build --outDir distTest", + "previewDev": "vite preview --outDir distDev", + "previewTest": "vite preview --outDir distTest", "tsc-build": "tsc", "eslint": "eslint . --ignore-path .gitignore --max-warnings 0", "eslint:fix": "eslint . --fix --ignore-path .gitignore --max-warnings 0", diff --git a/app-ugc/vite.config.ts b/app-ugc/vite.config.ts index cfe1717f..ffc3f714 100644 --- a/app-ugc/vite.config.ts +++ b/app-ugc/vite.config.ts @@ -1,3 +1,3 @@ import ugcViteConfig from 'shared/ugcViteConfig' -export default ugcViteConfig(3015) +export default ugcViteConfig({ devPort: 3015, testPort: 3045 }) diff --git a/app/.gitignore b/app/.gitignore index 0c8ab59c..e736533d 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,6 +1,7 @@ node_modules dev-dist dist +distDev distTest lib /test-results/ diff --git a/app/package.json b/app/package.json index 64f2970a..5e94f083 100644 --- a/app/package.json +++ b/app/package.json @@ -4,15 +4,14 @@ "type": "module", "sideEffects": false, "scripts": { - "start": "vite", "dev": "vite", "deploy": "./deploy.sh", "build": "vite build", - "buildDev": "vite build --mode development # Run before `previewDev`", - "buildTest": "vite build --mode test --outDir distTest # Run before testing", "build-watch": "vite build --watch", - "previewDev": "vite preview --mode development # This does NOT necessarily run with development env vars; it exists to enable HTTPS as per `vite.config.ts`", - "previewTest": "vite preview --mode test --outDir distTest --port 3043", + "buildDev": "vite build --outDir distDev --mode development", + "buildTest": "vite build --outDir distTest", + "previewDev": "vite preview --outDir distDev", + "previewTest": "vite preview --outDir distTest --port 3043", "postinstall": "./postinstall.sh", "tsc-build": "tsc", "eslint": "eslint . --ignore-path .gitignore --max-warnings 0", diff --git a/app/vite.config.ts b/app/vite.config.ts index 07dca77a..b77443f2 100644 --- a/app/vite.config.ts +++ b/app/vite.config.ts @@ -5,18 +5,9 @@ import checker from 'vite-plugin-checker' import fs from 'fs' import { VitePWA } from 'vite-plugin-pwa' -const isCI = Boolean(process.env.CI) +const ci = Boolean(process.env.CI) export default defineConfig(({ mode }: UserConfig) => { - const keyPath = './.cert/key.pem' - const certPath = './.cert/cert.pem' - let https - if (mode !== 'production' && !isCI) { - https = { - key: fs.readFileSync(keyPath), - cert: fs.readFileSync(certPath), - } - } // grep 3FBCE1B6-ABA3-4179-80B3-A965F8D087BC // We're using the version number due to https://developer.chrome.com/docs/workbox/service-worker-deployment/#its-all-in-the-timing:~:text=Problems%20arise%20in%20situations%20when%20unversioned%20static%20assets%20are%20cached const define = Object.fromEntries( @@ -30,7 +21,12 @@ export default defineConfig(({ mode }: UserConfig) => { const serverOptions = { port: 3013, strictPort: true, - https, + https: ci + ? undefined // running mkcert in CI is just ulgh + : { + key: fs.readFileSync('./.cert/key.pem'), + cert: fs.readFileSync('./.cert/cert.pem'), + }, headers: { // eslint-disable-next-line @typescript-eslint/naming-convention 'Cross-Origin-Opener-Policy': 'same-origin', diff --git a/hub-ugc/.gitignore b/hub-ugc/.gitignore index 78fdd4d7..a673b3ce 100644 --- a/hub-ugc/.gitignore +++ b/hub-ugc/.gitignore @@ -2,6 +2,7 @@ node_modules dev-dist dist distDev +distTest lib .cert env.sh diff --git a/hub-ugc/package.json b/hub-ugc/package.json index 503a637c..79beea42 100644 --- a/hub-ugc/package.json +++ b/hub-ugc/package.json @@ -4,13 +4,14 @@ "type": "module", "sideEffects": false, "scripts": { - "start": "vite", "dev": "vite", "deploy": "./deploy.sh", "build": "vite build", "build-watch": "vite build --watch", - "buildDev": "vite build --mode development --outDir distDev", - "previewDev": "vite preview --mode development", + "buildDev": "vite build --outDir distDev --mode development", + "buildTest": "vite build --outDir distTest", + "previewDev": "vite preview --outDir distDev", + "previewTest": "vite preview --outDir distTest", "tsc-build": "tsc", "eslint": "eslint . --ignore-path .gitignore --max-warnings 0", "eslint:fix": "eslint . --fix --ignore-path .gitignore --max-warnings 0", diff --git a/hub-ugc/vite.config.ts b/hub-ugc/vite.config.ts index f511dc52..b3b5acf7 100644 --- a/hub-ugc/vite.config.ts +++ b/hub-ugc/vite.config.ts @@ -1,3 +1,3 @@ import ugcViteConfig from 'shared/ugcViteConfig' -export default ugcViteConfig(3016) +export default ugcViteConfig({ devPort: 3016, testPort: 3046 }) diff --git a/shared/src/ugcViteConfig.ts b/shared/src/ugcViteConfig.ts index cb3826c0..54019924 100644 --- a/shared/src/ugcViteConfig.ts +++ b/shared/src/ugcViteConfig.ts @@ -21,7 +21,15 @@ const betterServiceWorkerDevExperience: BuildOptions = { }, } -const configBuilder = (port: number) => +const ci = Boolean(process.env.CI) + +const configBuilder = ({ + devPort, + testPort, +}: { + devPort: number + testPort: number +}) => defineConfig(({ mode }) => { const baseBuild: BuildOptions = { target: 'ES2022', @@ -34,14 +42,6 @@ const configBuilder = (port: number) => ...betterServiceWorkerDevExperience, ...baseBuild, } - const keyPath = './.cert/key.pem' - const certPath = './.cert/cert.pem' - let key - let cert - if (mode === 'development') { - key = fs.readFileSync(keyPath) - cert = fs.readFileSync(certPath) - } const serverOptions = { headers: { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -51,12 +51,14 @@ const configBuilder = (port: number) => // eslint-disable-next-line @typescript-eslint/naming-convention 'Cross-Origin-Resource-Policy': 'cross-origin', }, - port, + port: mode === 'development' ? devPort : testPort, strictPort: true, - https: { - key, - cert, - }, + https: ci + ? undefined // running mkcert in CI is just ulgh + : { + key: fs.readFileSync('./.cert/key.pem'), + cert: fs.readFileSync('./.cert/cert.pem'), + }, } return { esbuild: { diff --git a/turbo.json b/turbo.json index 6a036f72..57326c8a 100644 --- a/turbo.json +++ b/turbo.json @@ -48,7 +48,8 @@ }, "app-playwright#test:run": { "dependsOn": [ - "app#buildTest" + "app#buildTest", + "app-ugc#buildTest" ] }, "deploy": { @@ -90,6 +91,13 @@ "persistent": true, "cache": false }, + "previewTest": { + "dependsOn": [ + "buildTest" + ], + "persistent": true, + "cache": false + }, "//#turso": { "persistent": true, "cache": false