Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/test/externalTests/bossBar.js
3738 views
1
const assert = require('assert')
2
const { once, onceWithCleanup } = require('../../lib/promise_utils')
3
4
module.exports = (version) => async (bot) => {
5
// Skip test for versions older than 1.13 (bossbar command not available)
6
if (bot.registry.isOlderThan('1.13')) return
7
8
console.log('[bossBar test] Starting boss bar tests')
9
10
// Test boss bar creation
11
const createBossBar = async () => {
12
const uuid = 'test:bar1'
13
const title = 'Test Boss Bar'
14
const colorName = 'red'
15
const styleName = 'notched_6'
16
const health = 0.5
17
18
bot.test.sayEverywhere(`/bossbar add ${uuid} "${title}"`)
19
bot.test.sayEverywhere(`/bossbar set ${uuid} players ${bot.username}`)
20
bot.test.sayEverywhere(`/bossbar set ${uuid} color ${colorName}`)
21
bot.test.sayEverywhere(`/bossbar set ${uuid} style ${styleName}`)
22
bot.test.sayEverywhere(`/bossbar set ${uuid} value ${health * 100}`)
23
bot.test.sayEverywhere(`/bossbar set ${uuid} visible true`)
24
25
// Wait for the boss bar to be created
26
const [bossBar] = await once(bot, 'bossBarCreated')
27
console.log('DEBUG bossBar:', bossBar)
28
console.log('DEBUG bossBar own properties:', Object.getOwnPropertyNames(bossBar))
29
console.log('DEBUG bossBar prototype:', Object.getPrototypeOf(bossBar))
30
console.log('DEBUG bossBar.title:', bossBar.title, 'type:', typeof bossBar.title)
31
assert.strictEqual(bossBar.title.toString(), title)
32
// Do not check dividers or color here; they will be updated in the next step
33
}
34
35
// Test boss bar update
36
const updateBossBar = async () => {
37
const uuid = 'test:bar1'
38
const newHealth = 0.75
39
const newColor = 'blue'
40
const newStyle = 'notched_10'
41
42
bot.test.sayEverywhere(`/bossbar set ${uuid} color ${newColor}`)
43
bot.test.sayEverywhere(`/bossbar set ${uuid} style ${newStyle}`)
44
bot.test.sayEverywhere(`/bossbar set ${uuid} value ${newHealth * 100}`)
45
46
// Wait for the boss bar to have the expected state
47
const [bossBar] = await onceWithCleanup(bot, 'bossBarUpdated', {
48
timeout: 5000,
49
checkCondition: (bossBar) =>
50
bossBar.health === newHealth &&
51
bossBar.color === newColor &&
52
bossBar.dividers === 10
53
})
54
assert.strictEqual(bossBar.health, newHealth)
55
assert.strictEqual(bossBar.color, newColor)
56
assert.strictEqual(bossBar.dividers, 10)
57
}
58
59
// Test boss bar deletion
60
const deleteBossBar = async () => {
61
const uuid = 'test:bar1'
62
bot.test.sayEverywhere(`/bossbar remove ${uuid}`)
63
await once(bot, 'bossBarDeleted')
64
assert.strictEqual(bot.bossBars.length, 0)
65
}
66
67
try {
68
await createBossBar()
69
await updateBossBar()
70
await deleteBossBar()
71
console.log('[bossBar test] All tests passed!')
72
} catch (err) {
73
console.error('[bossBar test] Test failed:', err)
74
throw err
75
}
76
}
77
78