UNPKG

3.45 kBJavaScriptView Raw
1// Copyright (c) 2015 Uber Technologies, Inc.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21var test = require('tape');
22
23var captureStdio = require('./lib/capture-stdio.js');
24var ConsoleLogger = require('./lib/console-logger.js');
25
26test('can .error("message", new Error())', function (assert) {
27 var logger = ConsoleLogger();
28
29 assert.ok(captureStdio('error: hello',
30 function logError() {
31 logger.error('hello', new Error('lulz'));
32 }));
33
34 assert.ok(captureStdio('message=lulz',
35 function logError() {
36 logger.error('hello', new Error('lulz'));
37 }));
38
39 assert.ok(captureStdio('stack=Error: lulz',
40 function logError() {
41 logger.error('hello', new Error('lulz'));
42 }));
43
44 assert.end();
45});
46
47test('can error("message", { error: Error() })', function (assert) {
48 var logger = ConsoleLogger();
49
50 assert.ok(captureStdio('error: some message',
51 function logError() {
52 logger.error('some message', {
53 error: new Error('some error'),
54 other: 'key'
55 });
56 }));
57
58 assert.ok(captureStdio('message=some error',
59 function logError() {
60 logger.error('some message', {
61 error: new Error('some error'),
62 other: 'key'
63 });
64 }));
65
66 assert.ok(captureStdio('stack=Error: some error',
67 function logError() {
68 logger.error('some message', {
69 error: new Error('some error'),
70 other: 'key'
71 });
72 }));
73
74 assert.end();
75});
76
77test('can error(msg, { someKey: Error() })', function (assert) {
78 var logger = ConsoleLogger();
79
80 assert.ok(captureStdio('error: some message',
81 function logError() {
82 logger.error('some message', {
83 someKey: new Error('some error'),
84 other: 'key'
85 });
86 }));
87
88 assert.ok(captureStdio('message=some error',
89 function logError() {
90 logger.error('some message', {
91 someKey: new Error('some error'),
92 other: 'key'
93 });
94 }));
95
96 assert.ok(captureStdio('stack=Error: some error',
97 function logError() {
98 logger.error('some message', {
99 someKey: new Error('some error'),
100 other: 'key'
101 });
102 }));
103
104 assert.end();
105});