Skip to content

Commit 801bd19

Browse files
committed
refactoring-tests
1 parent 0ae9eec commit 801bd19

File tree

14 files changed

+77
-57
lines changed

14 files changed

+77
-57
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"main": "lib/miniprofiler.js",
66
"scripts": {
77
"lint": "eslint .",
8-
"test": "mocha tests/",
9-
"test:watch": "mocha tests/ --watch",
8+
"test": "mocha tests/ -c",
9+
"test:watch": "mocha tests/ -c --watch",
1010
"example": "node examples/express.js",
1111
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- tests/ -R spec",
1212
"check-coverage": "istanbul check-coverage --statements 70 --branches 70 --functions 70 --lines 70",

tests/assets-test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
var expect = require('chai').expect;
22
var fs = require('fs');
3+
var servers = require('./servers');
34

4-
for (var fw of ['express', 'koa']) {
5-
var server = require(`./server/${fw}/default`);
6-
7-
describe(`[${fw}] MiniProfiler Assets Tests`, function() {
8-
before(server.start);
5+
for (var server of servers) {
6+
describe(`[${server.framework}] MiniProfiler Assets Tests`, function() {
7+
before(server.start.bind(null, 'default'));
98
after(server.stop);
109

1110
var files = [
@@ -17,8 +16,10 @@ for (var fw of ['express', 'koa']) {
1716
files.forEach((file) => {
1817
it(`Should return ${file} file`, function(done) {
1918
server.get(`/mini-profiler-resources/${file}`, (err, response, body) => {
20-
expect(body).to.be.equal(fs.readFileSync(`./ui/${file}`, 'utf-8'));
21-
done();
19+
fs.readFile(`./ui/${file}`, 'utf-8', (err, content) => {
20+
expect(body).to.be.equal(content);
21+
done();
22+
});
2223
});
2324
});
2425
});

tests/basic-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var expect = require('chai').expect;
2+
var servers = require('./servers');
23

3-
for (var fw of ['express', 'koa']) {
4-
var server = require(`./server/${fw}/default`);
4+
for (var server of servers) {
55

6-
describe(`[${fw}] MiniProfiler Tests`, function() {
7-
before(server.start);
6+
describe(`[${server.framework}] MiniProfiler Tests`, function() {
7+
before(server.start.bind(null, 'default'));
88
after(server.stop);
99

1010
it('Profiled routes should always return Profiler ID', function(done) {
@@ -23,7 +23,7 @@ for (var fw of ['express', 'koa']) {
2323
var result = JSON.parse(body);
2424
expect(result.Id).to.equal(ids[0]);
2525
expect(result.Name).to.equal('/js-sleep');
26-
expect(result.DurationMilliseconds).to.be.above(200);
26+
expect(result.DurationMilliseconds).to.be.above(50);
2727
expect(result.Root.Children).to.be.empty;
2828
expect(result.Root.CustomTimings).to.have.property('custom');
2929
expect(result.Root.CustomTimings.custom).to.have.lengthOf(1);

tests/server/base.js

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ app.get('/step-two', (req, res) => {
2626
app.get('/js-sleep', function(req, res) {
2727
req.miniprofiler.timeQuery('custom', 'Sleeping...', setTimeout, function() {
2828
res.send();
29-
}, 300);
29+
}, 50);
3030
});
3131

32-
module.exports = require('../base.js')(app);
32+
module.exports = app;

tests/servers/express/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var server;
2+
module.exports = {
3+
start: function(name) {
4+
var app = require(`./${name}.js`);
5+
server = app.listen(8080);
6+
},
7+
stop: function() {
8+
server.close();
9+
}
10+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ app.get('/', (req, res) => {
1313
res.send();
1414
});
1515

16-
module.exports = require('../base.js')(app);
16+
module.exports = app;

tests/servers/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var request = require('request');
2+
var frameworks = [ 'koa', 'express' ];
3+
var all = [ ];
4+
5+
for (var fw of frameworks) {
6+
server = require(`./${fw}`)
7+
server.framework = fw;
8+
9+
server.get = (path, cb) => {
10+
request.get(`http://localhost:8080${path}`, (err, response, body) => {
11+
cb(err, response, body);
12+
});
13+
}
14+
15+
server.post = (path, params, cb) => {
16+
request.post({url: `http://localhost:8080${path}`, form: params }, (err, response, body) => {
17+
cb(err, response, body);
18+
});
19+
}
20+
21+
all.push(server);
22+
}
23+
24+
module.exports = all;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ app.use(route.get('/js-sleep', function *(){
2828
this.req.miniprofiler.timeQuery('custom', 'Sleeping...', setTimeout, function() {
2929
this.body = '';
3030
resolve();
31-
}, 300);
31+
}, 50);
3232
});
3333
}));
3434

35-
module.exports = require('../base.js')(app);
35+
module.exports = app;

tests/servers/koa/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var server;
2+
module.exports = {
3+
start: function(name) {
4+
var app = require(`./${name}.js`);
5+
server = app.listen(8080);
6+
},
7+
stop: function() {
8+
server.close();
9+
}
10+
}

0 commit comments

Comments
 (0)