mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-07 12:10:46 +00:00
make tests independent : do beforeEach instead of before to initialize the server/bots
This commit is contained in:
parent
b6b49a5c3c
commit
72c91c50e0
2 changed files with 22 additions and 9 deletions
|
|
@ -41,6 +41,7 @@ class MCServer extends EventEmitter {
|
||||||
this._server.on('listening', () => this.emit('listening',this._server.socketServer.address().port));
|
this._server.on('listening', () => this.emit('listening',this._server.socketServer.address().port));
|
||||||
this.emit('asap');
|
this.emit('asap');
|
||||||
|
|
||||||
process.on('unhandledRejection', err => this.emit('error',err));
|
//process.on('unhandledRejection', err => this.emit('error',err));
|
||||||
|
// TODO better catch all promises: using this make it impossible to run 2 servers in one process
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,7 +16,7 @@ describe("Server with mineflayer connection", function() {
|
||||||
var bot2;
|
var bot2;
|
||||||
var serv;
|
var serv;
|
||||||
|
|
||||||
async function onGround()
|
async function onGround(bot)
|
||||||
{
|
{
|
||||||
await new Promise((cb) => {
|
await new Promise((cb) => {
|
||||||
var l=() => {
|
var l=() => {
|
||||||
|
|
@ -29,7 +29,7 @@ describe("Server with mineflayer connection", function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
before(async function () {
|
beforeEach(async function () {
|
||||||
this.timeout(10 * 60 * 1000);
|
this.timeout(10 * 60 * 1000);
|
||||||
var options = settings;
|
var options = settings;
|
||||||
options["online-mode"]=false;
|
options["online-mode"]=false;
|
||||||
|
|
@ -50,10 +50,10 @@ describe("Server with mineflayer connection", function() {
|
||||||
username: "bot2"
|
username: "bot2"
|
||||||
});
|
});
|
||||||
|
|
||||||
await onGround();
|
return Promise.all([once(bot,'login'),once(bot2,'login')]);
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
afterEach(() => {
|
||||||
serv._server.close();
|
serv._server.close();
|
||||||
return once(serv._server,"close");
|
return once(serv._server,"close");
|
||||||
});
|
});
|
||||||
|
|
@ -61,15 +61,17 @@ describe("Server with mineflayer connection", function() {
|
||||||
|
|
||||||
|
|
||||||
describe("actions",() => {
|
describe("actions",() => {
|
||||||
|
|
||||||
it("can dig",async function () {
|
it("can dig",async function () {
|
||||||
|
await onGround(bot);
|
||||||
this.timeout(10 * 60 * 1000);
|
this.timeout(10 * 60 * 1000);
|
||||||
var pos=bot.entity.position.offset(0,-1,0);
|
var pos=bot.entity.position.offset(0,-1,0);
|
||||||
bot.dig(bot.blockAt(pos));
|
bot.dig(bot.blockAt(pos));
|
||||||
let [oldBlock,newBlock]=await once(bot,'blockUpdate:'+pos,{array:true});
|
let [oldBlock,newBlock]=await once(bot,'blockUpdate:'+pos,{array:true});
|
||||||
assert.equal(newBlock.type,0);
|
assert.equal(newBlock.type,0);
|
||||||
await onGround();
|
|
||||||
});
|
});
|
||||||
it.skip("can place a block",async function () {
|
it.skip("can place a block",async function () {
|
||||||
|
await onGround(bot);
|
||||||
|
|
||||||
this.timeout(10 * 60 * 1000);
|
this.timeout(10 * 60 * 1000);
|
||||||
var pos=bot.entity.position.offset(0,-2,0);
|
var pos=bot.entity.position.offset(0,-2,0);
|
||||||
|
|
@ -104,9 +106,10 @@ describe("Server with mineflayer connection", function() {
|
||||||
bot.chat('/playsound ambient.weather.rain');
|
bot.chat('/playsound ambient.weather.rain');
|
||||||
await once(bot,'soundEffectHeard');
|
await once(bot,'soundEffectHeard');
|
||||||
});
|
});
|
||||||
it("can use /summon",async () => {
|
|
||||||
bot.chat('/summon EnderDragon');
|
function waitDragon()
|
||||||
await new Promise((done) => {
|
{
|
||||||
|
return new Promise((done) => {
|
||||||
var listener=(entity) => {
|
var listener=(entity) => {
|
||||||
if(entity.name=="EnderDragon") {
|
if(entity.name=="EnderDragon") {
|
||||||
bot.removeListener('entitySpawn',listener);
|
bot.removeListener('entitySpawn',listener);
|
||||||
|
|
@ -115,13 +118,21 @@ describe("Server with mineflayer connection", function() {
|
||||||
};
|
};
|
||||||
bot.on('entitySpawn',listener);
|
bot.on('entitySpawn',listener);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it("can use /summon",async () => {
|
||||||
|
bot.chat('/summon EnderDragon');
|
||||||
|
await waitDragon();
|
||||||
});
|
});
|
||||||
it("can use /kill",async () => {
|
it("can use /kill",async () => {
|
||||||
|
bot.chat('/summon EnderDragon');
|
||||||
|
await waitDragon();
|
||||||
bot.chat('/kill @e[type=EnderDragon]');
|
bot.chat('/kill @e[type=EnderDragon]');
|
||||||
const entity=await once(bot,'entityDead');
|
const entity=await once(bot,'entityDead');
|
||||||
assert.equal(entity.name,"EnderDragon");
|
assert.equal(entity.name,"EnderDragon");
|
||||||
});
|
});
|
||||||
describe("can use /tp",() => {
|
describe("can use /tp",() => {
|
||||||
|
beforeEach(() => Promise.all([onGround(bot),onGround(bot2)]));
|
||||||
it("can tp myself", async () => {
|
it("can tp myself", async () => {
|
||||||
bot.chat('/tp 2 3 4');
|
bot.chat('/tp 2 3 4');
|
||||||
await once(bot,'forcedMove');
|
await once(bot,'forcedMove');
|
||||||
|
|
@ -160,6 +171,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');
|
||||||
bot.chat('/setblock 1 2 3 95 0');
|
bot.chat('/setblock 1 2 3 95 0');
|
||||||
let [oldBlock,newBlock]=await once(bot,'blockUpdate:'+new Vec3(1,2,3),{array:true});
|
let [oldBlock,newBlock]=await once(bot,'blockUpdate:'+new Vec3(1,2,3),{array:true});
|
||||||
assert.equal(newBlock.type,95);
|
assert.equal(newBlock.type,95);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue