Skip to content

Commit 00c5a55

Browse files
committed
better linter and more unprofiled tests
1 parent 8932443 commit 00c5a55

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"rules": {
99
"semi": [2, "always"],
1010
"no-unused-vars": ["error", { "vars": "all", "args": "none" }],
11-
"quotes": ["error", "single", { "avoidEscape": true } ]
11+
"quotes": ["error", "single", { "avoidEscape": true } ],
12+
"space-before-function-paren": ["error", "never"]
1213
}
1314
}

lib/miniprofiler.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function static(reqPath, res) {
7373
fs.readFile(path.join(includesDir, reqPath), function(err, data) {
7474
if (err) {
7575
debug(err);
76-
res.setHeader('Content-Type', 'text/html');
76+
res.setHeader('Content-Type', 'text/plain');
7777
res.writeHead(404);
7878
res.end('Resource unavailable.');
7979
return;
@@ -92,7 +92,7 @@ function results(req, res) {
9292
var data = storage(id);
9393
if (!data) {
9494
debug(`Id '${id}' not found.`);
95-
res.setHeader('Content-Type', 'text/html');
95+
res.setHeader('Content-Type', 'text/plain');
9696
res.writeHead(404);
9797
res.end(`Id '${id}' not found.`);
9898
return;
@@ -155,7 +155,9 @@ function middleware(f) {
155155

156156
if(req.path.startsWith(resourcePath)) {
157157
if (!enabled) {
158-
res.send(404);
158+
res.setHeader('Content-Type', 'text/plain');
159+
res.writeHead(404);
160+
res.end(`MiniProfiler is disabled.`);
159161
return;
160162
}
161163

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"main": "lib/miniprofiler.js",
66
"scripts": {
77
"lint": "eslint .",
8-
"test": "istanbul cover node_modules/mocha/bin/_mocha tests/",
8+
"test": "mocha tests/",
9+
"test:watch": "mocha tests/ --watch",
10+
"coverage": "istanbul cover node_modules/mocha/bin/_mocha tests/",
911
"example": "node examples/express/server.js"
1012
},
1113
"repository": {

tests/assets-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('MiniProfiler Assets Tests', function() {
2424
it('Unknown file should return 404', function(done) {
2525
server.get('/mini-profiler-resources/unkown.js', (err, response, body) => {
2626
expect(response.statusCode).to.be.equal(404);
27-
expect(response.headers['content-type']).to.be.equal('text/html');
27+
expect(response.headers['content-type']).to.be.equal('text/plain');
2828
expect(body).to.be.equal('Resource unavailable.');
2929
done();
3030
});

tests/share-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('MiniProfiler Share Tests', function() {
1313

1414
var expectNotFoundResponse = (done) => (err, response, body) => {
1515
expect(response.statusCode).to.be.equal(404);
16-
expect(response.headers['content-type']).to.be.equal('text/html');
16+
expect(response.headers['content-type']).to.be.equal('text/plain');
1717
done();
1818
};
1919

tests/unprofiled-test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,28 @@ describe('MiniProfiler Unprofiled Tests', function() {
55
before(server.start);
66
after(server.stop);
77

8-
it('Unprofiled route should not return Profiler ID', function(done) {
8+
it('Unprofiled server should not return Profiler ID', function(done) {
99
server.get('/', (err, response) => {
1010
expect(response.headers).to.not.include.keys('x-miniprofiler-ids');
1111
done();
1212
});
1313
});
14+
15+
var paths = [
16+
'/',
17+
'/includes.css',
18+
'/results',
19+
'/results?id=2'
20+
];
21+
22+
paths.forEach((path) => {
23+
it(`Unprofiled server should not find ${path} route`, function(done) {
24+
server.get(`/mini-profiler-resources${path}`, (err, response, body) => {
25+
expect(response.statusCode).to.be.equal(404);
26+
expect(response.headers['content-type']).to.be.equal('text/plain');
27+
expect(body).to.be.equal('MiniProfiler is disabled.');
28+
done();
29+
});
30+
});
31+
});
1432
});

0 commit comments

Comments
 (0)