Spaces:
Paused
Paused
Download tests-ui/utils/setup.js from brunvelop/ComfyUI: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/brunvelop/ComfyUI/resolve/refs%2Fpr%2F1/tests-ui/utils/setup.js
- Command line
-
hf download hf://spaces/brunvelop/ComfyUI@refs/pr/1/tests-ui/utils/setup.js
-
curl -L -o setup.js https://huggingface.co/spaces/brunvelop/ComfyUI/resolve/refs%2Fpr%2F1/tests-ui/utils/setup.js
1.23 kB
| require("../../web/scripts/api"); | |
| const fs = require("fs"); | |
| const path = require("path"); | |
| function* walkSync(dir) { | |
| const files = fs.readdirSync(dir, { withFileTypes: true }); | |
| for (const file of files) { | |
| if (file.isDirectory()) { | |
| yield* walkSync(path.join(dir, file.name)); | |
| } else { | |
| yield path.join(dir, file.name); | |
| } | |
| } | |
| } | |
| /** | |
| * @typedef { import("../../web/types/comfy").ComfyObjectInfo } ComfyObjectInfo | |
| */ | |
| /** | |
| * @param { { mockExtensions?: string[], mockNodeDefs?: Record<string, ComfyObjectInfo> } } config | |
| */ | |
| export function mockApi({ mockExtensions, mockNodeDefs } = {}) { | |
| if (!mockExtensions) { | |
| mockExtensions = Array.from(walkSync(path.resolve("../web/extensions/core"))) | |
| .filter((x) => x.endsWith(".js")) | |
| .map((x) => path.relative(path.resolve("../web"), x)); | |
| } | |
| if (!mockNodeDefs) { | |
| mockNodeDefs = JSON.parse(fs.readFileSync(path.resolve("./data/object_info.json"))); | |
| } | |
| jest.mock("../../web/scripts/api", () => ({ | |
| get api() { | |
| return { | |
| addEventListener: jest.fn(), | |
| getSystemStats: jest.fn(), | |
| getExtensions: jest.fn(() => mockExtensions), | |
| getNodeDefs: jest.fn(() => mockNodeDefs), | |
| init: jest.fn(), | |
| apiURL: jest.fn((x) => "../../web/" + x), | |
| }; | |
| }, | |
| })); | |
| } | |