diff --git a/.gitignore b/.gitignore index 39a72c4e4..34f59397d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .vagrant doc node_modules +*.out +*.log \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index eb4450521..9af2efaca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,28 @@ language: node_js node_js: - "0.10" +addons: + firefox: "31.0" # 3.4->31.0 +os: + - linux before_install: # node-canvas dependency - sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++ + # ROS deps for examples + - sudo sh -c 'echo "deb http://packages.ros.org/ros-shadow-fixed/ubuntu precise main" > /etc/apt/sources.list.d/ros-latest.list' + - wget http://packages.ros.org/ros.key -O - | sudo apt-key add - + - sudo apt-get update -qq + - sudo apt-get install ros-hydro-ros-base + - sudo apt-get install ros-hydro-rosbridge-server ros-hydro-tf2-web-republisher ros-hydro-common-tutorials ros-hydro-rospy-tutorials ros-hydro-actionlib-tutorials + - npm install -g grunt-cli karma-cli + + # Set up Xfvb for Firefox headless testing + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" before_script: - - npm install -g grunt-cli + - source /opt/ros/hydro/setup.bash + - sh test/examples/setup_examples.sh +script: + - rostopic list + - npm test + - npm run test-examples diff --git a/Gruntfile.js b/Gruntfile.js index 6bb733f19..a6390c07b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -21,15 +21,19 @@ module.exports = function(grunt) { build: { configFile: './test/karma.conf.js', singleRun: true, - browsers: ['PhantomJS'] + browsers: ['Firefox'] } }, mochaTest: { + options: { + reporter: 'spec', + timeout: 5000 + }, test: { - options: { - reporter: 'spec' - }, - src: ['test/**/*.test.js'] + src: ['test/*.test.js'] + }, + examples: { + src: ['test/examples/*.js'] } }, uglify: { @@ -95,9 +99,8 @@ module.exports = function(grunt) { grunt.registerTask('dev', ['browserify', 'watch']); - grunt.registerTask('test', ['jshint', 'mochaTest', 'browserify', 'karma']); + grunt.registerTask('test', ['jshint', 'mochaTest:test', 'browserify', 'karma']); grunt.registerTask('build', ['test', 'uglify']); grunt.registerTask('build_and_watch', ['watch']); grunt.registerTask('doc', ['clean', 'jsdoc']); }; - diff --git a/build/roslib.js b/build/roslib.js index 17aaa2b61..6a5601847 100644 --- a/build/roslib.js +++ b/build/roslib.js @@ -1115,7 +1115,8 @@ function Topic(options) { this.queue_size = options.queue_size || 100; // Check for valid compression types - if (this.compression && this.compression !== 'png' && this.compression !== 'none') { + if (this.compression && this.compression !== 'png' && + this.compression !== 'none') { this.emit('warning', this.compression + ' compression is not supported. No compression will be used.'); } @@ -1138,28 +1139,21 @@ Topic.prototype.__proto__ = EventEmitter2.prototype; */ Topic.prototype.subscribe = function(callback) { var that = this; - - this.on('message', function(message) { - callback(message); - }); - + this.on('message', callback); this.ros.on(this.name, function(data) { var message = new Message(data); that.emit('message', message); }); - this.ros.idCounter++; - var subscribeId = 'subscribe:' + this.name + ':' + this.ros.idCounter; - var call = { - op : 'subscribe', - id : subscribeId, - type : this.messageType, - topic : this.name, - compression : this.compression, - throttle_rate : this.throttle_rate - }; - - this.ros.callOnConnection(call); + this.subscribeId = 'subscribe:' + this.name + ':' + (++this.ros.idCounter); + this.ros.callOnConnection({ + op: 'subscribe', + id: this.subscribeId, + type: this.messageType, + topic: this.name, + compression: this.compression, + throttle_rate: this.throttle_rate + }); }; /** @@ -1167,15 +1161,12 @@ Topic.prototype.subscribe = function(callback) { * all subscribe callbacks. */ Topic.prototype.unsubscribe = function() { - this.ros.removeAllListeners([ this.name ]); - this.ros.idCounter++; - var unsubscribeId = 'unsubscribe:' + this.name + ':' + this.ros.idCounter; - var call = { - op : 'unsubscribe', - id : unsubscribeId, - topic : this.name - }; - this.ros.callOnConnection(call); + this.ros.removeAllListeners([this.name]); + this.ros.callOnConnection({ + op: 'unsubscribe', + id: this.subscribeId, + topic: this.name + }); }; /** @@ -1185,17 +1176,15 @@ Topic.prototype.advertise = function() { if (this.isAdvertised) { return; } - this.ros.idCounter++; - this.advertiseId = 'advertise:' + this.name + ':' + this.ros.idCounter; - var call = { - op : 'advertise', - id : this.advertiseId, - type : this.messageType, - topic : this.name, - latch : this.latch, - queue_size : this.queue_size - }; - this.ros.callOnConnection(call); + this.advertiseId = 'advertise:' + this.name + ':' + (++this.ros.idCounter); + this.ros.callOnConnection({ + op: 'advertise', + id: this.advertiseId, + type: this.messageType, + topic: this.name, + latch: this.latch, + queue_size: this.queue_size + }); this.isAdvertised = true; }; @@ -1206,13 +1195,11 @@ Topic.prototype.unadvertise = function() { if (!this.isAdvertised) { return; } - var unadvertiseId = this.advertiseId; - var call = { - op : 'unadvertise', - id : unadvertiseId, - topic : this.name - }; - this.ros.callOnConnection(call); + this.ros.callOnConnection({ + op: 'unadvertise', + id: this.advertiseId, + topic: this.name + }); this.isAdvertised = false; }; @@ -1223,22 +1210,22 @@ Topic.prototype.unadvertise = function() { */ Topic.prototype.publish = function(message) { if (!this.isAdvertised) { - this.advertise(); + this.advertise(); } this.ros.idCounter++; - var publishId = 'publish:' + this.name + ':' + this.ros.idCounter; var call = { - op : 'publish', - id : publishId, - topic : this.name, - msg : message, - latch : this.latch + op: 'publish', + id: 'publish:' + this.name + ':' + this.ros.idCounter, + topic: this.name, + msg: message, + latch: this.latch }; this.ros.callOnConnection(call); }; module.exports = Topic; + },{"./Message":7,"eventemitter2":30}],14:[function(require,module,exports){ /** * @author David Gossow - dgossow@willowgarage.com diff --git a/examples/fibonacci.html b/examples/fibonacci.html index 00962b3b2..f58084219 100644 --- a/examples/fibonacci.html +++ b/examples/fibonacci.html @@ -2,8 +2,8 @@
- - + + - + - + - + - + - +