Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Add nodestyle and lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
geek committed Jan 25, 2017
1 parent c28fdaa commit a9388c2
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ NodeReport*.txt
npm-debug.log
nodereport-*.tgz
nodereport_test.log
.eslintcache
40 changes: 22 additions & 18 deletions demo/api_call.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
// 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);
}
}

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://<machine>:8080/ or http://localhost:8080/');
console.log('api_call.js: Go to http://<machine>:8080/ or ' +
'http://localhost:8080/');

setTimeout(function(){
setTimeout(function() {
console.log('api_call.js: test timeout expired, exiting.');
process.exit(0);
}, 60000);
29 changes: 17 additions & 12 deletions demo/exception.js
Original file line number Diff line number Diff line change
@@ -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://<machine>:8080/ or http://localhost:8080/');
console.log('exception.js: Go to http://<machine>:8080/ or ' +
'http://localhost:8080/');

setTimeout(function() {
console.log('exception.js: test timeout expired, exiting.');
Expand Down
40 changes: 22 additions & 18 deletions demo/fatalerror.js
Original file line number Diff line number Diff line change
@@ -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());
}
}
}

Expand All @@ -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=<size in Mb> to change');
console.log('fatalerror.js: Go to http://<machine>:8080/ or http://localhost:8080/');
console.log('fatalerror.js: Note: heap default is 1.4Gb, use ' +
'--max-old-space-size=<size in Mb> to change');
console.log('fatalerror.js: Go to http://<machine>:8080/ or ' +
'http://localhost:8080/');

setTimeout(function(){
setTimeout(function() {
console.log('fatalerror.js: timeout expired, exiting.');
process.exit(0);
}, 60000);
61 changes: 33 additions & 28 deletions demo/loop.js
Original file line number Diff line number Diff line change
@@ -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:
}
}

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
"Richard Chamberlain <richard_chamberlain@uk.ibm.com> (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": "^1.1.0",
"tap": "^8.0.0"
}
}
4 changes: 2 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/test-api-bad-processobj.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
2 changes: 1 addition & 1 deletion test/test-api-bad-processversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

0 comments on commit a9388c2

Please sign in to comment.