Skip to content

Commit

Permalink
run app-ugc's previewTest with app-playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexErrant committed Nov 12, 2024
1 parent 7e7f526 commit e82cd47
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 46 deletions.
25 changes: 18 additions & 7 deletions app-playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
})
1 change: 1 addition & 0 deletions app-ugc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules
dev-dist
dist
distDev
distTest
lib
.cert
env.sh
7 changes: 4 additions & 3 deletions app-ugc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion app-ugc/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import ugcViteConfig from 'shared/ugcViteConfig'

export default ugcViteConfig(3015)
export default ugcViteConfig({ devPort: 3015, testPort: 3045 })
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
dev-dist
dist
distDev
distTest
lib
/test-results/
Expand Down
9 changes: 4 additions & 5 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 7 additions & 11 deletions app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions hub-ugc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules
dev-dist
dist
distDev
distTest
lib
.cert
env.sh
7 changes: 4 additions & 3 deletions hub-ugc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion hub-ugc/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import ugcViteConfig from 'shared/ugcViteConfig'

export default ugcViteConfig(3016)
export default ugcViteConfig({ devPort: 3016, testPort: 3046 })
30 changes: 16 additions & 14 deletions shared/src/ugcViteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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: {
Expand Down
10 changes: 9 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
},
"app-playwright#test:run": {
"dependsOn": [
"app#buildTest"
"app#buildTest",
"app-ugc#buildTest"
]
},
"deploy": {
Expand Down Expand Up @@ -90,6 +91,13 @@
"persistent": true,
"cache": false
},
"previewTest": {
"dependsOn": [
"buildTest"
],
"persistent": true,
"cache": false
},
"//#turso": {
"persistent": true,
"cache": false
Expand Down

0 comments on commit e82cd47

Please sign in to comment.