-
Notifications
You must be signed in to change notification settings - Fork 108
/
smoke-test.mjs
69 lines (64 loc) · 1.65 KB
/
smoke-test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import esbuild from "esbuild";
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const express = require("express");
const proxy = require("express-http-proxy");
const puppeteer = require("puppeteer");
const result = await esbuild.build({
entryPoints: ["build/esm/index.js"],
bundle: true,
format: "esm",
write: false,
});
const app = express();
app.get("/smoke", (_req, res) => {
res.type("html");
res.end(`<!DOCTYPE html>
<script type="importmap">
{
"imports": {
"arangojs": "/smoke/index.js"
}
}
</script>
`);
});
app.get("/smoke/index.js", (_req, res) => {
res.type("js");
res.end(result.outputFiles[0].text);
});
app.use("/", proxy("arangodb:8529"));
app.listen(8529, () => {
(async () => {
let info;
try {
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
const page = await browser.newPage();
await page.goto("http://127.0.0.1:8529/smoke", {
waitUntil: "networkidle2",
});
const response = await page.evaluate(async () => {
const arangojs = await import("arangojs");
const Database = arangojs.Database;
const db = new Database();
try {
const info = await db.version();
return JSON.stringify(info);
} catch (e) {
return JSON.stringify(e);
}
});
info = JSON.parse(response);
await browser.close();
} catch (e) {
console.error(e);
}
if (info.server !== "arango") {
console.error("Smoke test failed:", info);
process.exit(1);
} else {
console.log("Smoke test passed", info);
process.exit(0);
}
})();
});