t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Railway/Website/Nextjs.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

127 lines
3.8 KiB
TypeScript

import { Query } from "@distilled.cloud/core/query";
import { Railway as RailwayApi } from "@distilled.cloud/railway";
import * as Railway from "@/Railway";
import { suitePartition } from "../suiteProject.ts";
import * as Test from "@/Test/Alchemy";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
import { MinimumLogLevel } from "effect/References";
import * as Schedule from "effect/Schedule";
import * as pathe from "pathe";
import { cloneFixture } from "../../Cloudflare/Utils/Fixture.ts";
import { expectUrlContains } from "../../Cloudflare/Utils/Http.ts";
import { prepareNextjsFixture } from "../../Cloudflare/Website/TypeScriptCompat.ts";
const { test } = Test.make({ providers: Railway.providers() });
const logLevel = Effect.provideService(
MinimumLogLevel,
process.env.DEBUG ? "Debug" : "Info",
);
const fixtureDir = pathe.resolve(
import.meta.dirname,
"../../AWS/Website/fixtures/nextjs-app",
);
const fixtureEntries = [
".gitignore",
"package.json",
"next.config.ts",
"tsconfig.json",
"app",
"public",
];
const readService = Query.fn((id: string) => ({
deletedAt: RailwayApi.service({ id }).deletedAt,
}));
const waitUntilGone = (serviceId: string) =>
readService(serviceId).pipe(
Effect.map((service) =>
service.deletedAt != null ? ("gone" as const) : ("found" as const),
),
Effect.catchTag("RailwayNotFound", () => Effect.succeed("gone" as const)),
Effect.repeat({
schedule: Schedule.spaced("1 second"),
until: (status) => status === "gone",
times: 10,
}),
);
test.provider(
"Nextjs: deploy, GET /, destroy, gone",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
// Clone OUTSIDE the repo (OS temp dir): an in-workspace clone makes
// Next treat the alchemy monorepo as the workspace root and look up
// the root's typescript (catalog:build = tsgo, which has no JS compiler).
const rootDir = yield* cloneFixture(fixtureDir, {
prefix: "alchemy-nextjs-railway-",
entries: fixtureEntries,
});
yield* prepareNextjsFixture(rootDir);
const deployed = yield* stack.deploy(
Effect.gen(function* () {
const { project, environment } = yield* suitePartition;
const site = yield* Railway.Website.Nextjs("Web", {
project,
environment,
rootDir,
memo: {
include: [
"app/**",
"public/**",
"package.json",
"next.config.ts",
"tsconfig.json",
],
},
});
return { site };
}),
);
const url = deployed.site.url;
expect(url).toBeDefined();
expect(url).toMatch(/^https:\/\//);
expect(deployed.site.service).toBeDefined();
expect(deployed.site.project).toBeDefined();
yield* expectUrlContains(`${url!}/`, "NEXTJS_AWS_PAGE_MARKER", {
timeout: "90 seconds",
label: "home page",
});
yield* expectUrlContains(
`${url!}/api/hello?echo=roundtrip`,
"NEXTJS_AWS_API_MARKER",
{
timeout: "30 seconds",
label: "api route",
},
);
yield* expectUrlContains(`${url!}/static`, "NEXTJS_AWS_STATIC_MARKER", {
timeout: "30 seconds",
label: "extra route",
});
const serviceId = deployed.site.service!.serviceId;
yield* stack.destroy();
const gone = yield* waitUntilGone(serviceId);
expect(gone).toEqual("gone");
}).pipe(logLevel),
{
tags: [
"provider:railway",
"provider:railway:project",
"provider:railway:projectenvironment",
"provider:railway:service",
"provider:railway:website",
"live",
],
timeout: 120_000,
},
);