Vanilla server tests, client offline mode (#49)
* vanilla server launcher * update package.json * re-add babel to fix standard * fix ci * add buffer-equal * simple fixes * add offline client support * fix closing bugs, proper wait for server start * add test to mocha * change test timeout to 2 min * increase timeouts Co-authored-by: Romain Beaumont <romain.rom1@gmail.com>
This commit is contained in:
parent
bd97a8e1b7
commit
458136d877
13 changed files with 289 additions and 60 deletions
62
test/vanilla.js
Normal file
62
test/vanilla.js
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
// process.env.DEBUG = 'minecraft-protocol raknet'
|
||||
const vanillaServer = require('../tools/startVanillaServer')
|
||||
const { Client } = require('../src/client')
|
||||
const { waitFor } = require('../src/datatypes/util')
|
||||
|
||||
async function test () {
|
||||
// Start the server, wait for it to accept clients, throws on timeout
|
||||
const handle = await vanillaServer.startServerAndWait('1.16.201', 1000 * 120)
|
||||
console.log('Started server')
|
||||
|
||||
const client = new Client({
|
||||
hostname: '127.0.0.1',
|
||||
port: 19130,
|
||||
username: 'Notch',
|
||||
offline: true
|
||||
})
|
||||
|
||||
console.log('Started client')
|
||||
|
||||
let loop
|
||||
|
||||
await waitFor((res) => {
|
||||
client.once('resource_packs_info', (packet) => {
|
||||
client.write('resource_pack_client_response', {
|
||||
response_status: 'completed',
|
||||
resourcepackids: []
|
||||
})
|
||||
|
||||
client.once('resource_pack_stack', (stack) => {
|
||||
client.write('resource_pack_client_response', {
|
||||
response_status: 'completed',
|
||||
resourcepackids: []
|
||||
})
|
||||
})
|
||||
|
||||
client.queue('client_cache_status', { enabled: false })
|
||||
client.queue('request_chunk_radius', { chunk_radius: 1 })
|
||||
|
||||
clearInterval(loop)
|
||||
loop = setInterval(() => {
|
||||
client.queue('tick_sync', { request_time: BigInt(Date.now()), response_time: BigInt(Date.now()) })
|
||||
}, 200)
|
||||
|
||||
console.log('Awaiting join')
|
||||
|
||||
client.on('spawn', () => {
|
||||
console.log('✔ Client has spawned')
|
||||
client.close()
|
||||
handle.kill()
|
||||
res()
|
||||
})
|
||||
})
|
||||
}, 1000 * 60, () => {
|
||||
client.close()
|
||||
handle.kill()
|
||||
throw Error('❌ client timed out ')
|
||||
})
|
||||
clearInterval(loop)
|
||||
}
|
||||
|
||||
if (!module.parent) test()
|
||||
module.exports = { clientTest: test }
|
||||
10
test/vanilla.test.js
Normal file
10
test/vanilla.test.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/* eslint-env jest */
|
||||
|
||||
const { clientTest } = require('./vanilla')
|
||||
|
||||
describe('vanilla server test', function () {
|
||||
this.timeout(120 * 1000)
|
||||
it('client spawns', async () => {
|
||||
await clientTest()
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue