mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 06:03:33 -04:00
Merge pull request #263 from rom1504/enable_client_connection_tests
Enable client connection tests
This commit is contained in:
commit
c5d4848dfd
45
test/test.js
45
test/test.js
@ -258,7 +258,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) {
|
wrap.startServer({'online-mode': 'true'}, function(err) {
|
||||||
if(err)
|
if(err)
|
||||||
return done(err);
|
return done(err);
|
||||||
@ -267,14 +267,14 @@ mc.supportedVersions.forEach(function(supportedVersion){
|
|||||||
password: process.env.MC_PASSWORD,
|
password: process.env.MC_PASSWORD,
|
||||||
version: version.majorVersion
|
version: version.majorVersion
|
||||||
});
|
});
|
||||||
wrap.on('line', function(line) {
|
var lineListener=function(line) {
|
||||||
var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
||||||
if(!match) return;
|
if(!match) return;
|
||||||
assert.strictEqual(match[1], client.session.username);
|
assert.strictEqual(match[1], client.session.username);
|
||||||
assert.strictEqual(match[2], "hello everyone; I have logged in.");
|
assert.strictEqual(match[2], "hello everyone; I have logged in.");
|
||||||
wrap.writeServer("say hello\n");
|
wrap.writeServer("say hello\n");
|
||||||
});
|
};
|
||||||
var chatCount = 0;
|
wrap.on('line', lineListener);
|
||||||
client.on('login', function(packet) {
|
client.on('login', function(packet) {
|
||||||
assert.strictEqual(packet.levelType, 'default');
|
assert.strictEqual(packet.levelType, 'default');
|
||||||
assert.strictEqual(packet.difficulty, 1);
|
assert.strictEqual(packet.difficulty, 1);
|
||||||
@ -284,13 +284,19 @@ mc.supportedVersions.forEach(function(supportedVersion){
|
|||||||
message: "hello everyone; I have logged in."
|
message: "hello everyone; I have logged in."
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
var chatCount = 0;
|
||||||
client.on('chat', function(packet) {
|
client.on('chat', function(packet) {
|
||||||
done();
|
chatCount += 1;
|
||||||
|
assert.ok(chatCount <= 2);
|
||||||
|
if(chatCount==2) {
|
||||||
|
client.removeAllListeners('chat');
|
||||||
|
wrap.removeListener('line',lineListener);
|
||||||
|
done();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
it.skip("connects successfully - offline mode (STUBBED)", function(done) {
|
it("connects successfully - offline mode", function(done) {
|
||||||
wrap.startServer({'online-mode': 'false'}, function(err) {
|
wrap.startServer({'online-mode': 'false'}, function(err) {
|
||||||
if(err)
|
if(err)
|
||||||
return done(err);
|
return done(err);
|
||||||
@ -298,13 +304,14 @@ mc.supportedVersions.forEach(function(supportedVersion){
|
|||||||
username: 'Player',
|
username: 'Player',
|
||||||
version: version.majorVersion
|
version: version.majorVersion
|
||||||
});
|
});
|
||||||
wrap.on('line', function(line) {
|
var lineListener=function(line) {
|
||||||
var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
var match = line.match(/\[Server thread\/INFO\]: <(.+?)> (.+)/);
|
||||||
if(!match) return;
|
if(!match) return;
|
||||||
assert.strictEqual(match[1], 'Player');
|
assert.strictEqual(match[1], 'Player');
|
||||||
assert.strictEqual(match[2], "hello everyone; I have logged in.");
|
assert.strictEqual(match[2], "hello everyone; I have logged in.");
|
||||||
wrap.writeServer("say hello\n");
|
wrap.writeServer("say hello\n");
|
||||||
});
|
};
|
||||||
|
wrap.on('line', lineListener);
|
||||||
var chatCount = 0;
|
var chatCount = 0;
|
||||||
client.on('login', function(packet) {
|
client.on('login', function(packet) {
|
||||||
assert.strictEqual(packet.levelType, 'default');
|
assert.strictEqual(packet.levelType, 'default');
|
||||||
@ -321,26 +328,22 @@ mc.supportedVersions.forEach(function(supportedVersion){
|
|||||||
var message = JSON.parse(packet.message);
|
var message = JSON.parse(packet.message);
|
||||||
if(chatCount === 1) {
|
if(chatCount === 1) {
|
||||||
assert.strictEqual(message.translate, "chat.type.text");
|
assert.strictEqual(message.translate, "chat.type.text");
|
||||||
assert.deepEqual(message["with"][0], {
|
assert.deepEqual(message["with"][0].clickEvent, {
|
||||||
clickEvent: {
|
action: "suggest_command",
|
||||||
action: "suggest_command",
|
value: "/msg Player "
|
||||||
value: "/msg Player "
|
|
||||||
},
|
|
||||||
text: "Player"
|
|
||||||
});
|
});
|
||||||
|
assert.deepEqual(message["with"][0].text, "Player");
|
||||||
assert.strictEqual(message["with"][1], "hello everyone; I have logged in.");
|
assert.strictEqual(message["with"][1], "hello everyone; I have logged in.");
|
||||||
} else if(chatCount === 2) {
|
} else if(chatCount === 2) {
|
||||||
assert.strictEqual(message.translate, "chat.type.announcement");
|
assert.strictEqual(message.translate, "chat.type.announcement");
|
||||||
assert.strictEqual(message["with"][0], "Server");
|
assert.strictEqual(message["with"][0].text ? message["with"][0].text : message["with"][0], "Server");
|
||||||
assert.deepEqual(message["with"][1], {
|
assert.deepEqual(message["with"][1].extra[0].text ?
|
||||||
text: "",
|
message["with"][1].extra[0].text : message["with"][1].extra[0], "hello");
|
||||||
extra: ["hello"]
|
wrap.removeListener('line',lineListener);
|
||||||
});
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
it("gets kicked when no credentials supplied in online mode", function(done) {
|
it("gets kicked when no credentials supplied in online mode", function(done) {
|
||||||
wrap.startServer({'online-mode': 'true'}, function(err) {
|
wrap.startServer({'online-mode': 'true'}, function(err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user