mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-11 08:00:21 +00:00
Apply new code format standard (#217)
This commit is contained in:
@@ -1,69 +1,69 @@
|
||||
import { readdirSync, readFileSync } from "fs";
|
||||
import lg from "../utils/litegraph";
|
||||
import path from "path";
|
||||
import { start } from "../utils";
|
||||
import { readdirSync, readFileSync } from 'fs'
|
||||
import lg from '../utils/litegraph'
|
||||
import path from 'path'
|
||||
import { start } from '../utils'
|
||||
|
||||
const WORKFLOW_DIR = "tests-ui/workflows/examples";
|
||||
const WORKFLOW_DIR = 'tests-ui/workflows/examples'
|
||||
|
||||
// Resolve basic differences in old prompts
|
||||
function fixLegacyPrompt(prompt: { inputs: any }) {
|
||||
for (const n of Object.values(prompt)) {
|
||||
const { inputs } = n;
|
||||
const { inputs } = n
|
||||
|
||||
// Added inputs
|
||||
if (n.class_type === "VAEEncodeForInpaint") {
|
||||
if (n.inputs["grow_mask_by"] == null) n.inputs["grow_mask_by"] = 6;
|
||||
} else if (n.class_type === "SDTurboScheduler") {
|
||||
if (n.inputs["denoise"] == null) n.inputs["denoise"] = 1;
|
||||
if (n.class_type === 'VAEEncodeForInpaint') {
|
||||
if (n.inputs['grow_mask_by'] == null) n.inputs['grow_mask_by'] = 6
|
||||
} else if (n.class_type === 'SDTurboScheduler') {
|
||||
if (n.inputs['denoise'] == null) n.inputs['denoise'] = 1
|
||||
}
|
||||
|
||||
// This has been renamed
|
||||
if (inputs["choose file to upload"]) {
|
||||
const v = inputs["choose file to upload"];
|
||||
delete inputs["choose file to upload"];
|
||||
inputs["upload"] = v;
|
||||
if (inputs['choose file to upload']) {
|
||||
const v = inputs['choose file to upload']
|
||||
delete inputs['choose file to upload']
|
||||
inputs['upload'] = v
|
||||
}
|
||||
|
||||
delete n["is_changed"];
|
||||
delete n['is_changed']
|
||||
}
|
||||
return prompt;
|
||||
return prompt
|
||||
}
|
||||
|
||||
describe("example workflows", () => {
|
||||
describe('example workflows', () => {
|
||||
beforeEach(() => {
|
||||
lg.setup(global);
|
||||
});
|
||||
lg.setup(global)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
lg.teardown(global);
|
||||
});
|
||||
lg.teardown(global)
|
||||
})
|
||||
|
||||
for (const file of readdirSync(WORKFLOW_DIR)) {
|
||||
if (!file.endsWith(".json")) continue;
|
||||
if (!file.endsWith('.json')) continue
|
||||
const { workflow, prompt } = JSON.parse(
|
||||
readFileSync(path.resolve(WORKFLOW_DIR, file), "utf8")
|
||||
);
|
||||
readFileSync(path.resolve(WORKFLOW_DIR, file), 'utf8')
|
||||
)
|
||||
|
||||
let skip = false;
|
||||
let parsedWorkflow;
|
||||
let skip = false
|
||||
let parsedWorkflow
|
||||
try {
|
||||
// Workflows with group nodes dont generate the same IDs as the examples
|
||||
// they'll need recreating so skip them for now.
|
||||
parsedWorkflow = JSON.parse(workflow);
|
||||
skip = !!Object.keys(parsedWorkflow?.extra?.groupNodes ?? {}).length;
|
||||
parsedWorkflow = JSON.parse(workflow)
|
||||
skip = !!Object.keys(parsedWorkflow?.extra?.groupNodes ?? {}).length
|
||||
} catch (error) {}
|
||||
|
||||
(skip ? test.skip : test)(
|
||||
"correctly generates prompt json for " + file,
|
||||
;(skip ? test.skip : test)(
|
||||
'correctly generates prompt json for ' + file,
|
||||
async () => {
|
||||
if (!workflow || !prompt) throw new Error("Invalid example json");
|
||||
if (!workflow || !prompt) throw new Error('Invalid example json')
|
||||
|
||||
const { app } = await start();
|
||||
await app.loadGraphData(parsedWorkflow);
|
||||
const { app } = await start()
|
||||
await app.loadGraphData(parsedWorkflow)
|
||||
|
||||
const output = await app.graphToPrompt();
|
||||
expect(output.output).toEqual(fixLegacyPrompt(JSON.parse(prompt)));
|
||||
const output = await app.graphToPrompt()
|
||||
expect(output.output).toEqual(fixLegacyPrompt(JSON.parse(prompt)))
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user