Skip to content

Commit 672013a

Browse files
[test] create default user during browser test setup to fix errors being thrown in Comfy backend
1 parent 71343fc commit 672013a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

browser_tests/globalSetup.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { FullConfig } from '@playwright/test'
22
import dotenv from 'dotenv'
3+
import * as fs from 'fs'
4+
import * as path from 'path'
35

46
import { backupPath } from './utils/backupUtils'
57

@@ -18,4 +20,42 @@ export default function globalSetup(config: FullConfig) {
1820
)
1921
}
2022
}
23+
24+
// Create default user by writing directly to users.json file
25+
// This bypasses the API and ensures the user exists at filesystem level
26+
// TODO: Remove this once the backend is fixed
27+
try {
28+
const testComfyuiDir = process.env.TEST_COMFYUI_DIR
29+
if (!testComfyuiDir) {
30+
console.warn('TEST_COMFYUI_DIR is not set')
31+
return
32+
}
33+
const usersJsonPath = path.join(testComfyuiDir, 'user', 'users.json')
34+
35+
console.log('Creating default user in users.json...')
36+
37+
// Ensure user directory exists
38+
const userDirPath = path.dirname(usersJsonPath)
39+
if (!fs.existsSync(userDirPath)) {
40+
fs.mkdirSync(userDirPath, { recursive: true })
41+
}
42+
43+
// Create or update users.json with default user
44+
let users = {}
45+
if (fs.existsSync(usersJsonPath)) {
46+
const existingContent = fs.readFileSync(usersJsonPath, 'utf8')
47+
users = JSON.parse(existingContent)
48+
}
49+
50+
// Add default user if it doesn't exist
51+
if (!users['default']) {
52+
users['default'] = 'default'
53+
fs.writeFileSync(usersJsonPath, JSON.stringify(users))
54+
console.log('Default user added to users.json successfully')
55+
} else {
56+
console.log('Default user already exists in users.json')
57+
}
58+
} catch (error) {
59+
console.warn('Failed to create default user in users.json:', error)
60+
}
2161
}

0 commit comments

Comments
 (0)