From d16fb067761d21d253acd80881893b458af908ce Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 09:39:26 +0200 Subject: [PATCH 01/14] :sparkles: Add ES2015 support --- .gitignore | 1 + package.json | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 6e8ed5f..ba2397c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.swp .DS_Store node_modules +dist .tern-port argo-HEAD argo-jscoverage diff --git a/package.json b/package.json index e670c6b..432d8ef 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "argo": "^1.0.0", "argo-formatter-siren": "0.0.0", "async": "^0.9.0", + "babel-runtime": "^6.23.0", "calypso": "^1.0.0", "calypso-level": "^0.5.0", "calypso-query-decompiler": "^0.4.0", @@ -33,6 +34,9 @@ "zetta-streams": "^0.3.0" }, "devDependencies": { + "babel-cli": "^6.24.1", + "babel-plugin-transform-runtime": "^6.23.0", + "babel-preset-env": "^1.3.3", "memdown": "^0.10.2", "mocha": "^1.20.1", "portscanner": "^1.0.0", @@ -40,6 +44,7 @@ "zetta-cluster": "^6.3.0" }, "scripts": { + "build": "babel . --out-dir dist --ignore node_modules/,dist/ --copy-files", "test": "./node_modules/.bin/mocha -R spec", "coverage": "bin/_coverage", "tag": "bin/_tag" From 0cba74d7bf3722a22c314aecaef86f83fb495b15 Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 09:39:43 +0200 Subject: [PATCH 02/14] :bug: Fix tests containing illegal values --- test/test_peer_registry.js | 8 ++++---- test/test_stream_topic.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/test_peer_registry.js b/test/test_peer_registry.js index 51eccf8..d9cb22d 100644 --- a/test/test_peer_registry.js +++ b/test/test_peer_registry.js @@ -55,8 +55,8 @@ describe('Peer Registry', function() { it('should get peers by id', function(done) { var reg = new PeerRegistry(opts); - reg.save({ id: 012345 }, function() { - reg.get(012345, function(err, peer) { + reg.save({ id: 12345 }, function() { + reg.get(12345, function(err, peer) { assert(peer); done(); }); @@ -65,7 +65,7 @@ describe('Peer Registry', function() { it('should delete peers', function(done) { var reg = new PeerRegistry(opts); - var peer = { id: 0123456 }; + var peer = { id: 123456 }; reg.save(peer, function() { reg.remove(peer, function(err, peer) { assert.ifError(err); @@ -105,7 +105,7 @@ describe('Peer Registry', function() { it('should update existing peers', function(done) { var reg = new PeerRegistry(opts); - var peer = { id: 012345 }; + var peer = { id: 12345 }; reg.save(peer, function() { reg.add(peer, function(err, result) { diff --git a/test/test_stream_topic.js b/test/test_stream_topic.js index 590914c..6e96399 100644 --- a/test/test_stream_topic.js +++ b/test/test_stream_topic.js @@ -150,10 +150,10 @@ describe('Stream Topic', function() { describe('.match()', function() { - function matchTest(query, topic, eval) { - it('should return ' + eval + ' for query ' + query + ' on topic ' + topic, function() { + function matchTest(query, topic, eval_) { + it('should return ' + eval_ + ' for query ' + query + ' on topic ' + topic, function() { var t = StreamTopic.parse(query); - assert.equal(t.match(topic), eval); + assert.equal(t.match(topic), eval_); }) } From 5f42023dab9f3b48f7450d9a651f5096c71edc1f Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 09:45:09 +0200 Subject: [PATCH 03/14] :sparkles: Add .babelrc --- .babelrc | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..93b346d --- /dev/null +++ b/.babelrc @@ -0,0 +1,10 @@ +{ + "presets": [ + ["env", { + "targets": { + "node": 0.10 + } + }] + ], + "plugins": ["transform-runtime"] +} \ No newline at end of file From 3c0cfed4e1d2223a0d1d45b1fc13dd3effbaa9d9 Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 09:51:49 +0200 Subject: [PATCH 04/14] :green_heart: Make travis build the Babel built version --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d5ca5f4..6252fc1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,9 @@ node_js: - "0.12" - "4.1.2" - "5" -sudo: false + - "6" + +script: + - npm run build + - cd dist + - npm test From 340ff71a4c8c4458ff80f5f82d72acdaa22cde6d Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 09:52:41 +0200 Subject: [PATCH 05/14] :bug: Install dependencies in the built version --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6252fc1..38911d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,5 @@ node_js: script: - npm run build - cd dist + - npm install - npm test From 381ef51ab479246c0ea5bec2d63e87a3856f6c02 Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 10:00:26 +0200 Subject: [PATCH 06/14] :racehorse: Link already installed deps instead of reinstalling them --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 38911d9..a4b3903 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,5 +9,5 @@ node_js: script: - npm run build - cd dist - - npm install + - ln -s node_modules dist/node_modules - npm test From 09951c1a42d97845111843792ce0b7342efd3e3c Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 10:38:12 +0200 Subject: [PATCH 07/14] :bug: Fix bad path in symbolic link --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a4b3903..fa0326a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,5 +9,5 @@ node_js: script: - npm run build - cd dist - - ln -s node_modules dist/node_modules + - ln -s ../node_modules node_modules - npm test From 500af2e351ca3127f1df5a70f5c3809d0da57a58 Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 10:50:27 +0200 Subject: [PATCH 08/14] :bug: Fix some tests --- test/test_event_socket.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_event_socket.js b/test/test_event_socket.js index 3fec047..13cd398 100644 --- a/test/test_event_socket.js +++ b/test/test_event_socket.js @@ -97,7 +97,7 @@ describe('EventSocket', function() { var ws = new Ws(); var client = new EventSocket(ws, 'some-topic', { streamEnabled: true }); ws.on('onsend', function(data, options, cb) { - assert.equal(data, '{"data":null}'); + assert.deepStrictEqual(JSON.parse(data), { data: null }); done(); }); client.send('some/topic', { data: null }); @@ -107,7 +107,7 @@ describe('EventSocket', function() { var ws = new Ws(); var client = new EventSocket(ws, 'some-topic', { streamEnabled: false }); ws.on('onsend', function(data, options, cb) { - assert.equal(data, '{"data":null}'); + assert.deepStrictEqual(JSON.parse(data), { data: null }); done(); }); client.send('some/topic', { data: null }); From 48e846111e7430d3a3d377180d186fc3db46136d Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 11:48:04 +0200 Subject: [PATCH 09/14] Revert ":bug: Fix some tests" This reverts commit 500af2e351ca3127f1df5a70f5c3809d0da57a58. --- test/test_event_socket.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_event_socket.js b/test/test_event_socket.js index 13cd398..3fec047 100644 --- a/test/test_event_socket.js +++ b/test/test_event_socket.js @@ -97,7 +97,7 @@ describe('EventSocket', function() { var ws = new Ws(); var client = new EventSocket(ws, 'some-topic', { streamEnabled: true }); ws.on('onsend', function(data, options, cb) { - assert.deepStrictEqual(JSON.parse(data), { data: null }); + assert.equal(data, '{"data":null}'); done(); }); client.send('some/topic', { data: null }); @@ -107,7 +107,7 @@ describe('EventSocket', function() { var ws = new Ws(); var client = new EventSocket(ws, 'some-topic', { streamEnabled: false }); ws.on('onsend', function(data, options, cb) { - assert.deepStrictEqual(JSON.parse(data), { data: null }); + assert.equal(data, '{"data":null}'); done(); }); client.send('some/topic', { data: null }); From 794f0b0bc6a66a960d33e544b80e2ca21f535b06 Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 14:40:27 +0200 Subject: [PATCH 10/14] :green_heart: Test uncompiled version on target node --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index fa0326a..b41cd70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,17 @@ node_js: - "4.1.2" - "5" - "6" +env: + global: + - TARGET_NODE_VERSION="6" script: + - npm install - npm run build + - | + if [[ "${TRAVIS_NODE_VERSION}" == "${TARGET_NODE_VERSION}" ]]; then + npm test + fi - cd dist - ln -s ../node_modules node_modules - npm test From cee172ea134c1ee996066852455f5c5f7dd2c9e8 Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 15:00:05 +0200 Subject: [PATCH 11/14] :bug: Attempt to fix arguments reference issue --- lib/event_socket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/event_socket.js b/lib/event_socket.js index 8c0db8e..4c1c827 100644 --- a/lib/event_socket.js +++ b/lib/event_socket.js @@ -223,7 +223,7 @@ EventSocket.prototype.send = function(topic, data) { } try { - data = JSON.stringify(data); + arguments[1] = JSON.stringify(data); } catch (err) { console.error('ws JSON.stringify ', err); return; From b70adb1fbf3b2dab1386f8d39d52c2d494867152 Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 15:06:17 +0200 Subject: [PATCH 12/14] :bug: Add missing var definition --- test/test_event_streams.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_event_streams.js b/test/test_event_streams.js index 06643fe..894a765 100644 --- a/test/test_event_streams.js +++ b/test/test_event_streams.js @@ -218,7 +218,7 @@ describe('Event Streams', function() { .server('hub', [Driver, Driver], ['cloud']) .server('hub2', [Driver, Driver], ['cloud']) .on('ready', function() { - app = cluster.servers['cloud']; + var app = cluster.servers['cloud']; urls.push('localhost:' + cluster.servers['cloud']._testPort); urls.push('localhost:' + cluster.servers['hub']._testPort); From 5d97437b258ceeb04dceef45db2f6725f87ebdb2 Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 15:54:05 +0200 Subject: [PATCH 13/14] :bug: Add missing variable declarations --- lib/api_resources/servers.js | 2 +- lib/web_socket.js | 2 +- test/test_peer_connection_api.js | 1 + test/test_query_api.js | 4 +++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/api_resources/servers.js b/lib/api_resources/servers.js index 1a56ae1..bdfcd40 100644 --- a/lib/api_resources/servers.js +++ b/lib/api_resources/servers.js @@ -97,7 +97,7 @@ ServerResource.prototype.subscribe = function(env, next) { } var self = this; - parsed = url.parse(env.request.url, true); + var parsed = url.parse(env.request.url, true); var topic = decodeURIComponent(parsed.query.topic); if (topic) { diff --git a/lib/web_socket.js b/lib/web_socket.js index 04692e2..b15a40e 100644 --- a/lib/web_socket.js +++ b/lib/web_socket.js @@ -24,7 +24,7 @@ var WebSocket = module.exports = function(address, httpOptions) { var self = this; if (httpOptions) { - for (k in httpOptions) { + for (var k in httpOptions) { self.options[k] = httpOptions[k]; } } diff --git a/test/test_peer_connection_api.js b/test/test_peer_connection_api.js index fe5d1e0..e163c5d 100644 --- a/test/test_peer_connection_api.js +++ b/test/test_peer_connection_api.js @@ -297,6 +297,7 @@ describe('Peer Connection API', function() { describe('/peer-management update API', function() { var cloud = null; var localOne = null; + var localPort = null; var cloudPort = null; var localOnePort = null; var connectionId = null; diff --git a/test/test_query_api.js b/test/test_query_api.js index 92e1bf3..3190783 100644 --- a/test/test_query_api.js +++ b/test/test_query_api.js @@ -332,8 +332,10 @@ describe('Zetta Query Api', function() { }); describe('Non provisioned devices', function() { + var app = null; + beforeEach(function(done) { - machine = Scientist.create(TestDriver); + var machine = Scientist.create(TestDriver); Scientist.init(machine); reg.save(machine, function(err) { assert.ok(!err); From 82ac552cf895e7e36f4c1aeede6d3fbeb888cf5b Mon Sep 17 00:00:00 2001 From: Marvin Roger Date: Wed, 12 Apr 2017 16:04:22 +0200 Subject: [PATCH 14/14] :bug: Fix PeerRegistry mock --- test/fixture/scout_test_mocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixture/scout_test_mocks.js b/test/fixture/scout_test_mocks.js index 4adc3d0..43b2bf8 100644 --- a/test/fixture/scout_test_mocks.js +++ b/test/fixture/scout_test_mocks.js @@ -83,7 +83,7 @@ MockPeerRegistry.prototype.add = function(peer, cb) { MockPeerRegistry.prototype.get = function(id, cb) { this.peers.forEach(function(peer) { if (peer.id === id) { - cb(null, JSON.stringify(peer)); + cb(null, peer); } }); };