cocalc/src / smc-project / node_modules / broadway / node_modules / winston / test / log-exception-test.js
50659 views/*1* exception-test.js: Tests for exception data gathering in winston.2*3* (C) 2010 Charlie Robbins4* MIT LICENSE5*6*/78var assert = require('assert'),9path = require('path'),10fs = require('fs'),11spawn = require('child_process').spawn,12vows = require('vows'),13winston = require('../lib/winston'),14helpers = require('./helpers'),15exists = (fs.exists || path.exists);1617vows.describe('winston/logger/exceptions').addBatch({18"When using winston": {19"the handleException() method": {20"with a custom winston.Logger instance": helpers.assertHandleExceptions({21script: path.join(__dirname, 'fixtures', 'scripts', 'log-exceptions.js'),22logfile: path.join(__dirname, 'fixtures', 'logs', 'exception.log')23}),24"with the default winston logger": helpers.assertHandleExceptions({25script: path.join(__dirname, 'fixtures', 'scripts', 'default-exceptions.js'),26logfile: path.join(__dirname, 'fixtures', 'logs', 'default-exception.log')27}),28"when a custom exitOnError function is set": {29topic: function () {30var that = this,31scriptDir = path.join(__dirname, 'fixtures', 'scripts');3233that.child = spawn('node', [path.join(scriptDir, 'exit-on-error.js')]);34setTimeout(this.callback.bind(this), 1500);35},36"should not exit the process": function () {37assert.isFalse(this.child.killed);38this.child.kill();39}40}41},42"the unhandleException() method": {43topic: function () {44var that = this,45child = spawn('node', [path.join(__dirname, 'fixtures', 'scripts', 'unhandle-exceptions.js')]),46exception = path.join(__dirname, 'fixtures', 'logs', 'unhandle-exception.log');4748helpers.tryUnlink(exception);49child.on('exit', function () {50exists(exception, that.callback.bind(this, null));51});52},53"should not write to the specified error file": function (err, exists) {54assert.isTrue(!err);55assert.isFalse(exists);56}57}58}59}).export(module);6061