This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stack message missing caused by visit and invoke stack getter bef…
…ore call `captureStackTrace` (found in node V6.x). Use strict mode. Prettify tests.
- Loading branch information
Showing
3 changed files
with
63 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
var bl = require("bl"); | ||
var should = require("should"); | ||
var MemoryFileSystem = require("../lib/MemoryFileSystem"); | ||
var MemoryFileSystemError = require("../lib/MemoryFileSystemError"); | ||
|
||
describe("error", function() { | ||
function catchError(fn) { | ||
try { | ||
fn(); | ||
} catch(e) { | ||
return e; | ||
} | ||
return null; | ||
} | ||
|
||
it("should include the path in Error message", function(done) { | ||
var fs = new MemoryFileSystem(); | ||
var invalidPath = "/nonexist/file"; | ||
var error = catchError(function() { | ||
fs.statSync(invalidPath); | ||
}); | ||
error.message.should.containEql(invalidPath); | ||
|
||
fs.readFile(invalidPath, function(err) { | ||
err.message.should.containEql(invalidPath); | ||
done(); | ||
}); | ||
}); | ||
it("should use correct error message in the first line of Error stack", function(done) { | ||
var fs = new MemoryFileSystem(); | ||
fs.unlink("/test/abcd", function(error) { | ||
error.should.be.instanceof(Error); | ||
error.stack.should.startWith(error.name); | ||
|
||
var firstLine = error.stack.split(/\r\n|\n/)[0]; | ||
firstLine.should.containEql(error.code); | ||
firstLine.should.containEql(error.message); | ||
done(); | ||
}); | ||
}); | ||
it("should work fine without path and operation", function() { | ||
var errorData = { | ||
code:"ETEST", | ||
description:"testerror", | ||
}; | ||
var error = new MemoryFileSystemError(errorData); | ||
error.message.should.startWith(error.code); | ||
error.stack.should.startWith(error.name); | ||
error.stack.should.containEql(error.message); | ||
}); | ||
}); |