Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
/*
2
* exception-test.js: Tests for exception data gathering in winston.
3
*
4
* (C) 2010 Charlie Robbins
5
* MIT LICENSE
6
*
7
*/
8
9
var assert = require('assert'),
10
path = require('path'),
11
fs = require('fs'),
12
spawn = require('child_process').spawn,
13
vows = require('vows'),
14
winston = require('../lib/winston'),
15
helpers = require('./helpers'),
16
exists = (fs.exists || path.exists);
17
18
vows.describe('winston/logger/exceptions').addBatch({
19
"When using winston": {
20
"the handleException() method": {
21
"with a custom winston.Logger instance": helpers.assertHandleExceptions({
22
script: path.join(__dirname, 'fixtures', 'scripts', 'log-exceptions.js'),
23
logfile: path.join(__dirname, 'fixtures', 'logs', 'exception.log')
24
}),
25
"with the default winston logger": helpers.assertHandleExceptions({
26
script: path.join(__dirname, 'fixtures', 'scripts', 'default-exceptions.js'),
27
logfile: path.join(__dirname, 'fixtures', 'logs', 'default-exception.log')
28
}),
29
"when a custom exitOnError function is set": {
30
topic: function () {
31
var that = this,
32
scriptDir = path.join(__dirname, 'fixtures', 'scripts');
33
34
that.child = spawn('node', [path.join(scriptDir, 'exit-on-error.js')]);
35
setTimeout(this.callback.bind(this), 1500);
36
},
37
"should not exit the process": function () {
38
assert.isFalse(this.child.killed);
39
this.child.kill();
40
}
41
}
42
},
43
"the unhandleException() method": {
44
topic: function () {
45
var that = this,
46
child = spawn('node', [path.join(__dirname, 'fixtures', 'scripts', 'unhandle-exceptions.js')]),
47
exception = path.join(__dirname, 'fixtures', 'logs', 'unhandle-exception.log');
48
49
helpers.tryUnlink(exception);
50
child.on('exit', function () {
51
exists(exception, that.callback.bind(this, null));
52
});
53
},
54
"should not write to the specified error file": function (err, exists) {
55
assert.isTrue(!err);
56
assert.isFalse(exists);
57
}
58
}
59
}
60
}).export(module);
61