mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 19:20:54 +00:00
adapt test for multi-version
This commit is contained in:
parent
2e749ff49f
commit
13ceac4a83
6 changed files with 523 additions and 453 deletions
|
|
@ -2,6 +2,7 @@ version: 2
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
parallelism: 2
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/node:10
|
- image: circleci/node:10
|
||||||
steps:
|
steps:
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ module.exports = {
|
||||||
generations: require('./lib/generations'),
|
generations: require('./lib/generations'),
|
||||||
experience: require('./lib/experience'),
|
experience: require('./lib/experience'),
|
||||||
UserError: require('./lib/user_error'),
|
UserError: require('./lib/user_error'),
|
||||||
portal_detector: require('./lib/portal_detector')
|
portal_detector: require('./lib/portal_detector'),
|
||||||
|
supportedVersions
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMCServer (options) {
|
function createMCServer (options) {
|
||||||
|
|
|
||||||
31
test/common/parallel.js
Normal file
31
test/common/parallel.js
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
const nodeIndex = parseInt(process.env.CIRCLE_NODE_INDEX)
|
||||||
|
const nodeTotal = parseInt(process.env.CIRCLE_NODE_TOTAL)
|
||||||
|
const parallel = process.env.CIRCLE_NODE_INDEX !== undefined && process.env.CIRCLE_NODE_TOTAL !== undefined
|
||||||
|
const mc = require('../../')
|
||||||
|
|
||||||
|
// expected values :
|
||||||
|
// (0,4,10) -> (0,2)
|
||||||
|
// (1,4,10) -> (3,5)
|
||||||
|
// (2,4,10) -> (6,8)
|
||||||
|
// (3,4,10) -> (9,9)
|
||||||
|
function testedRange (nodeIndex, nodeTotal, numberOfVersions) {
|
||||||
|
const nbFirsts = Math.ceil(numberOfVersions / nodeTotal)
|
||||||
|
if (nodeIndex === (nodeTotal - 1)) {
|
||||||
|
return {
|
||||||
|
firstVersion: nbFirsts * nodeIndex,
|
||||||
|
lastVersion: numberOfVersions - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
firstVersion: nodeIndex * nbFirsts,
|
||||||
|
lastVersion: (nodeIndex + 1) * nbFirsts - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log({ nodeIndex, nodeTotal, versions: mc.supportedVersions.length })
|
||||||
|
const { firstVersion, lastVersion } = parallel ? testedRange(nodeIndex, nodeTotal, mc.supportedVersions.length) : {
|
||||||
|
firstVersion: 0,
|
||||||
|
lastVersion: mc.supportedVersions.length - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { firstVersion, lastVersion }
|
||||||
|
|
@ -4,7 +4,6 @@ const squid = require('flying-squid')
|
||||||
const settings = require('../config/default-settings')
|
const settings = require('../config/default-settings')
|
||||||
const mineflayer = require('mineflayer')
|
const mineflayer = require('mineflayer')
|
||||||
const { Vec3 } = require('vec3')
|
const { Vec3 } = require('vec3')
|
||||||
const Item = require('prismarine-item')('1.8')
|
|
||||||
|
|
||||||
function assertPosEqual (actual, expected) {
|
function assertPosEqual (actual, expected) {
|
||||||
expect(actual.distanceTo(expected)).toBeLessThan(1)
|
expect(actual.distanceTo(expected)).toBeLessThan(1)
|
||||||
|
|
@ -12,228 +11,243 @@ function assertPosEqual (actual, expected) {
|
||||||
|
|
||||||
const once = require('event-promise')
|
const once = require('event-promise')
|
||||||
|
|
||||||
describe('server with mineflayer connection', () => {
|
const { firstVersion, lastVersion } = require('./common/parallel')
|
||||||
jest.setTimeout(60 * 1000)
|
|
||||||
let bot
|
|
||||||
let bot2
|
|
||||||
let serv
|
|
||||||
|
|
||||||
async function onGround (bot) {
|
squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
await new Promise((resolve) => {
|
if (!(i >= firstVersion && i <= lastVersion)) {
|
||||||
const l = () => {
|
return
|
||||||
if (bot.entity.onGround) {
|
|
||||||
bot.removeListener('move', l)
|
|
||||||
resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bot.on('move', l)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function waitMessage (bot, message) {
|
const mcData = require('minecraft-data')(supportedVersion)
|
||||||
const msg1 = await once(bot, 'message')
|
const version = mcData.version
|
||||||
expect(msg1.extra[0].text).toEqual(message)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function waitMessages (bot, messages) {
|
const Item = require('prismarine-item')(supportedVersion)
|
||||||
const toReceive = messages.reduce((acc, message) => {
|
|
||||||
acc[message] = 1
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
const received = {}
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const listener = msg => {
|
|
||||||
const message = msg.extra[0].text
|
|
||||||
if (!toReceive[message]) throw new Error('Received ' + message + ' , expected to receive one of ' + messages)
|
|
||||||
if (received[message]) throw new Error('Received ' + message + ' two times')
|
|
||||||
received[message] = 1
|
|
||||||
if (Object.keys(received).length === messages.length) {
|
|
||||||
bot.removeListener('message', listener)
|
|
||||||
resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bot.on('message', listener)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function waitLoginMessage (bot) {
|
describe('server with mineflayer connection ' + version.minecraftVersion, () => {
|
||||||
return Promise.all([waitMessages(bot, ['bot joined the game.', 'bot2 joined the game.'])])
|
jest.setTimeout(60 * 1000)
|
||||||
}
|
let bot
|
||||||
|
let bot2
|
||||||
|
let serv
|
||||||
|
|
||||||
beforeEach(async () => {
|
async function onGround (bot) {
|
||||||
const options = settings
|
await new Promise((resolve) => {
|
||||||
options['online-mode'] = false
|
const l = () => {
|
||||||
options['port'] = 25566
|
if (bot.entity.onGround) {
|
||||||
options['view-distance'] = 2
|
bot.removeListener('move', l)
|
||||||
options['worldFolder'] = undefined
|
|
||||||
options['logging'] = false
|
|
||||||
|
|
||||||
serv = squid.createMCServer(options)
|
|
||||||
|
|
||||||
await once(serv, 'listening')
|
|
||||||
bot = mineflayer.createBot({
|
|
||||||
host: 'localhost',
|
|
||||||
port: 25566,
|
|
||||||
username: 'bot',
|
|
||||||
version: '1.8'
|
|
||||||
})
|
|
||||||
bot2 = mineflayer.createBot({
|
|
||||||
host: 'localhost',
|
|
||||||
port: 25566,
|
|
||||||
username: 'bot2',
|
|
||||||
version: '1.8'
|
|
||||||
})
|
|
||||||
|
|
||||||
await Promise.all([once(bot, 'login'), once(bot2, 'login')])
|
|
||||||
bot.entity.onGround = false
|
|
||||||
bot2.entity.onGround = false
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await serv.quit()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('actions', () => {
|
|
||||||
function waitSpawnZone (bot, view) {
|
|
||||||
const nbChunksExpected = (view * 2) * (view * 2)
|
|
||||||
let c = 0
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const listener = () => {
|
|
||||||
c++
|
|
||||||
if (c === nbChunksExpected) {
|
|
||||||
bot.removeListener('chunkColumnLoad', listener)
|
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bot.on('chunkColumnLoad', listener)
|
bot.on('move', l)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
test('can dig', async () => {
|
async function waitMessage (bot, message) {
|
||||||
await Promise.all([waitSpawnZone(bot, 2), waitSpawnZone(bot2, 2), onGround(bot), onGround(bot2)])
|
const msg1 = await once(bot, 'message')
|
||||||
|
expect(msg1.extra[0].text).toEqual(message)
|
||||||
|
}
|
||||||
|
|
||||||
const pos = bot.entity.position.offset(0, -1, 0).floored()
|
async function waitMessages (bot, messages) {
|
||||||
bot.dig(bot.blockAt(pos))
|
const toReceive = messages.reduce((acc, message) => {
|
||||||
|
acc[message] = 1
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
const received = {}
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const listener = msg => {
|
||||||
|
const message = msg.extra[0].text
|
||||||
|
if (!toReceive[message]) throw new Error('Received ' + message + ' , expected to receive one of ' + messages)
|
||||||
|
if (received[message]) throw new Error('Received ' + message + ' two times')
|
||||||
|
received[message] = 1
|
||||||
|
if (Object.keys(received).length === messages.length) {
|
||||||
|
bot.removeListener('message', listener)
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bot.on('message', listener)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
let [, newBlock] = await once(bot2, 'blockUpdate', {array: true})
|
async function waitLoginMessage (bot) {
|
||||||
assertPosEqual(newBlock.position, pos)
|
return Promise.all([waitMessages(bot, ['bot joined the game.', 'bot2 joined the game.'])])
|
||||||
expect(newBlock.type).toEqual(0)
|
}
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const PORT = Math.round(30000 + Math.random() * 20000)
|
||||||
|
const options = settings
|
||||||
|
options['online-mode'] = false
|
||||||
|
options['port'] = PORT
|
||||||
|
options['view-distance'] = 2
|
||||||
|
options['worldFolder'] = undefined
|
||||||
|
options['logging'] = false
|
||||||
|
options['version'] = version.minecraftVersion
|
||||||
|
|
||||||
|
serv = squid.createMCServer(options)
|
||||||
|
|
||||||
|
await once(serv, 'listening')
|
||||||
|
bot = mineflayer.createBot({
|
||||||
|
host: 'localhost',
|
||||||
|
port: PORT,
|
||||||
|
username: 'bot',
|
||||||
|
version: version.minecraftVersion
|
||||||
|
})
|
||||||
|
bot2 = mineflayer.createBot({
|
||||||
|
host: 'localhost',
|
||||||
|
port: PORT,
|
||||||
|
username: 'bot2',
|
||||||
|
version: version.minecraftVersion
|
||||||
|
})
|
||||||
|
|
||||||
|
await Promise.all([once(bot, 'login'), once(bot2, 'login')])
|
||||||
|
bot.entity.onGround = false
|
||||||
|
bot2.entity.onGround = false
|
||||||
})
|
})
|
||||||
|
|
||||||
test('can place a block', async () => {
|
afterEach(async () => {
|
||||||
await Promise.all([waitSpawnZone(bot, 2), waitSpawnZone(bot2, 2), onGround(bot), onGround(bot2)])
|
await serv.quit()
|
||||||
|
})
|
||||||
|
|
||||||
const pos = bot.entity.position.offset(0, -2, 0).floored()
|
describe('actions', () => {
|
||||||
bot.dig(bot.blockAt(pos))
|
function waitSpawnZone (bot, view) {
|
||||||
|
const nbChunksExpected = (view * 2) * (view * 2)
|
||||||
|
let c = 0
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const listener = () => {
|
||||||
|
c++
|
||||||
|
if (c === nbChunksExpected) {
|
||||||
|
bot.removeListener('chunkColumnLoad', listener)
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bot.on('chunkColumnLoad', listener)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
let [, newBlock] = await once(bot2, 'blockUpdate', {array: true})
|
test('can dig', async () => {
|
||||||
assertPosEqual(newBlock.position, pos)
|
await Promise.all([waitSpawnZone(bot, 2), waitSpawnZone(bot2, 2), onGround(bot), onGround(bot2)])
|
||||||
expect(newBlock.type).toEqual(0)
|
|
||||||
|
|
||||||
bot.creative.setInventorySlot(36, new Item(1, 1))
|
const pos = bot.entity.position.offset(0, -1, 0).floored()
|
||||||
await new Promise((resolve) => {
|
bot.dig(bot.blockAt(pos))
|
||||||
bot.inventory.on('windowUpdate', (slot, oldItem, newItem) => {
|
|
||||||
if (slot === 36 && newItem && newItem.type === 1) { resolve() }
|
let [, newBlock] = await once(bot2, 'blockUpdate', {array: true})
|
||||||
|
assertPosEqual(newBlock.position, pos)
|
||||||
|
expect(newBlock.type).toEqual(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can place a block', async () => {
|
||||||
|
await Promise.all([waitSpawnZone(bot, 2), waitSpawnZone(bot2, 2), onGround(bot), onGround(bot2)])
|
||||||
|
|
||||||
|
const pos = bot.entity.position.offset(0, -2, 0).floored()
|
||||||
|
bot.dig(bot.blockAt(pos))
|
||||||
|
|
||||||
|
let [, newBlock] = await once(bot2, 'blockUpdate', {array: true})
|
||||||
|
assertPosEqual(newBlock.position, pos)
|
||||||
|
expect(newBlock.type).toEqual(0)
|
||||||
|
|
||||||
|
bot.creative.setInventorySlot(36, new Item(1, 1))
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
bot.inventory.on('windowUpdate', (slot, oldItem, newItem) => {
|
||||||
|
if (slot === 36 && newItem && newItem.type === 1) { resolve() }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
bot.placeBlock(bot.blockAt(pos.offset(0, -1, 0)), new Vec3(0, 1, 0));
|
||||||
|
|
||||||
|
[, newBlock] = await once(bot2, 'blockUpdate', {array: true})
|
||||||
|
assertPosEqual(newBlock.position, pos)
|
||||||
|
expect(newBlock.type).toEqual(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('commands', () => {
|
||||||
|
jest.setTimeout(10 * 1000)
|
||||||
|
test('has an help command', async () => {
|
||||||
|
await waitLoginMessage(bot)
|
||||||
|
bot.chat('/help')
|
||||||
|
await once(bot, 'message')
|
||||||
|
})
|
||||||
|
test('can use /particle', async () => {
|
||||||
|
bot.chat('/particle 5 10 100 100 100')
|
||||||
|
await once(bot._client, 'world_particles')
|
||||||
|
})
|
||||||
|
test('can use /playsound', async () => {
|
||||||
|
bot.chat('/playsound ambient.weather.rain')
|
||||||
|
await once(bot, 'soundEffectHeard')
|
||||||
|
})
|
||||||
|
|
||||||
|
function waitDragon () {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const listener = (entity) => {
|
||||||
|
if (entity.name === 'EnderDragon') {
|
||||||
|
bot.removeListener('entitySpawn', listener)
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bot.on('entitySpawn', listener)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
test('can use /summon', async () => {
|
||||||
|
bot.chat('/summon EnderDragon')
|
||||||
|
await waitDragon()
|
||||||
|
})
|
||||||
|
test('can use /kill', async () => {
|
||||||
|
bot.chat('/summon EnderDragon')
|
||||||
|
await waitDragon()
|
||||||
|
bot.chat('/kill @e[type=EnderDragon]')
|
||||||
|
const entity = await once(bot, 'entityDead')
|
||||||
|
expect(entity.name).toEqual('EnderDragon')
|
||||||
|
})
|
||||||
|
describe('can use /tp', () => {
|
||||||
|
test('can tp myself', async () => {
|
||||||
|
bot.chat('/tp 2 3 4')
|
||||||
|
await once(bot, 'forcedMove')
|
||||||
|
assertPosEqual(bot.entity.position, new Vec3(2, 3, 4))
|
||||||
|
})
|
||||||
|
test('can tp somebody else', async () => {
|
||||||
|
bot.chat('/tp bot2 2 3 4')
|
||||||
|
await once(bot2, 'forcedMove')
|
||||||
|
assertPosEqual(bot2.entity.position, new Vec3(2, 3, 4))
|
||||||
|
})
|
||||||
|
test('can tp to somebody else', async () => {
|
||||||
|
await onGround(bot)
|
||||||
|
bot.chat('/tp bot2 bot')
|
||||||
|
await once(bot2, 'forcedMove')
|
||||||
|
assertPosEqual(bot2.entity.position, bot.entity.position)
|
||||||
|
})
|
||||||
|
test('can tp with relative positions', async () => {
|
||||||
|
await onGround(bot)
|
||||||
|
const initialPosition = bot.entity.position.clone()
|
||||||
|
bot.chat('/tp ~1 ~-2 ~3')
|
||||||
|
await once(bot, 'forcedMove')
|
||||||
|
assertPosEqual(bot.entity.position, initialPosition.offset(1, -2, 3))
|
||||||
|
})
|
||||||
|
test('can tp somebody else with relative positions', async () => {
|
||||||
|
await Promise.all([onGround(bot), onGround(bot2)])
|
||||||
|
const initialPosition = bot2.entity.position.clone()
|
||||||
|
bot.chat('/tp bot2 ~1 ~-2 ~3')
|
||||||
|
await once(bot2, 'forcedMove')
|
||||||
|
assertPosEqual(bot2.entity.position, initialPosition.offset(1, -2, 3))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
test('can use /deop', async () => {
|
||||||
bot.placeBlock(bot.blockAt(pos.offset(0, -1, 0)), new Vec3(0, 1, 0));
|
await waitLoginMessage(bot)
|
||||||
|
bot.chat('/deop bot')
|
||||||
[, newBlock] = await once(bot2, 'blockUpdate', {array: true})
|
await waitMessage(bot, 'bot is deopped')
|
||||||
assertPosEqual(newBlock.position, pos)
|
bot.chat('/op bot')
|
||||||
expect(newBlock.type).toEqual(1)
|
await waitMessage(bot, 'You do not have permission to use this command')
|
||||||
})
|
serv.getPlayer('bot').op = true
|
||||||
})
|
|
||||||
|
|
||||||
describe('commands', () => {
|
|
||||||
jest.setTimeout(10 * 1000)
|
|
||||||
test('has an help command', async () => {
|
|
||||||
await waitLoginMessage(bot)
|
|
||||||
bot.chat('/help')
|
|
||||||
await once(bot, 'message')
|
|
||||||
})
|
|
||||||
test('can use /particle', async () => {
|
|
||||||
bot.chat('/particle 5 10 100 100 100')
|
|
||||||
await once(bot._client, 'world_particles')
|
|
||||||
})
|
|
||||||
test('can use /playsound', async () => {
|
|
||||||
bot.chat('/playsound ambient.weather.rain')
|
|
||||||
await once(bot, 'soundEffectHeard')
|
|
||||||
})
|
|
||||||
|
|
||||||
function waitDragon () {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const listener = (entity) => {
|
|
||||||
if (entity.name === 'EnderDragon') {
|
|
||||||
bot.removeListener('entitySpawn', listener)
|
|
||||||
resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bot.on('entitySpawn', listener)
|
|
||||||
})
|
})
|
||||||
}
|
test('can use /setblock', async () => {
|
||||||
|
await once(bot, 'chunkColumnLoad')
|
||||||
test('can use /summon', async () => {
|
bot.chat('/setblock 1 2 3 95 0')
|
||||||
bot.chat('/summon EnderDragon')
|
let [, newBlock] = await once(bot, 'blockUpdate:' + new Vec3(1, 2, 3), {array: true})
|
||||||
await waitDragon()
|
expect(newBlock.type).toEqual(95)
|
||||||
})
|
|
||||||
test('can use /kill', async () => {
|
|
||||||
bot.chat('/summon EnderDragon')
|
|
||||||
await waitDragon()
|
|
||||||
bot.chat('/kill @e[type=EnderDragon]')
|
|
||||||
const entity = await once(bot, 'entityDead')
|
|
||||||
expect(entity.name).toEqual('EnderDragon')
|
|
||||||
})
|
|
||||||
describe('can use /tp', () => {
|
|
||||||
test('can tp myself', async () => {
|
|
||||||
bot.chat('/tp 2 3 4')
|
|
||||||
await once(bot, 'forcedMove')
|
|
||||||
assertPosEqual(bot.entity.position, new Vec3(2, 3, 4))
|
|
||||||
})
|
})
|
||||||
test('can tp somebody else', async () => {
|
test('can use /xp', async () => {
|
||||||
bot.chat('/tp bot2 2 3 4')
|
bot.chat('/xp 100')
|
||||||
await once(bot2, 'forcedMove')
|
await once(bot, 'experience')
|
||||||
assertPosEqual(bot2.entity.position, new Vec3(2, 3, 4))
|
expect(bot.experience.points).toEqual(100)
|
||||||
})
|
})
|
||||||
test('can tp to somebody else', async () => {
|
|
||||||
await onGround(bot)
|
|
||||||
bot.chat('/tp bot2 bot')
|
|
||||||
await once(bot2, 'forcedMove')
|
|
||||||
assertPosEqual(bot2.entity.position, bot.entity.position)
|
|
||||||
})
|
|
||||||
test('can tp with relative positions', async () => {
|
|
||||||
await onGround(bot)
|
|
||||||
const initialPosition = bot.entity.position.clone()
|
|
||||||
bot.chat('/tp ~1 ~-2 ~3')
|
|
||||||
await once(bot, 'forcedMove')
|
|
||||||
assertPosEqual(bot.entity.position, initialPosition.offset(1, -2, 3))
|
|
||||||
})
|
|
||||||
test('can tp somebody else with relative positions', async () => {
|
|
||||||
await Promise.all([onGround(bot), onGround(bot2)])
|
|
||||||
const initialPosition = bot2.entity.position.clone()
|
|
||||||
bot.chat('/tp bot2 ~1 ~-2 ~3')
|
|
||||||
await once(bot2, 'forcedMove')
|
|
||||||
assertPosEqual(bot2.entity.position, initialPosition.offset(1, -2, 3))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
test('can use /deop', async () => {
|
|
||||||
await waitLoginMessage(bot)
|
|
||||||
bot.chat('/deop bot')
|
|
||||||
await waitMessage(bot, 'bot is deopped')
|
|
||||||
bot.chat('/op bot')
|
|
||||||
await waitMessage(bot, 'You do not have permission to use this command')
|
|
||||||
serv.getPlayer('bot').op = true
|
|
||||||
})
|
|
||||||
test('can use /setblock', async () => {
|
|
||||||
await once(bot, 'chunkColumnLoad')
|
|
||||||
bot.chat('/setblock 1 2 3 95 0')
|
|
||||||
let [, newBlock] = await once(bot, 'blockUpdate:' + new Vec3(1, 2, 3), {array: true})
|
|
||||||
expect(newBlock.type).toEqual(95)
|
|
||||||
})
|
|
||||||
test('can use /xp', async () => {
|
|
||||||
bot.chat('/xp 100')
|
|
||||||
await once(bot, 'experience')
|
|
||||||
expect(bot.experience.points).toEqual(100)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,250 +1,260 @@
|
||||||
/* eslint-env jest */
|
/* eslint-env jest */
|
||||||
|
|
||||||
const {
|
const squid = require('flying-squid')
|
||||||
detectFrame,
|
const { firstVersion, lastVersion } = require('./common/parallel')
|
||||||
findPotentialLines,
|
|
||||||
findBorder,
|
|
||||||
getAir,
|
|
||||||
generateLine,
|
|
||||||
generatePortal,
|
|
||||||
makeWorldWithPortal
|
|
||||||
} = require('flying-squid').portal_detector('1.8')
|
|
||||||
|
|
||||||
const { Vec3 } = require('vec3')
|
squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
|
if (!(i >= firstVersion && i <= lastVersion)) return
|
||||||
|
|
||||||
describe('generate portal', () => {
|
const mcData = require('minecraft-data')(supportedVersion)
|
||||||
test('generate a line', () => {
|
const version = mcData.version
|
||||||
expect(generateLine(new Vec3(3, 1, 1), new Vec3(1, 0, 0), 2)).toEqual([new Vec3(3, 1, 1), new Vec3(4, 1, 1)])
|
|
||||||
})
|
|
||||||
|
|
||||||
test('generate a portal', () => {
|
const {
|
||||||
expect(generatePortal(new Vec3(2, 1, 1), new Vec3(1, 0, 0), 4, 5)).toEqual({
|
detectFrame,
|
||||||
bottom: generateLine(new Vec3(3, 1, 1), new Vec3(1, 0, 0), 2),
|
findPotentialLines,
|
||||||
left: generateLine(new Vec3(2, 2, 1), new Vec3(0, 1, 0), 3),
|
findBorder,
|
||||||
right: generateLine(new Vec3(5, 2, 1), new Vec3(0, 1, 0), 3),
|
getAir,
|
||||||
top: generateLine(new Vec3(3, 5, 1), new Vec3(1, 0, 0), 2),
|
generateLine,
|
||||||
air: generateLine(new Vec3(3, 2, 1), new Vec3(0, 1, 0), 3).concat(generateLine(new Vec3(4, 2, 1), new Vec3(0, 1, 0), 3))
|
generatePortal,
|
||||||
|
makeWorldWithPortal
|
||||||
|
} = squid.portal_detector(version.minecraftVersion)
|
||||||
|
|
||||||
|
const { Vec3 } = require('vec3')
|
||||||
|
|
||||||
|
describe('generate portal ' + version.minecraftVersion, () => {
|
||||||
|
test('generate a line', () => {
|
||||||
|
expect(generateLine(new Vec3(3, 1, 1), new Vec3(1, 0, 0), 2)).toEqual([new Vec3(3, 1, 1), new Vec3(4, 1, 1)])
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('detect portal', () => {
|
test('generate a portal', () => {
|
||||||
jest.setTimeout(60 * 1000)
|
expect(generatePortal(new Vec3(2, 1, 1), new Vec3(1, 0, 0), 4, 5)).toEqual({
|
||||||
const portalData = []
|
bottom: generateLine(new Vec3(3, 1, 1), new Vec3(1, 0, 0), 2),
|
||||||
|
left: generateLine(new Vec3(2, 2, 1), new Vec3(0, 1, 0), 3),
|
||||||
portalData.push({
|
right: generateLine(new Vec3(5, 2, 1), new Vec3(0, 1, 0), 3),
|
||||||
name: 'simple portal frame x',
|
top: generateLine(new Vec3(3, 5, 1), new Vec3(1, 0, 0), 2),
|
||||||
bottomLeft: new Vec3(2, 1, 1),
|
air: generateLine(new Vec3(3, 2, 1), new Vec3(0, 1, 0), 3).concat(generateLine(new Vec3(4, 2, 1), new Vec3(0, 1, 0), 3))
|
||||||
direction: new Vec3(1, 0, 0),
|
|
||||||
width: 4,
|
|
||||||
height: 5,
|
|
||||||
additionalAir: [],
|
|
||||||
additionalObsidian: []
|
|
||||||
})
|
|
||||||
|
|
||||||
portalData.push({
|
|
||||||
name: 'simple portal frame z',
|
|
||||||
bottomLeft: new Vec3(2, 1, 1),
|
|
||||||
direction: new Vec3(0, 0, 1),
|
|
||||||
width: 4,
|
|
||||||
height: 5,
|
|
||||||
additionalAir: [],
|
|
||||||
additionalObsidian: []
|
|
||||||
})
|
|
||||||
|
|
||||||
portalData.push({
|
|
||||||
name: 'big simple portal frame x',
|
|
||||||
bottomLeft: new Vec3(2, 1, 1),
|
|
||||||
direction: new Vec3(1, 0, 0),
|
|
||||||
width: 10,
|
|
||||||
height: 10,
|
|
||||||
additionalAir: [],
|
|
||||||
additionalObsidian: []
|
|
||||||
})
|
|
||||||
|
|
||||||
portalData.push({
|
|
||||||
name: 'simple portal frame x with borders',
|
|
||||||
bottomLeft: new Vec3(2, 1, 1),
|
|
||||||
direction: new Vec3(1, 0, 0),
|
|
||||||
width: 4,
|
|
||||||
height: 5,
|
|
||||||
additionalAir: [],
|
|
||||||
additionalObsidian: [new Vec3(2, 1, 1), new Vec3(5, 1, 1), new Vec3(2, 6, 1), new Vec3(5, 6, 1)]
|
|
||||||
})
|
|
||||||
|
|
||||||
const {bottom, left, right, top, air} = generatePortal(new Vec3(2, 1, 2), new Vec3(1, 0, 0), 4, 5)
|
|
||||||
|
|
||||||
portalData.push({
|
|
||||||
name: '2 portals',
|
|
||||||
bottomLeft: new Vec3(2, 1, 1),
|
|
||||||
direction: new Vec3(1, 0, 0),
|
|
||||||
width: 4,
|
|
||||||
height: 5,
|
|
||||||
additionalAir: air,
|
|
||||||
additionalObsidian: [].concat([], [bottom, left, right, top])
|
|
||||||
})
|
|
||||||
|
|
||||||
portalData.push({
|
|
||||||
name: 'huge simple portal frame z',
|
|
||||||
bottomLeft: new Vec3(2, 1, 1),
|
|
||||||
direction: new Vec3(0, 0, 1),
|
|
||||||
width: 50,
|
|
||||||
height: 50,
|
|
||||||
additionalAir: [],
|
|
||||||
additionalObsidian: []
|
|
||||||
})
|
|
||||||
|
|
||||||
portalData.forEach(({name, bottomLeft, direction, width, height, additionalAir, additionalObsidian}) => {
|
|
||||||
const portal = generatePortal(bottomLeft, direction, width, height)
|
|
||||||
const {bottom, left, right, top, air} = portal
|
|
||||||
describe('Detect ' + name, () => {
|
|
||||||
const expectedBorder = {bottom, left, right, top}
|
|
||||||
|
|
||||||
let world
|
|
||||||
beforeAll(async function () {
|
|
||||||
world = await makeWorldWithPortal(portal, additionalAir, additionalObsidian)
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('detect potential first lines', () => {
|
|
||||||
test('detect potential first lines from bottom left', async () => {
|
|
||||||
let potentialLines = await findPotentialLines(world, bottom[0], new Vec3(0, 1, 0))
|
|
||||||
expect(potentialLines).toContainEqual({
|
|
||||||
'direction': direction,
|
|
||||||
'line': bottom
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('detect potential first lines from bottom right', async () => {
|
|
||||||
let potentialLines = await findPotentialLines(world, bottom[bottom.length - 1], new Vec3(0, 1, 0))
|
|
||||||
expect(potentialLines).toContainEqual({
|
|
||||||
'direction': direction,
|
|
||||||
'line': bottom
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('detect potential first lines from top left', async () => {
|
|
||||||
let potentialLines = await findPotentialLines(world, top[0], new Vec3(0, -1, 0))
|
|
||||||
expect(potentialLines).toContainEqual({
|
|
||||||
'direction': direction,
|
|
||||||
'line': top
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('detect potential first lines from top right', async () => {
|
|
||||||
let potentialLines = await findPotentialLines(world, top[top.length - 1], new Vec3(0, -1, 0))
|
|
||||||
expect(potentialLines).toContainEqual({
|
|
||||||
'direction': direction,
|
|
||||||
'line': top
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('detect potential first lines from left top', async () => {
|
|
||||||
let potentialLines = await findPotentialLines(world, left[left.length - 1], direction)
|
|
||||||
expect(potentialLines).toEqual([{
|
|
||||||
'direction': new Vec3(0, 1, 0),
|
|
||||||
'line': left
|
|
||||||
}])
|
|
||||||
})
|
|
||||||
|
|
||||||
test('detect potential first lines from right bottom', async () => {
|
|
||||||
let potentialLines = await findPotentialLines(world, right[0], direction.scaled(-1))
|
|
||||||
expect(potentialLines).toEqual([{
|
|
||||||
'direction': new Vec3(0, 1, 0),
|
|
||||||
'line': right
|
|
||||||
}])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('find borders', () => {
|
|
||||||
test('find borders from bottom', async () => {
|
|
||||||
const border = await findBorder(world, {
|
|
||||||
'direction': direction,
|
|
||||||
'line': bottom
|
|
||||||
}, new Vec3(0, 1, 0))
|
|
||||||
expect(border).toEqual(expectedBorder)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('find borders from top', async () => {
|
|
||||||
const border = await findBorder(world, {
|
|
||||||
'direction': direction,
|
|
||||||
'line': top
|
|
||||||
}, new Vec3(0, -1, 0))
|
|
||||||
expect(border).toEqual(expectedBorder)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('find borders from left', async () => {
|
|
||||||
const border = await findBorder(world, {
|
|
||||||
'direction': new Vec3(0, 1, 0),
|
|
||||||
'line': left
|
|
||||||
}, direction)
|
|
||||||
expect(border).toEqual(expectedBorder)
|
|
||||||
})
|
|
||||||
test('find borders from right', async () => {
|
|
||||||
const border = await findBorder(world, {
|
|
||||||
'direction': new Vec3(0, 1, 0),
|
|
||||||
'line': right
|
|
||||||
}, direction.scaled(-1))
|
|
||||||
expect(border).toEqual(expectedBorder)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('detect portals', () => {
|
|
||||||
test('detect portals from bottom left', async () => {
|
|
||||||
const portals = await detectFrame(world, bottom[0], new Vec3(0, 1, 0))
|
|
||||||
expect(portals).toEqual([portal])
|
|
||||||
})
|
|
||||||
test('detect portals from top left', async () => {
|
|
||||||
const portals = await detectFrame(world, top[0], new Vec3(0, -1, 0))
|
|
||||||
expect(portals).toEqual([portal])
|
|
||||||
})
|
|
||||||
test('detect portals from right top', async () => {
|
|
||||||
const portals = await detectFrame(world, right[right.length - 1], direction.scaled(-1))
|
|
||||||
expect(portals).toEqual([portal])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('get air', () => {
|
|
||||||
const foundAir = getAir(expectedBorder)
|
|
||||||
expect(foundAir).toEqual(air)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
describe("doesn't detect non-portal", () => {
|
describe('detect portal ' + version.minecraftVersion, () => {
|
||||||
const portalData = []
|
jest.setTimeout(60 * 1000)
|
||||||
|
const portalData = []
|
||||||
|
|
||||||
portalData.push({
|
portalData.push({
|
||||||
name: 'simple portal frame x with one obsidian in the middle',
|
name: 'simple portal frame x',
|
||||||
bottomLeft: new Vec3(2, 1, 1),
|
bottomLeft: new Vec3(2, 1, 1),
|
||||||
direction: new Vec3(1, 0, 0),
|
direction: new Vec3(1, 0, 0),
|
||||||
width: 5,
|
width: 4,
|
||||||
height: 5,
|
height: 5,
|
||||||
additionalAir: [],
|
additionalAir: [],
|
||||||
additionalObsidian: [new Vec3(4, 3, 1)]
|
additionalObsidian: []
|
||||||
|
})
|
||||||
|
|
||||||
|
portalData.push({
|
||||||
|
name: 'simple portal frame z',
|
||||||
|
bottomLeft: new Vec3(2, 1, 1),
|
||||||
|
direction: new Vec3(0, 0, 1),
|
||||||
|
width: 4,
|
||||||
|
height: 5,
|
||||||
|
additionalAir: [],
|
||||||
|
additionalObsidian: []
|
||||||
|
})
|
||||||
|
|
||||||
|
portalData.push({
|
||||||
|
name: 'big simple portal frame x',
|
||||||
|
bottomLeft: new Vec3(2, 1, 1),
|
||||||
|
direction: new Vec3(1, 0, 0),
|
||||||
|
width: 10,
|
||||||
|
height: 10,
|
||||||
|
additionalAir: [],
|
||||||
|
additionalObsidian: []
|
||||||
|
})
|
||||||
|
|
||||||
|
portalData.push({
|
||||||
|
name: 'simple portal frame x with borders',
|
||||||
|
bottomLeft: new Vec3(2, 1, 1),
|
||||||
|
direction: new Vec3(1, 0, 0),
|
||||||
|
width: 4,
|
||||||
|
height: 5,
|
||||||
|
additionalAir: [],
|
||||||
|
additionalObsidian: [new Vec3(2, 1, 1), new Vec3(5, 1, 1), new Vec3(2, 6, 1), new Vec3(5, 6, 1)]
|
||||||
|
})
|
||||||
|
|
||||||
|
const {bottom, left, right, top, air} = generatePortal(new Vec3(2, 1, 2), new Vec3(1, 0, 0), 4, 5)
|
||||||
|
|
||||||
|
portalData.push({
|
||||||
|
name: '2 portals',
|
||||||
|
bottomLeft: new Vec3(2, 1, 1),
|
||||||
|
direction: new Vec3(1, 0, 0),
|
||||||
|
width: 4,
|
||||||
|
height: 5,
|
||||||
|
additionalAir: air,
|
||||||
|
additionalObsidian: [].concat([], [bottom, left, right, top])
|
||||||
|
})
|
||||||
|
|
||||||
|
portalData.push({
|
||||||
|
name: 'huge simple portal frame z',
|
||||||
|
bottomLeft: new Vec3(2, 1, 1),
|
||||||
|
direction: new Vec3(0, 0, 1),
|
||||||
|
width: 50,
|
||||||
|
height: 50,
|
||||||
|
additionalAir: [],
|
||||||
|
additionalObsidian: []
|
||||||
|
})
|
||||||
|
|
||||||
|
portalData.forEach(({name, bottomLeft, direction, width, height, additionalAir, additionalObsidian}) => {
|
||||||
|
const portal = generatePortal(bottomLeft, direction, width, height)
|
||||||
|
const {bottom, left, right, top, air} = portal
|
||||||
|
describe('Detect ' + name, () => {
|
||||||
|
const expectedBorder = {bottom, left, right, top}
|
||||||
|
|
||||||
|
let world
|
||||||
|
beforeAll(async function () {
|
||||||
|
world = await makeWorldWithPortal(portal, additionalAir, additionalObsidian)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('detect potential first lines', () => {
|
||||||
|
test('detect potential first lines from bottom left', async () => {
|
||||||
|
let potentialLines = await findPotentialLines(world, bottom[0], new Vec3(0, 1, 0))
|
||||||
|
expect(potentialLines).toContainEqual({
|
||||||
|
'direction': direction,
|
||||||
|
'line': bottom
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('detect potential first lines from bottom right', async () => {
|
||||||
|
let potentialLines = await findPotentialLines(world, bottom[bottom.length - 1], new Vec3(0, 1, 0))
|
||||||
|
expect(potentialLines).toContainEqual({
|
||||||
|
'direction': direction,
|
||||||
|
'line': bottom
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('detect potential first lines from top left', async () => {
|
||||||
|
let potentialLines = await findPotentialLines(world, top[0], new Vec3(0, -1, 0))
|
||||||
|
expect(potentialLines).toContainEqual({
|
||||||
|
'direction': direction,
|
||||||
|
'line': top
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('detect potential first lines from top right', async () => {
|
||||||
|
let potentialLines = await findPotentialLines(world, top[top.length - 1], new Vec3(0, -1, 0))
|
||||||
|
expect(potentialLines).toContainEqual({
|
||||||
|
'direction': direction,
|
||||||
|
'line': top
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('detect potential first lines from left top', async () => {
|
||||||
|
let potentialLines = await findPotentialLines(world, left[left.length - 1], direction)
|
||||||
|
expect(potentialLines).toEqual([{
|
||||||
|
'direction': new Vec3(0, 1, 0),
|
||||||
|
'line': left
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('detect potential first lines from right bottom', async () => {
|
||||||
|
let potentialLines = await findPotentialLines(world, right[0], direction.scaled(-1))
|
||||||
|
expect(potentialLines).toEqual([{
|
||||||
|
'direction': new Vec3(0, 1, 0),
|
||||||
|
'line': right
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('find borders', () => {
|
||||||
|
test('find borders from bottom', async () => {
|
||||||
|
const border = await findBorder(world, {
|
||||||
|
'direction': direction,
|
||||||
|
'line': bottom
|
||||||
|
}, new Vec3(0, 1, 0))
|
||||||
|
expect(border).toEqual(expectedBorder)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('find borders from top', async () => {
|
||||||
|
const border = await findBorder(world, {
|
||||||
|
'direction': direction,
|
||||||
|
'line': top
|
||||||
|
}, new Vec3(0, -1, 0))
|
||||||
|
expect(border).toEqual(expectedBorder)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('find borders from left', async () => {
|
||||||
|
const border = await findBorder(world, {
|
||||||
|
'direction': new Vec3(0, 1, 0),
|
||||||
|
'line': left
|
||||||
|
}, direction)
|
||||||
|
expect(border).toEqual(expectedBorder)
|
||||||
|
})
|
||||||
|
test('find borders from right', async () => {
|
||||||
|
const border = await findBorder(world, {
|
||||||
|
'direction': new Vec3(0, 1, 0),
|
||||||
|
'line': right
|
||||||
|
}, direction.scaled(-1))
|
||||||
|
expect(border).toEqual(expectedBorder)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('detect portals', () => {
|
||||||
|
test('detect portals from bottom left', async () => {
|
||||||
|
const portals = await detectFrame(world, bottom[0], new Vec3(0, 1, 0))
|
||||||
|
expect(portals).toEqual([portal])
|
||||||
|
})
|
||||||
|
test('detect portals from top left', async () => {
|
||||||
|
const portals = await detectFrame(world, top[0], new Vec3(0, -1, 0))
|
||||||
|
expect(portals).toEqual([portal])
|
||||||
|
})
|
||||||
|
test('detect portals from right top', async () => {
|
||||||
|
const portals = await detectFrame(world, right[right.length - 1], direction.scaled(-1))
|
||||||
|
expect(portals).toEqual([portal])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('get air', () => {
|
||||||
|
const foundAir = getAir(expectedBorder)
|
||||||
|
expect(foundAir).toEqual(air)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
portalData.forEach(({name, bottomLeft, direction, width, height, additionalAir, additionalObsidian}) => {
|
describe("doesn't detect non-portal " + version.minecraftVersion, () => {
|
||||||
const portal = generatePortal(bottomLeft, direction, width, height)
|
const portalData = []
|
||||||
const {bottom, right, top} = portal
|
|
||||||
describe("doesn't detect detect " + name, () => {
|
|
||||||
let world
|
|
||||||
beforeAll(async function () {
|
|
||||||
world = await makeWorldWithPortal(portal, additionalAir, additionalObsidian)
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("doesn't detect portals", () => {
|
portalData.push({
|
||||||
test("doesn't detect portals from bottom left", async () => {
|
name: 'simple portal frame x with one obsidian in the middle',
|
||||||
const portals = await detectFrame(world, bottom[0], new Vec3(0, 1, 0))
|
bottomLeft: new Vec3(2, 1, 1),
|
||||||
expect(portals).toEqual([])
|
direction: new Vec3(1, 0, 0),
|
||||||
|
width: 5,
|
||||||
|
height: 5,
|
||||||
|
additionalAir: [],
|
||||||
|
additionalObsidian: [new Vec3(4, 3, 1)]
|
||||||
|
})
|
||||||
|
|
||||||
|
portalData.forEach(({name, bottomLeft, direction, width, height, additionalAir, additionalObsidian}) => {
|
||||||
|
const portal = generatePortal(bottomLeft, direction, width, height)
|
||||||
|
const {bottom, right, top} = portal
|
||||||
|
describe("doesn't detect detect " + name, () => {
|
||||||
|
let world
|
||||||
|
beforeAll(async function () {
|
||||||
|
world = await makeWorldWithPortal(portal, additionalAir, additionalObsidian)
|
||||||
})
|
})
|
||||||
test("doesn't detect portals from top left", async () => {
|
|
||||||
const portals = await detectFrame(world, top[0], new Vec3(0, -1, 0))
|
describe("doesn't detect portals", () => {
|
||||||
expect(portals).toEqual([])
|
test("doesn't detect portals from bottom left", async () => {
|
||||||
})
|
const portals = await detectFrame(world, bottom[0], new Vec3(0, 1, 0))
|
||||||
test("doesn't detect portals from right top", async () => {
|
expect(portals).toEqual([])
|
||||||
const portals = await detectFrame(world, right[right.length - 1], direction.scaled(-1))
|
})
|
||||||
expect(portals).toEqual([])
|
test("doesn't detect portals from top left", async () => {
|
||||||
|
const portals = await detectFrame(world, top[0], new Vec3(0, -1, 0))
|
||||||
|
expect(portals).toEqual([])
|
||||||
|
})
|
||||||
|
test("doesn't detect portals from right top", async () => {
|
||||||
|
const portals = await detectFrame(world, right[right.length - 1], direction.scaled(-1))
|
||||||
|
expect(portals).toEqual([])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,33 +5,46 @@ const squid = require('flying-squid')
|
||||||
|
|
||||||
const settings = require('../config/default-settings')
|
const settings = require('../config/default-settings')
|
||||||
|
|
||||||
describe('server', () => {
|
const { firstVersion, lastVersion } = require('./common/parallel')
|
||||||
let serv
|
|
||||||
|
|
||||||
beforeAll(done => {
|
squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||||
const options = settings
|
if (!(i >= firstVersion && i <= lastVersion)) {
|
||||||
options['online-mode'] = false
|
return
|
||||||
options['port'] = 25566
|
}
|
||||||
options['view-distance'] = 2
|
const PORT = Math.round(30000 + Math.random() * 20000)
|
||||||
options['worldFolder'] = undefined
|
|
||||||
options['logging'] = false
|
|
||||||
serv = squid.createMCServer(options)
|
|
||||||
|
|
||||||
serv.on('listening', () => {
|
const mcData = require('minecraft-data')(supportedVersion)
|
||||||
done()
|
const version = mcData.version
|
||||||
|
|
||||||
|
describe(`simple server ${version.minecraftVersion}`, () => {
|
||||||
|
let serv
|
||||||
|
|
||||||
|
beforeAll(done => {
|
||||||
|
const options = settings
|
||||||
|
options['online-mode'] = false
|
||||||
|
options['port'] = PORT
|
||||||
|
options['view-distance'] = 2
|
||||||
|
options['worldFolder'] = undefined
|
||||||
|
options['logging'] = false
|
||||||
|
options['version'] = version.minecraftVersion
|
||||||
|
serv = squid.createMCServer(options)
|
||||||
|
|
||||||
|
serv.on('listening', () => {
|
||||||
|
done()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(done => {
|
afterAll(done => {
|
||||||
serv._server.close()
|
serv._server.close()
|
||||||
serv._server.on('close', () => {
|
serv._server.on('close', () => {
|
||||||
done()
|
done()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
test('is running', done => {
|
test('is running', done => {
|
||||||
const client = net.Socket()
|
const client = net.Socket()
|
||||||
client.connect(serv._server.socketServer.address().port, '127.0.0.1', done)
|
client.connect(serv._server.socketServer.address().port, '127.0.0.1', done)
|
||||||
client.on('error', done)
|
client.on('error', done)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue