mirror of
https://mirror.skon.top/github.com/langgenius/dify.git
synced 2026-04-20 23:40:16 +08:00
test: init e2e (#34193)
Some checks failed
autofix.ci / autofix (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Has been cancelled
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Has been cancelled
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Has been cancelled
Main CI Pipeline / Skip Duplicate Checks (push) Has been cancelled
Main CI Pipeline / Check Changed Files (push) Has been cancelled
Main CI Pipeline / Run API Tests (push) Has been cancelled
Main CI Pipeline / Skip API Tests (push) Has been cancelled
Main CI Pipeline / API Tests (push) Has been cancelled
Main CI Pipeline / Run Web Tests (push) Has been cancelled
Main CI Pipeline / Skip Web Tests (push) Has been cancelled
Main CI Pipeline / Web Tests (push) Has been cancelled
Main CI Pipeline / Run Web Full-Stack E2E (push) Has been cancelled
Main CI Pipeline / Skip Web Full-Stack E2E (push) Has been cancelled
Main CI Pipeline / Web Full-Stack E2E (push) Has been cancelled
Main CI Pipeline / Style Check (push) Has been cancelled
Main CI Pipeline / Run VDB Tests (push) Has been cancelled
Main CI Pipeline / Skip VDB Tests (push) Has been cancelled
Main CI Pipeline / VDB Tests (push) Has been cancelled
Main CI Pipeline / Run DB Migration Test (push) Has been cancelled
Main CI Pipeline / Skip DB Migration Test (push) Has been cancelled
Main CI Pipeline / DB Migration Test (push) Has been cancelled
Some checks failed
autofix.ci / autofix (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Has been cancelled
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Has been cancelled
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Has been cancelled
Main CI Pipeline / Skip Duplicate Checks (push) Has been cancelled
Main CI Pipeline / Check Changed Files (push) Has been cancelled
Main CI Pipeline / Run API Tests (push) Has been cancelled
Main CI Pipeline / Skip API Tests (push) Has been cancelled
Main CI Pipeline / API Tests (push) Has been cancelled
Main CI Pipeline / Run Web Tests (push) Has been cancelled
Main CI Pipeline / Skip Web Tests (push) Has been cancelled
Main CI Pipeline / Web Tests (push) Has been cancelled
Main CI Pipeline / Run Web Full-Stack E2E (push) Has been cancelled
Main CI Pipeline / Skip Web Full-Stack E2E (push) Has been cancelled
Main CI Pipeline / Web Full-Stack E2E (push) Has been cancelled
Main CI Pipeline / Style Check (push) Has been cancelled
Main CI Pipeline / Run VDB Tests (push) Has been cancelled
Main CI Pipeline / Skip VDB Tests (push) Has been cancelled
Main CI Pipeline / VDB Tests (push) Has been cancelled
Main CI Pipeline / Run DB Migration Test (push) Has been cancelled
Main CI Pipeline / Skip DB Migration Test (push) Has been cancelled
Main CI Pipeline / DB Migration Test (push) Has been cancelled
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
83
e2e/support/web-server.ts
Normal file
83
e2e/support/web-server.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import type { ManagedProcess } from './process'
|
||||
import { isPortReachable, startLoggedProcess, stopManagedProcess, waitForUrl } from './process'
|
||||
|
||||
type WebServerStartOptions = {
|
||||
baseURL: string
|
||||
command: string
|
||||
args?: string[]
|
||||
cwd: string
|
||||
logFilePath: string
|
||||
reuseExistingServer: boolean
|
||||
timeoutMs: number
|
||||
}
|
||||
|
||||
let activeProcess: ManagedProcess | undefined
|
||||
|
||||
const getUrlHostAndPort = (url: string) => {
|
||||
const parsedUrl = new URL(url)
|
||||
const isHttps = parsedUrl.protocol === 'https:'
|
||||
|
||||
return {
|
||||
host: parsedUrl.hostname,
|
||||
port: parsedUrl.port ? Number(parsedUrl.port) : isHttps ? 443 : 80,
|
||||
}
|
||||
}
|
||||
|
||||
export const startWebServer = async ({
|
||||
baseURL,
|
||||
command,
|
||||
args = [],
|
||||
cwd,
|
||||
logFilePath,
|
||||
reuseExistingServer,
|
||||
timeoutMs,
|
||||
}: WebServerStartOptions) => {
|
||||
const { host, port } = getUrlHostAndPort(baseURL)
|
||||
|
||||
if (reuseExistingServer && (await isPortReachable(host, port))) return
|
||||
|
||||
activeProcess = await startLoggedProcess({
|
||||
command,
|
||||
args,
|
||||
cwd,
|
||||
label: 'web server',
|
||||
logFilePath,
|
||||
})
|
||||
|
||||
let startupError: Error | undefined
|
||||
activeProcess.childProcess.once('error', (error) => {
|
||||
startupError = error
|
||||
})
|
||||
activeProcess.childProcess.once('exit', (code, signal) => {
|
||||
if (startupError) return
|
||||
|
||||
startupError = new Error(
|
||||
`Web server exited before readiness (code: ${code ?? 'unknown'}, signal: ${signal ?? 'none'}).`,
|
||||
)
|
||||
})
|
||||
|
||||
const deadline = Date.now() + timeoutMs
|
||||
while (Date.now() < deadline) {
|
||||
if (startupError) {
|
||||
await stopManagedProcess(activeProcess)
|
||||
activeProcess = undefined
|
||||
throw startupError
|
||||
}
|
||||
|
||||
try {
|
||||
await waitForUrl(baseURL, 1_000, 250, 1_000)
|
||||
return
|
||||
} catch {
|
||||
// Continue polling until timeout or child exit.
|
||||
}
|
||||
}
|
||||
|
||||
await stopManagedProcess(activeProcess)
|
||||
activeProcess = undefined
|
||||
throw new Error(`Timed out waiting for web server readiness at ${baseURL} after ${timeoutMs}ms.`)
|
||||
}
|
||||
|
||||
export const stopWebServer = async () => {
|
||||
await stopManagedProcess(activeProcess)
|
||||
activeProcess = undefined
|
||||
}
|
||||
Reference in New Issue
Block a user