-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
45 lines (39 loc) · 968 Bytes
/
Copy pathtest.js
File metadata and controls
45 lines (39 loc) · 968 Bytes
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
const { spawn } = require("child_process");
const http = require("http");
const app = spawn("node", ["app.js"], {
env: {
...process.env,
MONGODB_URI: process.env.MONGODB_URI || "mongodb://localhost:27017"
}
});
app.stdout.on("data", (data) => {
console.log(`APP: ${data}`);
});
app.stderr.on("data", (data) => {
console.error(`APP ERROR: ${data}`);
});
setTimeout(() => {
http.get("http://localhost:3000", (res) => {
let data = "";
res.on("data", (chunk) => {
data += chunk;
});
res.on("end", () => {
if (res.statusCode === 200) {
console.log("Test passed ✅");
app.kill();
process.exit(0);
} else {
console.error("Test failed ❌");
console.error(data);
app.kill();
process.exit(1);
}
});
}).on("error", (err) => {
console.error("Request failed ❌");
console.error(err.message);
app.kill();
process.exit(1);
});
}, 8000);