mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-04 02:30:36 +00:00
rewrite tests using async/await
much easier to understand that way
This commit is contained in:
parent
94edf79f97
commit
7efb2daea3
5 changed files with 81 additions and 93 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -5,3 +5,4 @@ config/settings.json
|
||||||
logs/
|
logs/
|
||||||
src/plugins/*
|
src/plugins/*
|
||||||
!src/plugins/README.md
|
!src/plugins/README.md
|
||||||
|
distTest
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
node_modules
|
node_modules
|
||||||
|
distTest
|
||||||
18
gulpfile.js
18
gulpfile.js
|
|
@ -25,8 +25,24 @@ gulp.task('compile', function() {
|
||||||
.pipe(gulp.dest('dist/'));
|
.pipe(gulp.dest('dist/'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task('compileTest', function() {
|
||||||
|
return gulp
|
||||||
|
.src('test/**/*.js')
|
||||||
|
.pipe(plumber({
|
||||||
|
errorHandler: function(err) {
|
||||||
|
console.error(err.stack);
|
||||||
|
this.emit('end');
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.pipe(sourcemaps.init())
|
||||||
|
.pipe(babel(options))
|
||||||
|
.pipe(plumber.stop())
|
||||||
|
.pipe(sourcemaps.write('maps/'))
|
||||||
|
.pipe(gulp.dest('distTest/'));
|
||||||
|
});
|
||||||
|
|
||||||
gulp.task('watch', function() {
|
gulp.task('watch', function() {
|
||||||
return gulp.watch('src/**/*.js', ['compile']);
|
return gulp.watch('src/**/*.js', ['compile']);
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('default', ['compile']);
|
gulp.task('default', ['compile','compileTest']);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepublish": "gulp",
|
"prepublish": "gulp",
|
||||||
"test": "mocha --reporter spec"
|
"test": "mocha --reporter spec distTest"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"licenses": {
|
"licenses": {
|
||||||
|
|
@ -55,12 +55,13 @@
|
||||||
"babel": "5.8.23",
|
"babel": "5.8.23",
|
||||||
"chai": "~3.2.0",
|
"chai": "~3.2.0",
|
||||||
"doctoc": "^0.15.0",
|
"doctoc": "^0.15.0",
|
||||||
|
"event-promise": "0.0.1",
|
||||||
"gulp": "^3.8.11",
|
"gulp": "^3.8.11",
|
||||||
"gulp-babel": "^5.1.0",
|
"gulp-babel": "^5.1.0",
|
||||||
"gulp-plumber": "^1.0.1",
|
"gulp-plumber": "^1.0.1",
|
||||||
"gulp-sourcemaps": "^1.3.0",
|
"gulp-sourcemaps": "^1.3.0",
|
||||||
"longjohn": "~0.2.8",
|
"longjohn": "~0.2.8",
|
||||||
"mineflayer": "^1.5.1",
|
"mineflayer": "^1.5.1",
|
||||||
"mocha": "~2.2.5"
|
"mocha": "~2.3.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,131 +8,100 @@ var Vec3 = require('vec3').Vec3;
|
||||||
function assertPosEqual(pos1,pos2) {
|
function assertPosEqual(pos1,pos2) {
|
||||||
assert.isBelow(pos1.distanceTo(pos2),0.1);
|
assert.isBelow(pos1.distanceTo(pos2),0.1);
|
||||||
}
|
}
|
||||||
|
var once = require('event-promise');
|
||||||
|
|
||||||
|
describe("Server with mineflayer connection", () => {
|
||||||
describe("Server with mineflayer connection", function() {
|
|
||||||
var bot;
|
var bot;
|
||||||
var bot2;
|
var bot2;
|
||||||
var serv;
|
var serv;
|
||||||
before(function(done){
|
before(async () => {
|
||||||
var options = settings;
|
var options = settings;
|
||||||
options["online-mode"]=false;
|
options["online-mode"]=false;
|
||||||
options["port"]=25566;
|
options["port"]=25566;
|
||||||
|
|
||||||
serv=mcServer.createMCServer(options);
|
serv=mcServer.createMCServer(options);
|
||||||
|
|
||||||
serv.on("listening",function(){
|
await once(serv,"listening");
|
||||||
bot = mineflayer.createBot({
|
bot = mineflayer.createBot({
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: 25566,
|
port: 25566,
|
||||||
username: "bot"
|
username: "bot"
|
||||||
});
|
});
|
||||||
bot2 = mineflayer.createBot({
|
bot2 = mineflayer.createBot({
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: 25566,
|
port: 25566,
|
||||||
username: "bot2"
|
username: "bot2"
|
||||||
});
|
});
|
||||||
|
return Promise.all([once(bot,'spawn'),once(bot2,'spawn')])
|
||||||
var nbSpawn=0;
|
|
||||||
|
|
||||||
function spawn() {
|
|
||||||
nbSpawn++;
|
|
||||||
if(nbSpawn==2)
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.on('spawn', spawn);
|
|
||||||
bot2.on('spawn', spawn);
|
|
||||||
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function(done){
|
after(() => {
|
||||||
serv._server.close();
|
serv._server.close();
|
||||||
serv._server.on("close",function(){
|
return once(serv._server,"close");
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("commands",function(){
|
describe("commands",() => {
|
||||||
it("has an help command", function(done) {
|
it("has an help command", async () => {
|
||||||
bot.once("message",function(){
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
bot.chat("/help");
|
bot.chat("/help");
|
||||||
|
await once(bot,"message");
|
||||||
});
|
});
|
||||||
it("can use /particle",function(done){
|
it("can use /particle",async () => {
|
||||||
bot._client.once('world_particles',function(){
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
bot.chat("/particle 5 10 100 100 100");
|
bot.chat("/particle 5 10 100 100 100");
|
||||||
|
await once(bot._client,'world_particles');
|
||||||
});
|
});
|
||||||
it("can use /playsound",function(done) {
|
it("can use /playsound",async () => {
|
||||||
bot.once('soundEffectHeard',function(){
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
bot.chat('/playsound ambient.weather.rain');
|
bot.chat('/playsound ambient.weather.rain');
|
||||||
|
await once(bot,'soundEffectHeard');
|
||||||
});
|
});
|
||||||
it("can use /summon",function(done) {
|
it("can use /summon",async () => {
|
||||||
var listener=function(entity){
|
|
||||||
if(entity.name=="EnderDragon") {
|
|
||||||
bot.removeListener('entitySpawn',listener);
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
bot.on('entitySpawn',listener);
|
|
||||||
bot.chat('/summon EnderDragon');
|
bot.chat('/summon EnderDragon');
|
||||||
});
|
await new Promise((done) => {
|
||||||
describe("can use /tp",function() {
|
var listener=(entity) => {
|
||||||
it("can tp myself",function(done) {
|
if(entity.name=="EnderDragon") {
|
||||||
bot.once('forcedMove', function () {
|
bot.removeListener('entitySpawn',listener);
|
||||||
assertPosEqual(bot.entity.position,new Vec3(2, 3, 4));
|
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
bot.chat('/tp 2 3 4');
|
};
|
||||||
});
|
bot.on('entitySpawn',listener);
|
||||||
it("can tp somebody else",function(done) {
|
});
|
||||||
bot2.once('forcedMove', function () {
|
});
|
||||||
assertPosEqual(bot2.entity.position,new Vec3(2, 3, 4));
|
describe("can use /tp",() => {
|
||||||
done();
|
it("can tp myself", async () => {
|
||||||
});
|
bot.chat('/tp 2 3 4');
|
||||||
|
await once(bot,'forcedMove');
|
||||||
|
assertPosEqual(bot.entity.position, new Vec3(2, 3, 4));
|
||||||
|
});
|
||||||
|
it("can tp somebody else",async () => {
|
||||||
bot.chat('/tp bot2 2 3 4');
|
bot.chat('/tp bot2 2 3 4');
|
||||||
|
await once(bot2,'forcedMove');
|
||||||
|
assertPosEqual(bot2.entity.position, new Vec3(2, 3, 4));
|
||||||
});
|
});
|
||||||
it("can tp to somebody else",function(done) {
|
it("can tp to somebody else",async () => {
|
||||||
bot2.once('forcedMove', function () {
|
|
||||||
assertPosEqual(bot2.entity.position,bot.entity.position);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
bot.chat('/tp bot2 bot');
|
bot.chat('/tp bot2 bot');
|
||||||
|
await once(bot2,'forcedMove');
|
||||||
|
assertPosEqual(bot2.entity.position, bot.entity.position);
|
||||||
});
|
});
|
||||||
it("can tp with relative positions",function(done) {
|
it("can tp with relative positions",async () => {
|
||||||
var initialPosition=bot.entity.position.clone();
|
var initialPosition=bot.entity.position.clone();
|
||||||
bot.once('forcedMove', function () {
|
|
||||||
assertPosEqual(bot.entity.position,initialPosition.offset(1,-2,3));
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
bot.chat('/tp ~1 ~-2 ~3');
|
bot.chat('/tp ~1 ~-2 ~3');
|
||||||
|
await once(bot,'forcedMove');
|
||||||
|
assertPosEqual(bot.entity.position,initialPosition.offset(1,-2,3));
|
||||||
});
|
});
|
||||||
it("can tp somebody else with relative positions",function(done) {
|
it("can tp somebody else with relative positions",async () => {
|
||||||
var initialPosition=bot2.entity.position.clone();
|
var initialPosition=bot2.entity.position.clone();
|
||||||
bot2.once('forcedMove', function () {
|
|
||||||
assertPosEqual(bot2.entity.position,initialPosition.offset(1,-2,3));
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
bot.chat('/tp bot2 ~1 ~-2 ~3');
|
bot.chat('/tp bot2 ~1 ~-2 ~3');
|
||||||
|
await once(bot2,'forcedMove');
|
||||||
|
assertPosEqual(bot2.entity.position,initialPosition.offset(1,-2,3));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("can use /deop",function(done) {
|
it("can use /deop",async () => {
|
||||||
bot.once('message',function(message){
|
|
||||||
assert.equal(message.text,'bot is deopped');
|
|
||||||
bot.once('message',function(message){
|
|
||||||
assert.equal(message.text,'You do not have permission to use this command');
|
|
||||||
serv.getPlayer("bot").op=true;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
bot.chat('/deop bot');
|
bot.chat('/deop bot');
|
||||||
|
let msg1=await once(bot,'message');
|
||||||
|
assert.equal(msg1.text,'bot is deopped');
|
||||||
bot.chat('/op bot');
|
bot.chat('/op bot');
|
||||||
|
let msg2=await once(bot,'message');
|
||||||
|
assert.equal(msg2.text,'You do not have permission to use this command');
|
||||||
|
serv.getPlayer("bot").op=true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue