import * as Railway from "@alchemy.run/railway";
import { describe, expect } from "@alchemy.run/test";
import * as Test from "@alchemy.run/test/Alchemy";
import * as Effect from "effect/Effect";
import * as pathe from "pathe";
import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
const { test } = Test.make({ providers: Railway.providers(), dev: true });
const fixtureDir = pathe.resolve(
import.meta.dirname,
"../../AWS/Website/fixtures/react-router-app",
);
const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
const fixtureEntries = [
".gitignore",
"package.json",
"react-router.config.ts",
"vite.config.ts",
"app",
"public",
];
describe(
"Railway.Website.ReactRouter local",
{ tags: ["provider:railway", "provider:railway:website", "local"] },
() => {
test.provider(
"dev runs the framework server with no cloud resources",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
const rootDir = yield* cloneFixture(fixtureDir, {
prefix: "alchemy-react-router-railway-local-",
tempRoot,
entries: fixtureEntries,
});
const deployed = yield* stack.deploy(
Effect.gen(function* () {
const site = yield* Railway.Website.ReactRouter("Web", {
rootDir,
});
return { site };
}),
);
const url = deployed.site.url;
expect(url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1):\d+\/?$/);
expect(deployed.site.service).toBeUndefined();
expect(deployed.site.project).toBeUndefined();
const origin = String(url).replace(/\/+$/, "");
yield* expectUrlContains(`${origin}/`, "REACT_ROUTER_AWS_PAGE_MARKER", {
timeout: "90 seconds",
label: "dev home page",
});
yield* expectUrlContains(
`${origin}/api/hello?echo=roundtrip`,
"REACT_ROUTER_AWS_API_MARKER",
{ label: "api route (dev)" },
);
yield* stack.destroy();
}),
{ timeout: 120_000 },
);
},
);