1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var test = require('tape');
|
22 |
|
23 | var FileLogger = require('./lib/file-logger.js');
|
24 |
|
25 | test('can .error("message", new Error())', function (assert) {
|
26 | var logger = FileLogger();
|
27 |
|
28 | logger.error('hello', new Error('lulz'), function (err) {
|
29 | assert.ifError(err);
|
30 |
|
31 | logger.readFile(function (err, file) {
|
32 | assert.ifError(err);
|
33 |
|
34 | assert.notEqual(file.indexOf('error: hello'), -1);
|
35 | assert.notEqual(file.indexOf('message=lulz'), -1);
|
36 | assert.notEqual(
|
37 | file.indexOf('stack=Error: lulz'), -1);
|
38 |
|
39 | logger.destroy();
|
40 | assert.end();
|
41 | });
|
42 | });
|
43 | });
|
44 |
|
45 | test('can error("message", { error: Error() })', function (assert) {
|
46 | var logger = FileLogger();
|
47 |
|
48 | logger.error('some message', {
|
49 | error: new Error('some error'),
|
50 | other: 'key'
|
51 | }, function (err) {
|
52 | assert.ifError(err);
|
53 |
|
54 | logger.readFile(function (err, file) {
|
55 | assert.ifError(err);
|
56 |
|
57 | assert.notEqual(
|
58 | file.indexOf('error: some message'), -1);
|
59 | assert.notEqual(
|
60 | file.indexOf('message=some error'), -1);
|
61 | assert.notEqual(
|
62 | file.indexOf('stack=Error: some error'), -1);
|
63 | assert.notEqual(file.indexOf('other=key'), -1);
|
64 |
|
65 | logger.destroy();
|
66 | assert.end();
|
67 | });
|
68 | });
|
69 | });
|
70 |
|
71 | test('can error(msg, { someKey: Error() })', function (assert) {
|
72 | var logger = FileLogger();
|
73 |
|
74 | logger.error('some message', {
|
75 | someKey: new Error('some error'),
|
76 | other: 'key'
|
77 | }, function (err) {
|
78 | assert.ifError(err);
|
79 |
|
80 | logger.readFile(function (err, file) {
|
81 | assert.ifError(err);
|
82 |
|
83 | assert.notEqual(
|
84 | file.indexOf('error: some message'), -1);
|
85 | assert.notEqual(
|
86 | file.indexOf('message=some error'), -1);
|
87 | assert.notEqual(
|
88 | file.indexOf('stack=Error: some error'), -1);
|
89 | assert.notEqual(file.indexOf('other=key'), -1);
|
90 |
|
91 | logger.destroy();
|
92 | assert.end();
|
93 | });
|
94 | });
|
95 | });
|