mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-10 13:41:03 +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:
|
||||
build:
|
||||
parallelism: 2
|
||||
docker:
|
||||
- image: circleci/node:10
|
||||
steps:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ module.exports = {
|
|||
generations: require('./lib/generations'),
|
||||
experience: require('./lib/experience'),
|
||||
UserError: require('./lib/user_error'),
|
||||
portal_detector: require('./lib/portal_detector')
|
||||
portal_detector: require('./lib/portal_detector'),
|
||||
supportedVersions
|
||||
}
|
||||
|
||||
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 mineflayer = require('mineflayer')
|
||||
const { Vec3 } = require('vec3')
|
||||
const Item = require('prismarine-item')('1.8')
|
||||
|
||||
function assertPosEqual (actual, expected) {
|
||||
expect(actual.distanceTo(expected)).toBeLessThan(1)
|
||||
|
|
@ -12,7 +11,19 @@ function assertPosEqual (actual, expected) {
|
|||
|
||||
const once = require('event-promise')
|
||||
|
||||
describe('server with mineflayer connection', () => {
|
||||
const { firstVersion, lastVersion } = require('./common/parallel')
|
||||
|
||||
squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||
if (!(i >= firstVersion && i <= lastVersion)) {
|
||||
return
|
||||
}
|
||||
|
||||
const mcData = require('minecraft-data')(supportedVersion)
|
||||
const version = mcData.version
|
||||
|
||||
const Item = require('prismarine-item')(supportedVersion)
|
||||
|
||||
describe('server with mineflayer connection ' + version.minecraftVersion, () => {
|
||||
jest.setTimeout(60 * 1000)
|
||||
let bot
|
||||
let bot2
|
||||
|
|
@ -61,27 +72,29 @@ describe('server with mineflayer connection', () => {
|
|||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const PORT = Math.round(30000 + Math.random() * 20000)
|
||||
const options = settings
|
||||
options['online-mode'] = false
|
||||
options['port'] = 25566
|
||||
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: 25566,
|
||||
port: PORT,
|
||||
username: 'bot',
|
||||
version: '1.8'
|
||||
version: version.minecraftVersion
|
||||
})
|
||||
bot2 = mineflayer.createBot({
|
||||
host: 'localhost',
|
||||
port: 25566,
|
||||
port: PORT,
|
||||
username: 'bot2',
|
||||
version: '1.8'
|
||||
version: version.minecraftVersion
|
||||
})
|
||||
|
||||
await Promise.all([once(bot, 'login'), once(bot2, 'login')])
|
||||
|
|
@ -237,3 +250,4 @@ describe('server with mineflayer connection', () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,5 +1,14 @@
|
|||
/* eslint-env jest */
|
||||
|
||||
const squid = require('flying-squid')
|
||||
const { firstVersion, lastVersion } = require('./common/parallel')
|
||||
|
||||
squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||
if (!(i >= firstVersion && i <= lastVersion)) return
|
||||
|
||||
const mcData = require('minecraft-data')(supportedVersion)
|
||||
const version = mcData.version
|
||||
|
||||
const {
|
||||
detectFrame,
|
||||
findPotentialLines,
|
||||
|
|
@ -8,11 +17,11 @@ const {
|
|||
generateLine,
|
||||
generatePortal,
|
||||
makeWorldWithPortal
|
||||
} = require('flying-squid').portal_detector('1.8')
|
||||
} = squid.portal_detector(version.minecraftVersion)
|
||||
|
||||
const { Vec3 } = require('vec3')
|
||||
|
||||
describe('generate portal', () => {
|
||||
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)])
|
||||
})
|
||||
|
|
@ -28,7 +37,7 @@ describe('generate portal', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('detect portal', () => {
|
||||
describe('detect portal ' + version.minecraftVersion, () => {
|
||||
jest.setTimeout(60 * 1000)
|
||||
const portalData = []
|
||||
|
||||
|
|
@ -211,7 +220,7 @@ describe('detect portal', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe("doesn't detect non-portal", () => {
|
||||
describe("doesn't detect non-portal " + version.minecraftVersion, () => {
|
||||
const portalData = []
|
||||
|
||||
portalData.push({
|
||||
|
|
@ -250,3 +259,4 @@ describe("doesn't detect non-portal", () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -5,16 +5,28 @@ const squid = require('flying-squid')
|
|||
|
||||
const settings = require('../config/default-settings')
|
||||
|
||||
describe('server', () => {
|
||||
const { firstVersion, lastVersion } = require('./common/parallel')
|
||||
|
||||
squid.supportedVersions.forEach((supportedVersion, i) => {
|
||||
if (!(i >= firstVersion && i <= lastVersion)) {
|
||||
return
|
||||
}
|
||||
const PORT = Math.round(30000 + Math.random() * 20000)
|
||||
|
||||
const mcData = require('minecraft-data')(supportedVersion)
|
||||
const version = mcData.version
|
||||
|
||||
describe(`simple server ${version.minecraftVersion}`, () => {
|
||||
let serv
|
||||
|
||||
beforeAll(done => {
|
||||
const options = settings
|
||||
options['online-mode'] = false
|
||||
options['port'] = 25566
|
||||
options['port'] = PORT
|
||||
options['view-distance'] = 2
|
||||
options['worldFolder'] = undefined
|
||||
options['logging'] = false
|
||||
options['version'] = version.minecraftVersion
|
||||
serv = squid.createMCServer(options)
|
||||
|
||||
serv.on('listening', () => {
|
||||
|
|
@ -35,3 +47,4 @@ describe('server', () => {
|
|||
client.on('error', done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue