forked from lightningpixel/modly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.test.mjs
More file actions
87 lines (79 loc) · 2.4 KB
/
Copy pathutils.test.mjs
File metadata and controls
87 lines (79 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import test from 'node:test'
import assert from 'node:assert/strict'
import { buildSync } from 'esbuild'
import { createRequire } from 'node:module'
import { mkdtempSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join, resolve } from 'node:path'
function loadModule() {
const outfile = join(mkdtempSync(join(tmpdir(), 'modly-modelutils-test-')), 'utils.cjs')
const require = createRequire(import.meta.url)
const result = buildSync({
entryPoints: [resolve('src/areas/models/utils.ts')],
bundle: true,
platform: 'node',
format: 'cjs',
write: false,
})
writeFileSync(outfile, result.outputFiles[0].text, 'utf8')
return require(outfile)
}
const {
finishExtensionRepair,
formatModelName,
isExtensionRepairable,
} = loadModule()
test('formatModelName turns a hyphenated id into a Title-cased label', () => {
assert.equal(formatModelName('trellis'), 'Trellis')
assert.equal(formatModelName('stable-fast-3d'), 'Stable Fast 3d')
assert.equal(formatModelName('hunyuan-3d-2'), 'Hunyuan 3d 2')
})
test('formatModelName only capitalizes word-initial chars (digits left as-is)', () => {
// \b\w upper-cases the first char of each space-separated word; the "d" after
// a digit is mid-word and stays lower-case.
assert.equal(formatModelName('a-b-c'), 'A B C')
assert.equal(formatModelName(''), '')
})
test('only model extensions with a usable manifest expose Repair', () => {
const model = {
type: 'model',
id: 'pixal3d',
name: 'Pixal3D',
trusted: false,
builtin: false,
nodes: [],
}
assert.equal(isExtensionRepairable(model), true)
assert.equal(isExtensionRepairable({
...model,
corrupted: true,
manifestError: 'incomplete',
}), true)
assert.equal(isExtensionRepairable({
...model,
corrupted: true,
manifestError: 'invalid',
}), false)
assert.equal(isExtensionRepairable({
...model,
builtin: true,
corrupted: true,
manifestError: 'incomplete',
}), false)
assert.equal(isExtensionRepairable({
...model,
type: 'process',
entry: 'processor.js',
}), false)
})
test('Repair completion refreshes extension state even when setup fails', async () => {
let refreshCount = 0
const error = await finishExtensionRepair(
{ success: false, error: 'setup failed' },
async () => {
refreshCount += 1
},
)
assert.equal(refreshCount, 1)
assert.equal(error, 'setup failed')
})