import json import os from pathlib import Path import pytest from js_lift import NODE, JsSource, run_node, slice_braced JS = JsSource(Path(os.environ.get("MANAGER_JS_DIR") or (Path(__file__).resolve().parent.parent / "js"))) pytestmark = pytest.mark.skipif(NODE is None, reason="node is required to execute the lifted production JS") COMPONENT = {"packname": "a pack", "category": "", "nodes": [], "links": [], "external": []} def load(status, body): source = JS.text("components-manager.js") script = """ const registered = []; const app = {graph: {}}; const api = {fetchApi: async () => ({status: %s, json: async () => JSON.parse(%s)})}; const SEPARATOR = '/'; const sleep = async () => {}; const register_pack_map = () => {}; class GroupNodeConfig { constructor(name, data) { this.name = name; } async registerType(category) { registered.push([this.name, category]); } } %s %s let failed = null; try { await load_components(); } catch(e) { failed = String(e); } console.log(JSON.stringify({groupNodes: app.graph.extra?.groupNodes ?? {}, registered, failed})); """ % ( json.dumps(status), json.dumps(body), slice_braced(source, "function storeGroupNode(name, data, register=true)"), JS.lift_declaration("components-manager.js", "export async function load_components()"), ) return run_node(script) @pytest.mark.parametrize("status, body", [ (403, '{"error": "comfyui_outdated"}'), (403, '{"error": "security_level"}'), (403, ""), (400, ""), (404, "404: Not Found"), (500, "
500 Internal Server Error"), (502, "