diff --git a/.gitignore b/.gitignore index 98d91318d..43c038e41 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ venv/ /web/extensions/* !/web/extensions/logging.js.example !/web/extensions/core/ +/tests-ui/data/object_info.json \ No newline at end of file diff --git a/tests-ui/setup.js b/tests-ui/setup.js index 9af4f213b..5bfd2eca3 100644 --- a/tests-ui/setup.js +++ b/tests-ui/setup.js @@ -1,68 +1,71 @@ const { spawn } = require("child_process"); const { resolve } = require("path"); -const { writeFile } = require("fs"); +const { writeFile, existsSync } = require("fs"); const http = require("http"); - async function setup() { - // Wait up to 30s for it to start - let success = false; - let child; - for (let i = 0; i < 30; i++) { - try { - await new Promise((res, rej) => { - http - .get("http://127.0.0.1:8188/object_info", (resp) => { - let data = ""; - resp.on("data", (chunk) => { - data += chunk; - }); - resp.on("end", () => { - // Modify the response data to add some checkpoints - const objectInfo = JSON.parse(data); - objectInfo.CheckpointLoaderSimple.input.required.ckpt_name[0] = ["model1.safetensors", "model2.ckpt"]; +async function setup() { + // Wait up to 30s for it to start + let success = false; + let child; + for (let i = 0; i < 30; i++) { + try { + await new Promise((res, rej) => { + http + .get("http://127.0.0.1:8188/object_info", (resp) => { + let data = ""; + resp.on("data", (chunk) => { + data += chunk; + }); + resp.on("end", () => { + // Modify the response data to add some checkpoints + const objectInfo = JSON.parse(data); + objectInfo.CheckpointLoaderSimple.input.required.ckpt_name[0] = ["model1.safetensors", "model2.ckpt"]; - data = JSON.stringify(objectInfo, undefined, "\t"); + data = JSON.stringify(objectInfo, undefined, "\t"); - writeFile( - "data/object_info.json", - data, - { - encoding: "utf8", - }, - (err) => { - if (err) { - rej(err); - } else { - res(); - } + writeFile( + "data/object_info.json", + data, + { + encoding: "utf8", + }, + (err) => { + if (err) { + rej(err); + } else { + res(); } - ); - res(); - }); - }) - .on("error", rej); - }); - success = true; - break; - } catch (error) { - if (i === 0) { - // Start the server on first iteration if it fails to connect - console.log("Starting ComfyUI server..."); + } + ); + res(); + }); + }) + .on("error", rej); + }); + success = true; + break; + } catch (error) { + if (i === 0) { + // Start the server on first iteration if it fails to connect + console.log("Starting ComfyUI server..."); - const python = resolve("../../python_embeded/python.exe"); - child = spawn(python, ["-s", "ComfyUI/main.py", "--cpu"], { cwd: "../.." }); + let python = resolve("../../python_embeded/python.exe"); + if (!existsSync(python)) { + python = "python"; } - await new Promise((r) => { - setTimeout(r, 1000); - }); + child = spawn(python, ["-s", "ComfyUI/main.py", "--cpu"], { cwd: "../.." }); } + await new Promise((r) => { + setTimeout(r, 1000); + }); } + } - child?.kill(); + child?.kill(); - if (!success) { - throw new Error("Waiting for server timed out..."); - } - } + if (!success) { + throw new Error("Waiting for server timed out..."); + } +} setup(); \ No newline at end of file