Fix tests

This commit is contained in:
mhsjlw 2018-02-04 16:45:47 -05:00
parent 711a484b72
commit 9fca132bc1
3 changed files with 14 additions and 11 deletions

View file

@ -1,3 +1,3 @@
machine: machine:
node: node:
version: 6 version: 8

View file

@ -15,7 +15,7 @@
}, },
"scripts": { "scripts": {
"prepare": "require-self", "prepare": "require-self",
"test": "mocha --reporter spec distTest" "test": "mocha --reporter spec"
}, },
"keywords": [], "keywords": [],
"licenses": { "licenses": {
@ -59,7 +59,7 @@
"devDependencies": { "devDependencies": {
"chai": "^3.2.0", "chai": "^3.2.0",
"longjohn": "^0.2.8", "longjohn": "^0.2.8",
"mineflayer": "^1.7.5", "mineflayer": "^2.6.1",
"mocha": "^3.0.0", "mocha": "^3.0.0",
"require-self": "^0.1.0" "require-self": "^0.1.0"
} }

View file

@ -4,6 +4,7 @@ const settings = require('../config/default-settings');
const mineflayer = require("mineflayer"); const mineflayer = require("mineflayer");
const assert = require('chai').assert; const assert = require('chai').assert;
const Vec3 = require('vec3').Vec3; const Vec3 = require('vec3').Vec3;
const Item = require('prismarine-item')("1.8");
function assertPosEqual(actual,expected) { function assertPosEqual(actual,expected) {
assert.isBelow(actual.distanceTo(expected),1,"expected: "+expected+", actual: "+actual+"\n"); assert.isBelow(actual.distanceTo(expected),1,"expected: "+expected+", actual: "+actual+"\n");
@ -11,7 +12,7 @@ function assertPosEqual(actual,expected) {
const once = require('event-promise'); const once = require('event-promise');
describe("Server with mineflayer connection", function() { describe("Server with mineflayer connection", function() {
this.timeout(10 * 60 * 1000); this.timeout(60 * 1000);
let bot; let bot;
let bot2; let bot2;
let serv; let serv;
@ -61,7 +62,7 @@ describe("Server with mineflayer connection", function() {
} }
beforeEach(async function () { beforeEach(async function () {
this.timeout(10 * 60 * 1000); this.timeout(60 * 1000);
const options = settings; const options = settings;
options["online-mode"]=false; options["online-mode"]=false;
options["port"]=25566; options["port"]=25566;
@ -74,12 +75,14 @@ describe("Server with mineflayer connection", function() {
bot = mineflayer.createBot({ bot = mineflayer.createBot({
host: "localhost", host: "localhost",
port: 25566, port: 25566,
username: "bot" username: "bot",
version: "1.8"
}); });
bot2 = mineflayer.createBot({ bot2 = mineflayer.createBot({
host: "localhost", host: "localhost",
port: 25566, port: 25566,
username: "bot2" username: "bot2",
version: "1.8"
}); });
await Promise.all([once(bot,'login'),once(bot2,'login')]); await Promise.all([once(bot,'login'),once(bot2,'login')]);
@ -111,7 +114,7 @@ describe("Server with mineflayer connection", function() {
} }
it("can dig",async function () { it("can dig",async function () {
this.timeout(10 * 60 * 1000); this.timeout(60 * 1000);
await Promise.all([waitSpawnZone(bot,2),waitSpawnZone(bot2,2),onGround(bot),onGround(bot2)]); await Promise.all([waitSpawnZone(bot,2),waitSpawnZone(bot2,2),onGround(bot),onGround(bot2)]);
const pos=bot.entity.position.offset(0,-1,0).floored(); const pos=bot.entity.position.offset(0,-1,0).floored();
@ -124,7 +127,7 @@ describe("Server with mineflayer connection", function() {
it("can place a block",async function () { it("can place a block",async function () {
this.timeout(10 * 60 * 1000); this.timeout(60 * 1000);
await Promise.all([waitSpawnZone(bot,2),waitSpawnZone(bot2,2),onGround(bot),onGround(bot2)]); await Promise.all([waitSpawnZone(bot,2),waitSpawnZone(bot2,2),onGround(bot),onGround(bot2)]);
const pos=bot.entity.position.offset(0,-2,0).floored(); const pos=bot.entity.position.offset(0,-2,0).floored();
@ -134,7 +137,7 @@ describe("Server with mineflayer connection", function() {
assertPosEqual(newBlock.position,pos); assertPosEqual(newBlock.position,pos);
assert.equal(newBlock.type,0,"block "+pos+" should have been dug"); assert.equal(newBlock.type,0,"block "+pos+" should have been dug");
bot.creative.setInventorySlot(36,new mineflayer.Item(1,1)); bot.creative.setInventorySlot(36, new Item(1,1));
await new Promise((cb) => { await new Promise((cb) => {
bot.inventory.on("windowUpdate",(slot,oldItem,newItem) => { bot.inventory.on("windowUpdate",(slot,oldItem,newItem) => {
if(slot==36 && newItem && newItem.type==1) if(slot==36 && newItem && newItem.type==1)
@ -231,7 +234,7 @@ describe("Server with mineflayer connection", function() {
serv.getPlayer("bot").op=true; serv.getPlayer("bot").op=true;
}); });
it("can use /setblock",async() => { it("can use /setblock",async() => {
await once(bot,'chunkColumnLoad'); await once(bot, 'chunkColumnLoad');
bot.chat('/setblock 1 2 3 95 0'); bot.chat('/setblock 1 2 3 95 0');
let [,newBlock]=await once(bot,'blockUpdate:'+new Vec3(1,2,3),{array:true}); let [,newBlock]=await once(bot,'blockUpdate:'+new Vec3(1,2,3),{array:true});
assert.equal(newBlock.type,95); assert.equal(newBlock.type,95);