The suite creates and deletes flows, dashboards and users, and ran against whatever stack was up, which is the dev instance's data. make test-stack starts the compose project fluksio-test (compose.test.yml over the local stack's files) with its own containers, volumes and image tags, served by the local Traefik on app.test.localhost and api.test.localhost, and leaves it running. The hostname is fixed, so it no longer comes off the running dev stack, and a LAN stack makes no difference. The suite's default origin is the test stack.
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import path from "node:path"
|
|
import { fileURLToPath } from "node:url"
|
|
import dotenv from "dotenv"
|
|
|
|
const __filename = fileURLToPath(import.meta.url)
|
|
const __dirname = path.dirname(__filename)
|
|
|
|
dotenv.config({ path: path.join(__dirname, "../../.env") })
|
|
|
|
function getEnvVar(name: string): string {
|
|
const value = process.env[name]
|
|
if (!value) {
|
|
throw new Error(`Environment variable ${name} is undefined`)
|
|
}
|
|
return value
|
|
}
|
|
|
|
export const firstSuperuser = getEnvVar("FIRST_SUPERUSER")
|
|
export const firstSuperuserPassword = getEnvVar("FIRST_SUPERUSER_PASSWORD")
|
|
|
|
/**
|
|
* The two origins a run talks to: the app in the browser, and the API for the
|
|
* setup and teardown around a spec.
|
|
*
|
|
* Deliberately *not* taken from `VITE_API_URL`, even though `../../.env` above
|
|
* has one. That variable belongs to the app build, and in a checkout configured
|
|
* for a deployment it names the deployment — so a suite reading it would drive
|
|
* a browser at the local stack while sending its `DELETE`s to the live
|
|
* instance. Both origins come from the same place instead: whatever the browser
|
|
* is pointed at is what teardown may write to.
|
|
*/
|
|
export const appUrl =
|
|
process.env.PLAYWRIGHT_BASE_URL || "http://app.test.localhost"
|
|
|
|
export const apiUrl = process.env.PLAYWRIGHT_API_URL || apiOrigin(appUrl)
|
|
|
|
/** `app.<domain>` serves the SPA, `api.<domain>` serves its API. */
|
|
function apiOrigin(app: string): string {
|
|
const url = new URL(app)
|
|
if (!url.hostname.startsWith("app.")) {
|
|
throw new Error(
|
|
`Cannot derive the API origin from PLAYWRIGHT_BASE_URL=${app}. ` +
|
|
"Set PLAYWRIGHT_API_URL to name it.",
|
|
)
|
|
}
|
|
url.hostname = `api.${url.hostname.slice("app.".length)}`
|
|
return url.origin
|
|
}
|