2022-10-12 09:47:13 +00:00
|
|
|
import { createSandbox } from "../environments/deno_sandbox.ts";
|
2022-10-10 12:50:21 +00:00
|
|
|
import { EndpointHook, EndpointHookT } from "./endpoint.ts";
|
|
|
|
import { System } from "../system.ts";
|
|
|
|
|
|
|
|
import { Application } from "../../server/deps.ts";
|
|
|
|
import { assertEquals } from "../../test_deps.ts";
|
2023-08-11 18:37:13 +00:00
|
|
|
import { compileManifest } from "../compile.ts";
|
|
|
|
import { esbuild } from "../deps.ts";
|
2022-10-10 12:50:21 +00:00
|
|
|
|
2023-08-11 18:37:13 +00:00
|
|
|
Deno.test("Run a plugos endpoint server", async () => {
|
|
|
|
const tempDir = await Deno.makeTempDir();
|
|
|
|
const system = new System<EndpointHookT>("server");
|
|
|
|
|
|
|
|
const workerPath = await compileManifest(
|
|
|
|
new URL("../test.plug.yaml", import.meta.url).pathname,
|
|
|
|
tempDir,
|
|
|
|
);
|
|
|
|
|
|
|
|
await system.load(
|
|
|
|
new URL(`file://${workerPath}`),
|
2023-12-06 17:44:48 +00:00
|
|
|
"test",
|
|
|
|
0,
|
2023-08-11 18:37:13 +00:00
|
|
|
createSandbox,
|
|
|
|
);
|
|
|
|
|
|
|
|
const app = new Application();
|
|
|
|
const port = 3123;
|
|
|
|
|
2023-09-04 19:14:04 +00:00
|
|
|
system.addHook(new EndpointHook(app, "/_/"));
|
2023-08-11 18:37:13 +00:00
|
|
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
app.listen({ port: port, signal: controller.signal });
|
|
|
|
|
|
|
|
const res = await fetch(`http://localhost:${port}/_/test/?name=Pete`);
|
|
|
|
assertEquals(res.status, 200);
|
|
|
|
assertEquals(res.headers.get("Content-type"), "application/json");
|
|
|
|
assertEquals(await res.json(), [1, 2, 3]);
|
|
|
|
console.log("Aborting");
|
|
|
|
controller.abort();
|
|
|
|
await system.unloadAll();
|
|
|
|
|
|
|
|
await Deno.remove(tempDir, { recursive: true });
|
|
|
|
esbuild.stop();
|
|
|
|
});
|