feat(collect-i18n-node-defs): add mock for object_info API endpoint to allow script execution without backend

fix(collect-i18n-node-defs): create empty locale files if no node definitions are collected to prevent build failures
This commit is contained in:
snomiao
2025-09-13 07:48:52 +00:00
parent 4ea2987502
commit f697717b4d

View File

@@ -1,4 +1,3 @@
import './setup-browser-globals.js'
import * as fs from 'fs'
import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage'
@@ -6,18 +5,29 @@ import type { ComfyNodeDef } from '../src/schemas/nodeDefSchema'
import type { ComfyApi } from '../src/scripts/api'
import { ComfyNodeDefImpl } from '../src/stores/nodeDefStore'
import { normalizeI18nKey } from '../src/utils/formatUtil'
import './setup-browser-globals.js'
const localePath = './src/locales/en/main.json'
const nodeDefsPath = './src/locales/en/nodeDefs.json'
test('collect-i18n-node-defs', async ({ comfyPage }) => {
// Mock view route
comfyPage.page.route('**/view**', async (route) => {
await comfyPage.page.route('**/view**', async (route) => {
await route.fulfill({
body: JSON.stringify({})
})
})
// // Mock the object_info API endpoint to return empty node definitions
// // This allows the script to run without a ComfyUI backend
await comfyPage.page.route('**/api/object_info', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({})
})
})
const nodeDefs: ComfyNodeDefImpl[] = (
Object.values(
await comfyPage.page.evaluate(async () => {
@@ -32,6 +42,27 @@ test('collect-i18n-node-defs', async ({ comfyPage }) => {
console.log(`Collected ${nodeDefs.length} node definitions`)
// If no node definitions were collected (e.g., running without backend),
// create empty locale files to avoid build failures
if (nodeDefs.length === 0) {
console.warn('No node definitions found - creating empty locale files')
const locale = JSON.parse(fs.readFileSync(localePath, 'utf-8'))
fs.writeFileSync(
localePath,
JSON.stringify(
{
...locale,
dataTypes: {},
nodeCategories: {}
},
null,
2
)
)
fs.writeFileSync(nodeDefsPath, JSON.stringify({}, null, 2))
return
}
const allDataTypesLocale = Object.fromEntries(
nodeDefs
.flatMap((nodeDef) => {