test-console
Advanced tools
Comparing version 0.7.0 to 0.7.1
{ | ||
"name": "test-console", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "A simple and pragmatic library for testing Node.js console output.", | ||
@@ -19,4 +19,3 @@ "main": "src/index.js", | ||
"spy", | ||
"test", | ||
"double" | ||
"test double" | ||
], | ||
@@ -23,0 +22,0 @@ "author": "James Shore", |
@@ -15,3 +15,3 @@ # test-console | ||
console.log("foo"); | ||
}; | ||
}); | ||
assert.deepEqual(output, [ "foo\n "]); | ||
@@ -158,2 +158,4 @@ ``` | ||
__0.7.1:__ Bug fix: Sync() versions restore old behavior even if exception occurs | ||
__0.7.0:__ Initial release: `inspect()`, `inspectSync()`, `ignore()`, and `ignoreSync()` | ||
@@ -160,0 +162,0 @@ |
@@ -62,2 +62,20 @@ // Copyright (c) 2014 Titanium I.T. LLC. All rights reserved. For license, see "README" or "LICENSE" file. | ||
it("restores old behavior even when an exception occurs", function() { | ||
// inception! | ||
stdout.inspectSync(function(output) { | ||
var exceptionPropagated = false; | ||
try { | ||
stdout.inspectSync(function() { | ||
throw new Error("intentional exception"); | ||
}); | ||
} | ||
catch (err) { | ||
exceptionPropagated = true; | ||
} | ||
assert.isTrue(exceptionPropagated, "exception should be propagated"); | ||
console.log("foo"); | ||
assert.deepEqual(output, [ "foo\n" ], "console should be restored"); | ||
}); | ||
}); | ||
it("also returns output", function() { | ||
@@ -64,0 +82,0 @@ var output = stdout.inspectSync(function() { |
@@ -16,3 +16,3 @@ // Copyright (c) 2014 Titanium I.T. LLC. All rights reserved. For license, see "README" or "LICENSE" file. | ||
var originalStdout = stream.write; | ||
var originalWrite = stream.write; | ||
stream.write = function(string) { | ||
@@ -25,3 +25,3 @@ output.push(string); | ||
restore: function() { | ||
stream.write = originalStdout; | ||
stream.write = originalWrite; | ||
} | ||
@@ -33,4 +33,8 @@ }; | ||
var inspect = this.inspect(); | ||
fn(inspect.output); | ||
inspect.restore(); | ||
try { | ||
fn(inspect.output); | ||
} | ||
finally { | ||
inspect.restore(); | ||
} | ||
return inspect.output; | ||
@@ -37,0 +41,0 @@ }; |
13525
236
192