|
| 1 | +var expect = require('chai').expect; |
| 2 | +var miniprofiler = require('../miniprofiler.js'); |
| 3 | +var server = require('./demo-server.js'); |
| 4 | + |
| 5 | +describe('MiniProfiler Step Tests', function() { |
| 6 | + before(server.start); |
| 7 | + after(server.stop); |
| 8 | + |
| 9 | + it('Index route should not profile any step', function(done) { |
| 10 | + server.get('/', (err, response, body) => { |
| 11 | + var ids = JSON.parse(response.headers['x-miniprofiler-ids']); |
| 12 | + expect(ids).to.have.lengthOf(1); |
| 13 | + |
| 14 | + server.post('/mini-profiler-resources/results', { id: ids[0], popup: 1 }, (err, response, body) => { |
| 15 | + var result = JSON.parse(body) |
| 16 | + expect(result.Id).to.equal(ids[0]); |
| 17 | + expect(result.Name).to.equal('/'); |
| 18 | + expect(result.Root.Children).to.be.empty; |
| 19 | + |
| 20 | + done(); |
| 21 | + }); |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + it('step route should profile one step', function(done) { |
| 26 | + server.get('/step', (err, response, body) => { |
| 27 | + var ids = JSON.parse(response.headers['x-miniprofiler-ids']); |
| 28 | + expect(ids).to.have.lengthOf(1); |
| 29 | + |
| 30 | + server.post('/mini-profiler-resources/results', { id: ids[0], popup: 1 }, (err, response, body) => { |
| 31 | + var result = JSON.parse(body) |
| 32 | + expect(result.Id).to.equal(ids[0]); |
| 33 | + expect(result.Name).to.equal('/step'); |
| 34 | + expect(result.Root.Children).to.have.lengthOf(1); |
| 35 | + |
| 36 | + expect(result.Root.Children[0].Name).to.equal('Step 1'); |
| 37 | + expect(result.Root.Children[0].Children).to.be.empty; |
| 38 | + |
| 39 | + done(); |
| 40 | + }); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + it('step-two route should profile two nested step', function(done) { |
| 45 | + server.get('/step-two', (err, response, body) => { |
| 46 | + var ids = JSON.parse(response.headers['x-miniprofiler-ids']); |
| 47 | + expect(ids).to.have.lengthOf(1); |
| 48 | + |
| 49 | + server.post('/mini-profiler-resources/results', { id: ids[0], popup: 1 }, (err, response, body) => { |
| 50 | + var result = JSON.parse(body) |
| 51 | + expect(result.Id).to.equal(ids[0]); |
| 52 | + expect(result.Name).to.equal('/step-two'); |
| 53 | + expect(result.Root.Children).to.have.lengthOf(1); |
| 54 | + |
| 55 | + expect(result.Root.Children[0].Name).to.equal('Step 1'); |
| 56 | + expect(result.Root.Children[0].Children).to.have.lengthOf(1); |
| 57 | + |
| 58 | + expect(result.Root.Children[0].Children[0].Name).to.equal('Step 2'); |
| 59 | + expect(result.Root.Children[0].Children[0].Children).to.be.empty; |
| 60 | + done(); |
| 61 | + }); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
0 commit comments