From fd0d9f5a1329fb69e2065507aa42fac6d13db29f Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Wed, 30 Sep 2015 17:23:47 +0200 Subject: [PATCH 1/3] fix and enable offline client connection test --- test/test.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/test/test.js b/test/test.js index 8eccbc9..9efed64 100644 --- a/test/test.js +++ b/test/test.js @@ -298,7 +298,7 @@ mc.supportedVersions.forEach(function(supportedVersion){ }); done(); }); - it.skip("connects successfully - offline mode (STUBBED)", function(done) { + it("connects successfully - offline mode", function(done) { wrap.startServer({'online-mode': 'false'}, function(err) { if(err) return done(err); @@ -329,26 +329,20 @@ mc.supportedVersions.forEach(function(supportedVersion){ var message = JSON.parse(packet.message); if(chatCount === 1) { assert.strictEqual(message.translate, "chat.type.text"); - assert.deepEqual(message["with"][0], { - clickEvent: { - action: "suggest_command", - value: "/msg Player " - }, - text: "Player" + assert.deepEqual(message["with"][0].clickEvent, { + action: "suggest_command", + value: "/msg Player " }); + assert.deepEqual(message["with"][0].text, "Player"); assert.strictEqual(message["with"][1], "hello everyone; I have logged in."); } else if(chatCount === 2) { assert.strictEqual(message.translate, "chat.type.announcement"); - assert.strictEqual(message["with"][0], "Server"); - assert.deepEqual(message["with"][1], { - text: "", - extra: ["hello"] - }); + assert.strictEqual(message["with"][0].text ? message["with"][0].text : message["with"][0], "Server"); + assert.deepEqual(message["with"][1].extra[0].text ? message["with"][1].extra[0].text : message["with"][1].extra[0], "hello"); done(); } }); }); - done(); }); it("gets kicked when no credentials supplied in online mode", function(done) { wrap.startServer({'online-mode': 'true'}, function(err) { From 698a64f926c6b38f1e1173d10191b35936fc7821 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Wed, 30 Sep 2015 17:30:52 +0200 Subject: [PATCH 2/3] fix and enable online client connection test --- test/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test.js b/test/test.js index 9efed64..9a33fb9 100644 --- a/test/test.js +++ b/test/test.js @@ -266,7 +266,7 @@ mc.supportedVersions.forEach(function(supportedVersion){ }); }); }); - it.skip("connects successfully - online mode (STUBBED)", function(done) { + it("connects successfully - online mode", function(done) { wrap.startServer({'online-mode': 'true'}, function(err) { if(err) return done(err); @@ -293,10 +293,10 @@ mc.supportedVersions.forEach(function(supportedVersion){ }); }); client.on('chat', function(packet) { + client.removeAllListeners('chat'); done(); }); }); - done(); }); it("connects successfully - offline mode", function(done) { wrap.startServer({'online-mode': 'false'}, function(err) { From 788ad2981501cfeb0cc9ff35f4d66447575d05c0 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Wed, 30 Sep 2015 17:53:24 +0200 Subject: [PATCH 3/3] fix chat count problem in tests + line listener --- test/test.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/test/test.js b/test/test.js index 9a33fb9..4714aa6 100644 --- a/test/test.js +++ b/test/test.js @@ -275,14 +275,14 @@ mc.supportedVersions.forEach(function(supportedVersion){ password: process.env.MC_PASSWORD, version: version.majorVersion }); - wrap.on('line', function(line) { + var lineListener=function(line) { var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/); if(!match) return; assert.strictEqual(match[1], client.session.username); assert.strictEqual(match[2], "hello everyone; I have logged in."); wrap.writeServer("say hello\n"); - }); - var chatCount = 0; + }; + wrap.on('line', lineListener); client.on('login', function(packet) { assert.strictEqual(packet.levelType, 'default'); assert.strictEqual(packet.difficulty, 1); @@ -292,9 +292,15 @@ mc.supportedVersions.forEach(function(supportedVersion){ message: "hello everyone; I have logged in." }); }); + var chatCount = 0; client.on('chat', function(packet) { - client.removeAllListeners('chat'); - done(); + chatCount += 1; + assert.ok(chatCount <= 2); + if(chatCount==2) { + client.removeAllListeners('chat'); + wrap.removeListener('line',lineListener); + done(); + } }); }); }); @@ -306,13 +312,14 @@ mc.supportedVersions.forEach(function(supportedVersion){ username: 'Player', version: version.majorVersion }); - wrap.on('line', function(line) { + var lineListener=function(line) { var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/); if(!match) return; assert.strictEqual(match[1], 'Player'); assert.strictEqual(match[2], "hello everyone; I have logged in."); wrap.writeServer("say hello\n"); - }); + }; + wrap.on('line', lineListener); var chatCount = 0; client.on('login', function(packet) { assert.strictEqual(packet.levelType, 'default'); @@ -338,7 +345,9 @@ mc.supportedVersions.forEach(function(supportedVersion){ } else if(chatCount === 2) { assert.strictEqual(message.translate, "chat.type.announcement"); assert.strictEqual(message["with"][0].text ? message["with"][0].text : message["with"][0], "Server"); - assert.deepEqual(message["with"][1].extra[0].text ? message["with"][1].extra[0].text : message["with"][1].extra[0], "hello"); + assert.deepEqual(message["with"][1].extra[0].text ? + message["with"][1].extra[0].text : message["with"][1].extra[0], "hello"); + wrap.removeListener('line',lineListener); done(); } });