Page MenuHomeSealhub

add-route.test.ts
No OneTemporary

add-route.test.ts

import { promises as fs } from "fs";
import { exec, spawn } from "child_process";
import { promisify } from "util";
import axios from "axios";
import waitPort from "wait-port";
import getPort from "get-port";
const execAsync = promisify(exec);
describe("add route test", () => {
let node_pid = 0;
const app_path = "/tmp/sealious-minimal";
const container_name = "sealgen-test-mongo";
afterEach(async function () {
try {
if (node_pid != 0) await execAsync(`kill -9 ${node_pid}`);
} catch (error) {
throw new Error("node process exited unexpectedly, please inspect the output");
}
await Promise.all([
fs.rm(app_path, { recursive: true, force: true }),
execAsync(`docker rm -f ${container_name}`),
]);
});
it.only("creates minimal sealious app", async function () {
this.timeout(250000);
console.log("\tcloning sealious-minimal...");
await execAsync(
`git clone https://hub.sealcode.org/source/sealious-minimal.git ${app_path} && cd ${app_path} && git checkout f48991a0a8b426e0d2f4a4b448fdd41d643b0dae`
);
console.log("\tinstalling dependencies and sealgen...");
await execAsync(
`cd ${app_path} && npm ci && rm -rf node_modules/@sealcode/sealgen && ln -s $OLDPWD node_modules/@sealcode/sealgen`
);
console.log("\trunning add-route and building app...");
await execAsync(
`cd ${app_path} && npx sealgen add-route --url=/sample --action=Sample --mode=page && npm run build`
);
console.log(
"\tstarting the database...(if timeouts here, run 'docker pull mongo:4.4-bionic' to solve)"
);
const port = await getPort();
await execAsync(`docker run -p ${port}:27017 --name ${container_name} -d mongo:4.4-bionic`);
console.log("\trunning app and making request to the generated url...");
const env = { ...process.env, SEALIOUS_MONGO_PORT: port.toString() };
let app_start = spawn(`node`, [`${app_path}/dist/back/index.js`], {
env,
});
app_start.stdout.on("data", (data) => console.log(data.toString()));
app_start.stderr.on("data", (data) => console.log(data.toString()));
if (app_start.pid == undefined) throw new Error("node failed to start");
node_pid = app_start.pid;
await waitPort({
host: "localhost",
port: 8080,
output: "silent",
timeout: 6000,
});
const res = await axios.get("http://localhost:8080/sample");
if (res.status != 200) {
throw new Error("url generated by add-route exists but doesnt return 200");
}
});
});

File Metadata

Mime Type
text/x-java
Expires
Thu, Jan 23, 19:19 (20 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
599887
Default Alt Text
add-route.test.ts (2 KB)

Event Timeline