Skip to content

Commit 63b6555

Browse files
committed
linter and test fix
1 parent 28d7264 commit 63b6555

File tree

6 files changed

+22
-30
lines changed

6 files changed

+22
-30
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ node_js:
33
- "4"
44
- "5"
55
- "stable"
6+
7+
before_script:
8+
- npm run lint

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ Then see [examples/express/server.js](/examples/express/server.js) for example u
2121

2222
Things to do:
2323

24-
- remove dependency from express and connect
24+
- support major web frameworks like: Express, Hapi, koa.js, Sails.js
25+
- add examples for every web frameworks
2526
- storing of client timings on first result postback (there's a todo in the `results` function about where to do this)
2627
- document more things
27-
- better unit test code coverage for everything
28-
- add examples for every web frameworks
29-
- add examples for every provider
30-
- add more providers (mongodb, mysql, redis)
31-
- remove old ids from global storage (when?)
28+
- add providers for pg, mongodb, mysql, redis and more
3229
- add eslint to travis
33-
- better eslint (https://github.com/NodeRedis/node_redis/blob/master/.eslintrc)

examples/express/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ app.get('/js-sleep', function(req, res) {
2222
setTimeout(function() {
2323
res.render('home');
2424
}, ms());
25-
}
25+
};
2626

2727
req.miniprofiler.timeQuery('custom', 'Sleeping...', waitBeforeRender, function() {
28-
return 300
28+
return 300;
2929
});
3030
});
3131

lib/miniprofiler.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,13 @@ function startProfiling(request, enabled) {
243243
};
244244

245245
if (enabled) {
246+
currentRequestExtension.id = uuid.v4();
246247
currentRequestExtension.startDate = Date.now();
247248
currentRequestExtension.startTime = process.hrtime();
248249
currentRequestExtension.stopTime = null;
249250
currentRequestExtension.stepGraph = makeStep(request.path, currentRequestExtension.startTime, null);
250-
currentRequestExtension.id = uuid.v4();
251251
currentRequestExtension.customTimings = {};
252+
debug(`Profiling started for ${request.path} with id ${currentRequestExtension.id}`);
252253
}
253254
currentRequestExtension.timeQuery = function() {
254255
var args = Array.prototype.slice.call(arguments, enabled ? 0 : 3);
@@ -284,6 +285,7 @@ function stopProfiling(request){
284285

285286
var extension = request.miniprofiler;
286287
var time = process.hrtime();
288+
debug(`Profiling stopped for ${request.path} with id ${extension.id}`);
287289
if(extension.stepGraph.parent != null){
288290
throw new Error('profiling ended while still in a function, was left in ['+extension.stepGraph.name+']');
289291
}
@@ -346,7 +348,7 @@ function step(name, request, call) {
346348
* to have ended the query.
347349
*/
348350
function timeQuery(extension, type, query, executeFunction) {
349-
debug(`timeQuery "${type}" with command "${query}"`);
351+
debug(`Started timed query "${type}" with command "${query}"`);
350352

351353
var time = process.hrtime();
352354
var startDate = Date.now();
@@ -367,21 +369,17 @@ function timeQuery(extension, type, query, executeFunction) {
367369
};
368370
extension.stepGraph.customTimings[type].push(customTiming);
369371

370-
//Do we need this?
371-
/*
372372
for(var i = 0; i < params.length; i++){
373-
var param = params[i];
374373
if(_.isFunction(params[i])){
374+
var param = params[i];
375375
params[i] = function() {
376-
//customTiming.stopTime = process.hrtime();
377-
376+
debug(`Stopped timed query "${type}" with command "${query}"`);
377+
customTiming.stopTime = process.hrtime();
378378
var ret = param.apply(this, arguments);
379-
380379
return ret;
381380
};
382381
}
383382
}
384-
*/
385383

386384
var ret = executeFunction.apply(this, params);
387385

tests/basic-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ describe('MiniProfiler Tests', function() {
2525
expect(result.Root.Children).to.be.empty;
2626
expect(result.Root.CustomTimings).to.have.property('custom');
2727
expect(result.Root.CustomTimings.custom).to.have.lengthOf(1);
28-
expect(result.Root.CustomTimings.custom[0].ExecuteType).to.be.equal('custom')
29-
expect(result.Root.CustomTimings.custom[0].CommandString).to.be.equal('Sleeping...')
30-
expect(result.Root.CustomTimings.custom[0].DurationMilliseconds).to.be.above(result.DurationMilliseconds);
28+
29+
expect(result.Root.CustomTimings.custom[0].ExecuteType).to.be.equal('custom');
30+
expect(result.Root.CustomTimings.custom[0].CommandString).to.be.equal('Sleeping...');
31+
expect(result.Root.CustomTimings.custom[0].DurationMilliseconds).to.be.below(result.DurationMilliseconds);
3132
done();
3233
});
3334
});

tests/server/default.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,9 @@ app.get('/step-two', (req, res) => {
2424
});
2525

2626
app.get('/js-sleep', function(req, res) {
27-
var waitBeforeRender = function(ms) {
28-
setTimeout(function() {
29-
res.send();
30-
}, ms());
31-
}
32-
33-
req.miniprofiler.timeQuery('custom', 'Sleeping...', waitBeforeRender, function() {
34-
return 300
35-
});
27+
req.miniprofiler.timeQuery('custom', 'Sleeping...', setTimeout, function() {
28+
res.send();
29+
}, 300);
3630
});
3731

3832
module.exports = require('./base.js')(app);

0 commit comments

Comments
 (0)