Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let server;
- describe('Node.js Unified Logging', function() {
- describe('Middleware With Async Hooks', function() {
- before(function(done) {
- // start server
- server = app.listen(3000, () => {
- console.log('listening on port 3000');
- });
- // make a request
- request('http://localhost:3000/home', function (error, response, body) {
- done();
- });
- });
- after(function() {
- // close server when done
- server.close();
- });
- it('makes logs', function() {
- return logArray.should.not.be.empty;
- });
- let objs = [];
- it('makes logs that contain JSON', function() {
- logArray.forEach((entry) => {
- let bracketIdx = entry.indexOf('{');
- let jsonStr = entry.substr(bracketIdx);
- let obj = JSON.parse(jsonStr);
- objs.push(obj);
- });
- return objs.should.not.be.empty;
- });
- it('makes logs that all have a span id', function() {
- return objs.should.all.have.property('ul-span-id');
- });
- it('makes logs with matching head spans', function() {
- const headSpanId = objs[0]['ul-ctx-head-span-id'];
- return objs.should.all.have.property('ul-ctx-head-span-id', headSpanId);
- });
- it('makes logs with matching caller spans', function() {
- const callerSpanId = objs[0]['ul-ctx-caller-span-id'];
- return objs.should.all.have.property('ul-ctx-caller-span-id', callerSpanId);
- });
- it('makes logs that all have an operation name', function() {
- return objs.should.all.have.property('ul-operation');
- });
- let homeLog;
- let asyncLog;
- let dbLog;
- it('makes one log for the home operation', function() {
- objs.forEach((log) => {
- if (log['ul-operation'] === 'GET /home') {
- homeLog = log;
- } else if (log['ul-operation'] === 'GET /async') {
- asyncLog = log;
- } else if (log['ul-operation'] === 'GET /db') {
- dbLog = log;
- }
- });
- return homeLog.should.exist;
- });
- it('makes one log for the async operation', function() {
- return asyncLog.should.exist;
- });
- it('makes one log for the db operation', function() {
- return dbLog.should.exist;
- });
- it('logs the async span as a child of the home span', function() {
- return homeLog['ul-span-id'].should.equal(asyncLog['ul-child-of']);
- });
- it('logs the db span as a child of the async span', function() {
- return asyncLog['ul-span-id'].should.equal(dbLog['ul-child-of']);
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement