diff --git a/.gitignore b/.gitignore index e19ac5f..04ddaad 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ NodeReport*.txt npm-debug.log nodereport-*.tgz nodereport_test.log +.eslintcache diff --git a/demo/api_call.js b/demo/api_call.js index bb4e580..804c150 100644 --- a/demo/api_call.js +++ b/demo/api_call.js @@ -1,25 +1,28 @@ // Example - generation of NodeReport via API call +'use strict'; + var nodereport = require('nodereport'); -var http = require("http"); +var http = require('http'); var count = 0; function my_listener(request, response) { - switch(count++) { - case 0: - response.writeHead(200,{"Content-Type": "text/plain"}); - response.write("\nRunning NodeReport API demo... refresh page to trigger NodeReport"); - response.end(); - break; - case 1: - response.writeHead(200,{"Content-Type": "text/plain"}); - // Call the nodereport module to trigger a NodeReport - var filename = nodereport.triggerReport(); - response.write("\n" + filename + " written - refresh page to close"); - response.end(); - break; - default: - process.exit(0); + switch (count++) { + case 0: + response.writeHead(200, {'Content-Type': 'text/plain'}); + response.write('\nRunning NodeReport API demo... refresh page to ' + + 'trigger NodeReport'); + response.end(); + break; + case 1: + response.writeHead(200, {'Content-Type': 'text/plain'}); + // Call the nodereport module to trigger a NodeReport + var filename = nodereport.triggerReport(); + response.write('\n' + filename + ' written - refresh page to close'); + response.end(); + break; + default: + process.exit(0); } } @@ -27,9 +30,10 @@ var http_server = http.createServer(my_listener); http_server.listen(8080); console.log('api_call.js: Node running'); -console.log('api_call.js: Go to http://:8080/ or http://localhost:8080/'); +console.log('api_call.js: Go to http://:8080/ or ' + + 'http://localhost:8080/'); -setTimeout(function(){ +setTimeout(function() { console.log('api_call.js: test timeout expired, exiting.'); process.exit(0); }, 60000); diff --git a/demo/exception.js b/demo/exception.js index e677acf..30b8616 100644 --- a/demo/exception.js +++ b/demo/exception.js @@ -1,31 +1,36 @@ // Example - generation of NodeReport on uncaught exception -require('nodereport').setEvents("exception"); -var http = require("http"); +'use strict'; + +require('nodereport').setEvents('exception'); +var http = require('http'); var count = 0; function my_listener(request, response) { - switch(count++) { - case 0: - response.writeHead(200,{"Content-Type": "text/plain"}); - response.write("\nRunning NodeReport exception demo... refresh page to cause exception (application will terminate)"); - response.end(); - break; - default: - throw new UserException('*** exception.js: exception thrown from my_listener()'); + switch (count++) { + case 0: + response.writeHead(200, {'Content-Type': 'text/plain'}); + response.write('\nRunning NodeReport exception demo... refresh page to ' + + 'cause exception (application will terminate)'); + response.end(); + break; + default: + throw new UserException('*** exception.js: exception thrown from ' + + 'my_listener()'); } } function UserException(message) { this.message = message; - this.name = "UserException"; + this.name = 'UserException'; } var http_server = http.createServer(my_listener); http_server.listen(8080); console.log('exception.js: Node running'); -console.log('exception.js: Go to http://:8080/ or http://localhost:8080/'); +console.log('exception.js: Go to http://:8080/ or ' + + 'http://localhost:8080/'); setTimeout(function() { console.log('exception.js: test timeout expired, exiting.'); diff --git a/demo/fatalerror.js b/demo/fatalerror.js index 0abba5c..b3f59d4 100644 --- a/demo/fatalerror.js +++ b/demo/fatalerror.js @@ -1,24 +1,26 @@ // Example - generation of Nodereport on fatal error (Javascript heap OOM) -require('nodereport').setEvents("fatalerror"); +'use strict'; + +require('nodereport').setEvents('fatalerror'); var http = require('http'); var count = 0; function my_listener(request, response) { - switch(count++) { - case 0: - response.writeHead(200,{"Content-Type": "text/plain"}); - response.write("\nRunning NodeReport fatal error demo... refresh page to trigger excessive memory usage (application will terminate)"); - response.end(); - break; - case 1: - console.log('heap_oom.js: allocating excessive Javascript heap memory....'); - var list = []; - while (true) { - list.push(new MyRecord()); - } - response.end(); - break; + switch (count++) { + case 0: + response.writeHead(200, {'Content-Type': 'text/plain'}); + response.write('\nRunning NodeReport fatal error demo... refresh page ' + + 'to trigger excessive memory usage (application will terminate)'); + response.end(); + break; + case 1: + console.log('heap_oom.js: allocating excessive Javascript heap ' + + 'memory....'); + var list = []; + while (true) { + list.push(new MyRecord()); + } } } @@ -32,10 +34,12 @@ var http_server = http.createServer(my_listener); http_server.listen(8080); console.log('fatalerror.js: Node running'); -console.log('fatalerror.js: Note: heap default is 1.4Gb, use --max-old-space-size= to change'); -console.log('fatalerror.js: Go to http://:8080/ or http://localhost:8080/'); +console.log('fatalerror.js: Note: heap default is 1.4Gb, use ' + + '--max-old-space-size= to change'); +console.log('fatalerror.js: Go to http://:8080/ or ' + + 'http://localhost:8080/'); -setTimeout(function(){ +setTimeout(function() { console.log('fatalerror.js: timeout expired, exiting.'); process.exit(0); }, 60000); diff --git a/demo/loop.js b/demo/loop.js index b50e44b..4e2734a 100644 --- a/demo/loop.js +++ b/demo/loop.js @@ -1,37 +1,42 @@ // Example - geneation of Nodereport via signal for a looping application -require('nodereport').setEvents("signal"); -var http = require("http"); +'use strict'; + +require('nodereport').setEvents('signal'); +var http = require('http'); var count = 0; function my_listener(request, response) { - switch(count++) { - case 0: - response.writeHead(200,{"Content-Type": "text/plain"}); - response.write("\nRunning NodeReport looping application demo. Node process ID = " + process.pid); - response.write("\n\nRefresh page to enter loop, then use 'kill -USR2 " + process.pid + "' to trigger NodeReport"); - response.end(); - break; - case 1: - console.log("loop.js: going to loop now, use 'kill -USR2 " + process.pid + "' to trigger NodeReport"); - var list = []; - for (var i=0; i<10000000000; i++) { - for (var j=0; i<1000; i++) { - list.push(new MyRecord()); - } - for (var j=0; i<1000; i++) { - list[j].id += 1; - list[j].account += 2; - } - for (var j=0; i<1000; i++) { - list.pop(); + switch (count++) { + case 0: + response.writeHead(200, {'Content-Type': 'text/plain'}); + response.write('\nRunning NodeReport looping application demo. Node ' + + 'process ID = ' + process.pid); + response.write('\n\nRefresh page to enter loop, then use \'kill -USR2 ' + + process.pid + '\' to trigger NodeReport'); + response.end(); + break; + case 1: + console.log('loop.js: going to loop now, use \'kill -USR2 ' + + process.pid + '\' to trigger NodeReport'); + var list = []; + for (var i = 0; i < 10000000000; i++) { + for (var j = 0; i < 1000; i++) { + list.push(new MyRecord()); + } + for (j = 0; i < 1000; i++) { + list[j].id += 1; + list[j].account += 2; + } + for (j = 0; i < 1000; i++) { + list.pop(); + } } - } - response.writeHead(200,{"Content-Type": "text/plain"}); - response.write("\nNodeReport demo.... finished looping"); - response.end(); - break; - default: + response.writeHead(200, {'Content-Type': 'text/plain'}); + response.write('\nNodeReport demo.... finished looping'); + response.end(); + break; + default: } } diff --git a/index.js b/index.js index 2860d19..7b76b95 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,11 @@ // Main module entry point for nodereport +'use strict'; const api = require('./api'); // NODEREPORT_EVENTS env var overrides the defaults -const options = process.env.NODEREPORT_EVENTS || 'exception+fatalerror+signal+apicall'; +const options = process.env.NODEREPORT_EVENTS || + 'exception+fatalerror+signal+apicall'; api.setEvents(options); exports.triggerReport = api.triggerReport; diff --git a/package.json b/package.json index a6a0419..94d59d7 100644 --- a/package.json +++ b/package.json @@ -18,12 +18,15 @@ "Richard Chamberlain (https://github.com/rnchamberlain)" ], "scripts": { + "lint": "node-style", + "pretest": "npm run lint", "test": "tap test/test*.js" }, "bugs": { "url": "https://github.com/nodejs/nodereport/issues" }, "devDependencies": { + "node-style": "^2.0.0", "tap": "^8.0.0" } } diff --git a/test/common.js b/test/common.js index bc11f42..15f9979 100644 --- a/test/common.js +++ b/test/common.js @@ -61,9 +61,9 @@ exports.validate = (t, report, options) => { if (this.isWindows()) { // On Windows we need to strip double quotes from the command line in // the report, and escape backslashes in the regex comparison string. - t.match(nodeReportSection.replace(/"/g,''), + t.match(nodeReportSection.replace(/"/g, ''), new RegExp('Command line: ' - + (options.commandline).replace(/\\/g,'\\\\')), + + (options.commandline).replace(/\\/g, '\\\\')), 'Checking report contains expected command line'); } else { t.match(nodeReportSection, diff --git a/test/test-api-bad-processobj.js b/test/test-api-bad-processobj.js index 652bbfd..71ab2c0 100644 --- a/test/test-api-bad-processobj.js +++ b/test/test-api-bad-processobj.js @@ -19,7 +19,7 @@ if (process.argv[2] === 'child') { tap.equal(reports.length, 1, 'Found reports ' + reports); const report = reports[0]; const validateOpts = { pid: child.pid, expectedVersions: [], - commandline: child.spawnargs.join(' '), }; + commandline: child.spawnargs.join(' ') }; common.validate(tap, report, validateOpts); }); } diff --git a/test/test-api-bad-processversion.js b/test/test-api-bad-processversion.js index 6d9cede..c04fa53 100644 --- a/test/test-api-bad-processversion.js +++ b/test/test-api-bad-processversion.js @@ -19,7 +19,7 @@ if (process.argv[2] === 'child') { tap.equal(reports.length, 1, 'Found reports ' + reports); const report = reports[0]; const validateOpts = { pid: child.pid, expectNodeVersion: true, - commandline: child.spawnargs.join(' '), }; + commandline: child.spawnargs.join(' ') }; common.validate(tap, report, validateOpts); }); }