Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

v0.1.0 - Write tests.

  • Loading branch information...
commit 07bafca25d65f12b402efa31521f9b19ac70a359 1 parent ac9bd55
@remixz authored
View
1  README.md
@@ -6,7 +6,6 @@ minecraft-pi allows you to control a [Minecraft: Pi Edition](http://pi.minecraft
*TODO:*
-* Write tests
* Better documentation
### Usage
View
7 lib/minecraft.js
@@ -15,12 +15,13 @@ var Blocks = require('./blocks.json');
/**
* Constructor
*/
-function Minecraft (host, port) {
+function Minecraft (host, port, callback) {
var self = this;
this.connection = net.connect({port: port, host: host}, function () {
console.log('Connected to server!');
self.chat('Hello from Node.js! Commanding from ' + os.hostname());
+ callback();
});
this.connection.on('end', function() {
@@ -46,6 +47,10 @@ Minecraft.prototype.sendReceive = function (command, callback) {
this.connection.on('data', callback);
};
+Minecraft.prototype.end = function () {
+ this.connection.destroy();
+}
+
/**
* Commands
*/
View
BIN  minecraft-pi.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
7 package.json
@@ -3,7 +3,7 @@
"name": "minecraft-pi",
"description": "A Node.js API for Minecraft: Pi Edition.",
"license": "MIT",
- "version": "0.0.2",
+ "version": "0.1.0",
"homepage": "https://github.com/remixz/minecraft-pi",
"repository": {
"type": "git",
@@ -14,12 +14,13 @@
},
"main": "./lib/minecraft.js",
"scripts": {
- "test": "tap test/*.js"
+ "test": "tap ./test/*.js"
},
"dependencies": {
},
"devDependencies": {
- "tap": "~0.4.0"
+ "tap": "~0.4.0",
+ "async": "~0.2.5"
},
"optionalDependencies": {},
"engines": {
View
46 test/index.js
@@ -0,0 +1,46 @@
+/**
+ * minecraft-pi tests.
+ *
+ * @package minecraft-pi
+ * @author Zachary Bruggeman <talkto@zachbruggeman.me>
+ */
+
+/**
+ * Dependencies
+ */
+var test = require('tap').test;
+var async = require('async');
+var Minecraft = require('./../lib/minecraft.js');
+var client, receivedData;
+
+async.auto({
+ connect: function (callback) {
+ client = new Minecraft('192.168.1.89', 4711, callback); // To test for yourself, please edit this to point to your local pi server.
+ },
+
+ data: ['connect', function (callback) {
+ client.getBlock(99999, 99999, 99999, function(data) {
+ receivedData = data.toString();
+ client.end();
+ callback();
+ });
+ }],
+
+ test: ['connect', 'data', function (callback) {
+ test('Client connection', function(t) {
+ t.type(client.connection, 'object', 'The connection should be an object.');
+ t.end();
+ });
+
+ test('Receiving data', function(t) {
+ t.type(receivedData, 'string', 'A string of data should be returned.')
+ t.equals(receivedData, '0\n', 'Expected result.')
+ t.end();
+ });
+ }]
+}, function(err, obj) {
+ test('Catch errors', function(t) {
+ t.equal(err, null, 'Errors should be null.');
+ t.end();
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.