Skip to content

Commit

Permalink
ES6 Linting
Browse files Browse the repository at this point in the history
- changed var statements to const/let
- added dev dependency on @types/node to remove warnings from index.d.ts
- migrated istanbul to nyc coverage
- added package lock
  • Loading branch information
aricart committed Mar 25, 2019
1 parent 1f558a9 commit 3f70f04
Show file tree
Hide file tree
Showing 53 changed files with 6,176 additions and 905 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module.exports = {
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"mocha": true,
"node": true
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"rules": {
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ xunit.xml

logs/*
reports/*
tmp/*
tmp/*
coverage/*
.nyc_output/*
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ tmp/*
benchmark/
examples/
test/
coverage/
.istanbul.yml
.travis.yml
.eslintrc.js
.eslintignore
.nyc_output/
crockford.jscsrc
Makefile
TODO
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ language: node_js
sudo: false

node_js:
- "8"
- "10"
- "11"

cache: npm

git:
depth: false

env:
- NATS_VERSION=v1.3.0
- NATS_VERSION=v1.4.1

before_script:
- wget "https://github.com/nats-io/gnatsd/releases/download/$NATS_VERSION/gnatsd-$NATS_VERSION-linux-amd64.zip" -O tmp.zip
- unzip tmp.zip
- mv gnatsd-$NATS_VERSION-linux-amd64 gnatsd

script:
- if [[ "$TRAVIS_NODE_VERSION" == 6 ]]; then npm test; fi
- if [[ "$TRAVIS_NODE_VERSION" == 8 ]]; then npm test; fi
- if [[ "$TRAVIS_NODE_VERSION" == 10 ]]; then npm run coveralls; fi
- if [[ "$TRAVIS_NODE_VERSION" == 10 ]]; then npm test; fi
- if [[ "$TRAVIS_NODE_VERSION" == 11 ]]; then npm run coveralls; fi
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A [Node.js](http://nodejs.org/) client for the [NATS messaging system](https://n
[![Build Status](https://travis-ci.org/nats-io/node-nats.svg?branch=master)](https://travis-ci.org/nats-io/node-nats)
[![Coveralls](https://img.shields.io/coveralls/github/nats-io/node-nats/master.svg)](https://coveralls.io/r/nats-io/node-nats?branch=master)
[![npm](https://img.shields.io/npm/v/nats.svg)](https://www.npmjs.com/package/nats)
[![npm](https://img.shields.io/npm/dt/nats.svg)](https://www.npmjs.com/package/nats)
[![npm](https://img.shields.io/npm/dm/nats.svg)](https://www.npmjs.com/package/nats)

## Installation
Expand Down Expand Up @@ -208,7 +209,7 @@ See examples for more usage.
```javascript
// Simple connect using credentials file. This loads JWT and signing key
// each time that NATS connects.
var nc = NATS.connect('connect.ngs.global', NATS.creds("./myid.creds");
var nc = NATS.connect('connect.ngs.global', NATS.creds("./myid.creds"));

// Setting nkey and signing callback directly.
var nc = NATS.connect(url, {
Expand Down
20 changes: 10 additions & 10 deletions benchmark/pub_perf.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
"use strict";

var NATS = require('../lib/nats');
var nats = NATS.connect();
var fs = require('fs');
const NATS = require('../lib/nats');
const nats = NATS.connect();
const fs = require('fs');

///////////////////////////////////////
// Publish Performance
///////////////////////////////////////

var loop = 1000000;
var hash = 2500;
const loop = 1000000;
const hash = 2500;

console.log('Publish Performance Test');

nats.on('connect', function() {

var start = new Date();
const start = new Date();

var invalid2octet = Buffer.from('\xc3\x28', 'binary');
const invalid2octet = Buffer.from('\xc3\x28', 'binary');

for (var i = 0; i < loop; i++) {
for (let i = 0; i < loop; i++) {
nats.publish('test', invalid2octet);
//nats.publish('test', 'ok');
if (i % hash === 0) {
Expand All @@ -28,8 +28,8 @@ nats.on('connect', function() {
}

nats.flush(function() {
var stop = new Date();
var mps = parseInt(loop / ((stop - start) / 1000), 10);
const stop = new Date();
const mps = parseInt(loop / ((stop - start) / 1000), 10);
log("pub", loop, stop - start);
console.log('\nPublished at ' + mps + ' msgs/sec');
});
Expand Down
22 changes: 11 additions & 11 deletions benchmark/pub_sub_perf.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
"use strict";

var fs = require('fs');
var NATS = require('../lib/nats');
var nc1 = NATS.connect();
var nc2 = NATS.connect();
const fs = require('fs');
const NATS = require('../lib/nats');
const nc1 = NATS.connect();
const nc2 = NATS.connect();

///////////////////////////////////////
// Publish/Subscribe Performance
///////////////////////////////////////

var loop = 1000000;
var hash = 2500;
const loop = 1000000;
const hash = 2500;

console.log('Publish/Subscribe Performance Test');

nc1.on('connect', function() {

var received = 0;
var start = new Date();
let received = 0;
const start = new Date();

nc1.subscribe('test', function() {
received += 1;

if (received === loop) {
var stop = new Date();
var mps = parseInt(loop / ((stop - start) / 1000), 10);
const stop = new Date();
const mps = parseInt(loop / ((stop - start) / 1000), 10);
console.log('\nPublished/Subscribe at ' + mps + ' msgs/sec');
console.log('Received ' + received + ' messages');
log("pubsub", loop, stop - start);
Expand All @@ -33,7 +33,7 @@ nc1.on('connect', function() {

// Make sure sub is registered
nc1.flush(function() {
for (var i = 0; i < loop; i++) {
for (let i = 0; i < loop; i++) {
nc2.publish('test', 'ok');
if (i % hash === 0) {
process.stdout.write('+');
Expand Down
24 changes: 12 additions & 12 deletions benchmark/reconnect_perf.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
"use strict";

var fs = require('fs');
var NATS = require('../lib/nats'),
const fs = require('fs');
const NATS = require('../lib/nats'),
nsc = require('../test/support/nats_server_control');


///////////////////////////////////////
// Reconnect Performance
///////////////////////////////////////

var loop = 1000000;
var hash = 2500;
var PORT = 1426;
var server;
var start;
const loop = 1000000;
const hash = 2500;
const PORT = 1426;
let server;
let start;

console.log('Reconnect Performance Test');

server = nsc.start_server(PORT, function() {
var nc = NATS.connect({
const nc = NATS.connect({
'port': PORT
});
nc.on('connect', function() {
var fun = function() {
const fun = function () {
//do nothing
};
for (var i = 0; i < loop; i++) {
for (let i = 0; i < loop; i++) {
nc.subscribe('test' + i, fun);
if (i % hash === 0) {
process.stdout.write('+');
Expand All @@ -39,8 +39,8 @@ server = nsc.start_server(PORT, function() {
});
nc.on('reconnect', function() {
nc.flush(function() {
var stop = new Date();
var t = stop - start;
const stop = new Date();
const t = stop - start;
console.log('\nReconnected in ' + t + ' ms');
nc.close();
server.kill();
Expand Down
26 changes: 13 additions & 13 deletions benchmark/request_perf.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
"use strict";
var fs = require('fs');
var NATS = require('../lib/nats');
var nc1 = NATS.connect();
var nc2 = NATS.connect();
const fs = require('fs');
const NATS = require('../lib/nats');
const nc1 = NATS.connect();
const nc2 = NATS.connect();

///////////////////////////////////////
// Request Performance
///////////////////////////////////////

var loop = 100000;
var hash = 1000;
var received = 0;
const loop = 100000;
const hash = 1000;
let received = 0;

console.log('Request Performance Test');

nc1.on('connect', function() {

var start = new Date();
const start = new Date();

nc1.subscribe('request.test', function(msg, reply) {
nc1.publish(reply, 'ok');
Expand All @@ -25,17 +25,17 @@ nc1.on('connect', function() {
// Need to flush here since using separate connections.
nc1.flush(function() {

for (var i = 0; i < loop; i++) {
for (let i = 0; i < loop; i++) {
nc2.request('request.test', 'help', {
'max': 1
}, function() {
received += 1;
if (received === loop) {
var stop = new Date();
var rps = parseInt(loop / ((stop - start) / 1000), 10);
const stop = new Date();
const rps = parseInt(loop / ((stop - start) / 1000), 10);
console.log('\n' + rps + ' request-responses/sec');
var latmicros = ((stop - start) * 1000) / (loop * 2);
var lat = parseInt(latmicros, 10); // Request=2, Reponse=2 RTs
const latmicros = ((stop - start) * 1000) / (loop * 2);
const lat = parseInt(latmicros, 10); // Request=2, Reponse=2 RTs
console.log('Avg roundtrip latency: ' + lat + ' microseconds');
log("rr", loop, stop - start, latmicros);
} else if (received % hash === 0) {
Expand Down
18 changes: 9 additions & 9 deletions benchmark/sub_perf.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"use strict";

var fs = require('fs');
var NATS = require('../lib/nats');
var nats = NATS.connect();
const fs = require('fs');
const NATS = require('../lib/nats');
const nats = NATS.connect();

///////////////////////////////////////
// Subscribe Performance
///////////////////////////////////////

var start;
var loop = 1000000;
var hash = 2500;
var received = 0;
let start;
const loop = 1000000;
const hash = 2500;
let received = 0;

console.log('Subscribe Performance Test');
console.log("Waiting on %d messages", loop);
Expand All @@ -22,9 +22,9 @@ nats.subscribe('test', function() {
start = new Date();
}
if (received === loop) {
var stop = new Date();
const stop = new Date();
console.log('\nDone test');
var mps = parseInt(loop / ((stop - start) / 1000), 10);
const mps = parseInt(loop / ((stop - start) / 1000), 10);
console.log('Received at ' + mps + ' msgs/sec');
log("sub", loop, stop - start);
} else if (received % hash === 0) {
Expand Down
17 changes: 8 additions & 9 deletions examples/expander
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
*/
"use strict";

var url = require("url");
var dns = require("dns");
const url = require("url");
const dns = require("dns");

// Mapping function for A records
function mapA(u) {
return function(a) {
return a.map(function(s) {
var auth = "";
let auth = "";
if (u.auth) {
auth = u.auth + "@";
}
var hostport = s;
let hostport = s;
if(u.port) {
hostport += ":" + u.port;
}
Expand All @@ -38,11 +38,11 @@ function mapA(u) {
function mapSrv(u) {
return function(a) {
return a.map(function(s) {
var auth = "";
let auth = "";
if (u.auth) {
auth = u.auth + "@";
}
var hostport = s.name;
let hostport = s.name;
if(s.port) {
hostport += ":" + s.port;
}
Expand All @@ -66,9 +66,9 @@ function mapSrv(u) {
// });
//
function expand(natsurl, type, callback) {
var u = url.parse(natsurl);
const u = url.parse(natsurl);
type = type.toUpperCase();
var fun = null;
let fun = null;
switch(type) {
case "A":
fun = mapA(u);
Expand All @@ -87,4 +87,3 @@ function expand(natsurl, type, callback) {
callback(undefined, fun(records));
});
}

Loading

0 comments on commit 3f70f04

Please sign in to comment.