forked from TobiasMelen/next-dev-https
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
35 lines (34 loc) · 893 Bytes
/
test.js
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
//@ts-check
const { test } = require("node:test");
const { spawn } = require("node:child_process");
test("Test dev server startup", () => {
const childProcess = spawn("pnpm", ["run", "dev"], {
cwd: "sandbox",
shell: true,
stdio: "pipe",
detached: true,
});
return new Promise((res, rej) => {
childProcess.stdout.setEncoding("utf-8");
childProcess.stderr.setEncoding("utf-8");
childProcess.stdout.on("data", (msg) => {
if (msg.includes("compiled client and server successfully")) {
res("Completed");
}
});
childProcess.stderr.on("data", (msg) => {
rej(Error(msg));
});
childProcess.on("error", (err) => {
rej(err);
});
childProcess.on("close", (exitCode) => {
rej(`Exit code ${exitCode}`);
});
}).finally(() => {
process.kill(
//@ts-ignore
-childProcess.pid
);
});
});