File size: 4,051 Bytes
befd7da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'use strict';

const definitions = require('./stream.definitions');

/*

TEST ALL FOLLOWING BUNYAN LOGGER FORMAT STYLES :

log.info();     // Returns a boolean: is the "info" level enabled?
                // This is equivalent to `log.isInfoEnabled()` or
                // `log.isEnabledFor(INFO)` in log4j.

log.info('hi');                     // Log a simple string message (or number).
log.info('hi %s', bob, anotherVar); // Uses `util.format` for msg formatting.

log.info({foo: 'bar'}, 'hi');
                // The first field can optionally be a "fields" object, which
                // is merged into the log record.

log.info(err);  // Special case to log an `Error` instance to the record.
                // This adds an "err" field with exception details
                // (including the stack) and sets "msg" to the exception
                // message.
log.info(err, 'more on this: %s', more);
                // ... or you can specify the "msg".

log.info({foo: 'bar', err: err}, 'some msg about this error');
                // To pass in an Error *and* other fields, use the `err`
                // field name for the Error instance.
*/

describe('SentrySteam class', () => {
  it('should log a message from logger#debug(message)', () => {
    const message = 'Hello';
    const client = definitions.givenClient();
    const logger = definitions.givenLogger(client, 'debug');
    logger.debug(message);

    definitions.thenClientCapturesMessage(client, 'info', message);
  });

  it('should log a message from logger#info(message, messageArgs)', () => {
    const client = definitions.givenClient();
    const logger = definitions.givenLogger(client, 'debug');
    logger.info('Hello %s', 'Joe Mocha', '!');
    definitions.thenClientCapturesMessage(client, 'info', 'Hello Joe Mocha !');
  });

  it('should log a message with tags from logger#info(extraWithTags, message)', () => {
    const message = 'Hello';
    const client = definitions.givenClient();
    const logger = definitions.givenLogger(client, 'debug');
    const tags = { foo: 'bar' };
    logger.debug({ tags }, message);

    definitions.thenClientCapturesMessage(client, 'info', message, null, tags);
  });

  it('should log a message from logger#warn(extra, message)', () => {
    const client = definitions.givenClient();
    const logger = definitions.givenLogger(client);
    logger.warn({ foo: 'bar' }, 'Hello');
    definitions.thenClientCapturesMessage(client, 'warning', 'Hello', { foo: 'bar' });
  });

  it('should log a message from logger#error(error)', () => {
    const client = definitions.givenClient();
    const logger = definitions.givenLogger(client);
    const err = new Error('Hello Error');
    err.code = 400;
    err.signal = 400;
    logger.error(err);

    definitions.thenClientCapturesException(client, 'error', err);
  });

  it('should log a message from logger#error(error, message, messageArgs)', () => {
    const client = definitions.givenClient();
    const logger = definitions.givenLogger(client);
    const err = new Error('Hello Error');

    logger.error(err, 'Hello %s', 'Joe Mocha', '!');

    definitions.thenClientCapturesException(client, 'error', err, { msg: 'Hello Joe Mocha !' });
  });

  it('should log a message from logger#debug(extraWithError, message)', () => {
    const client = definitions.givenClient();
    const logger = definitions.givenLogger(client, 'debug');
    const err = new Error('Hello Error');

    logger.debug({ foo: 'bar', err }, 'Hello');

    definitions.thenClientCapturesException(client, 'info', err, { msg: 'Hello', foo: 'bar' });
  });

  it('should log a message with tags from logger#debug(extraWithError, message)', () => {
    const client = definitions.givenClient();
    const logger = definitions.givenLogger(client, 'debug');
    const err = new Error('Hello Error');
    const tags = { foo: 'bar' };

    logger.debug({ foo: 'bar', err, tags }, 'Hello');

    definitions.thenClientCapturesException(client, 'info', err, { msg: 'Hello', foo: 'bar' }, tags);
  });
});