diff options
Diffstat (limited to 'node_modules/pretty-error/test')
-rw-r--r-- | node_modules/pretty-error/test/ParsedError.coffee | 82 | ||||
-rw-r--r-- | node_modules/pretty-error/test/PrettyError.coffee | 109 | ||||
-rw-r--r-- | node_modules/pretty-error/test/mocha.opts | 5 |
3 files changed, 196 insertions, 0 deletions
diff --git a/node_modules/pretty-error/test/ParsedError.coffee b/node_modules/pretty-error/test/ParsedError.coffee new file mode 100644 index 000000000..516d34e98 --- /dev/null +++ b/node_modules/pretty-error/test/ParsedError.coffee @@ -0,0 +1,82 @@ +chai = require 'chai' +ParsedError = require '../src/ParsedError' + +chai.should() + +error = (what) -> + if typeof what is 'string' + return error -> throw Error what + + else if what instanceof Function + try + do what + return null + catch e + return e + + else + throw Error "bad argument for error" + +describe "ParsedError", -> + describe "constructor()", -> + it "should accept Error() instances", -> + (-> new ParsedError error -> throw Error "some message").should.not.throw() + + it "should accept ReferenceError() and other derivatives of Error()", -> + (-> new ParsedError error -> throw ReferenceError "some message").should.not.throw() + + it "should accept non errors", -> + (-> e = new ParsedError 'some string').should.not.throw() + + describe "message", -> + it "should return the original error message", -> + e = new ParsedError error 'a' + e.message.should.equal 'a' + + describe "kind", -> + it "should return 'Error' for normal error", -> + e = new ParsedError error 'a' + e.kind.should.equal 'Error' + + it "should recognize 'ReferenceError'", -> + e = new ParsedError error -> a.b = c + e.kind.should.equal 'ReferenceError' + + describe "type", -> + it.skip "should return original error type", -> + e = new ParsedError error -> a.b = c + e.type.should.be.equal 'not_defined' + + describe "arguments", -> + it.skip "should return original error arguments", -> + e = new ParsedError error -> a.b = c + e.arguments.should.be.eql ['a'] + + describe "stack", -> + it "should return original error stack", -> + e = new ParsedError error -> a.b = c + e.stack.should.be.equal e.error.stack + + describe "trace", -> + it "should include correct information about each trace item", -> + e = new ParsedError error -> a.b = c + e.trace.should.have.length.above 2 + + item = e.trace[0] + item.should.include.keys 'original', + 'what', 'path', 'addr', + 'file', 'dir', 'col', + 'line', 'jsCol', 'jsLine' + 'packageName', 'shortenedPath', 'shortenedAddr' + + item.path.should.equal module.filename.replace(/[\\]+/g, '/') + + item.line.should.be.a 'number' + item.col.should.be.a 'number' + + describe "_rectifyPath()", -> + it "should work", -> + ParsedError::_rectifyPath('F:/a/node_modules/b/node_modules/d/node_modules/e/f.js').path.should.equal '[a]/[b]/[d]/[e]/f.js' + + it "should return path when `node_modules` is not present", -> + ParsedError::_rectifyPath('a/b/c').path.should.equal 'a/b/c' diff --git a/node_modules/pretty-error/test/PrettyError.coffee b/node_modules/pretty-error/test/PrettyError.coffee new file mode 100644 index 000000000..1b7a715b6 --- /dev/null +++ b/node_modules/pretty-error/test/PrettyError.coffee @@ -0,0 +1,109 @@ +chai = require 'chai' +PrettyError = require '../src/PrettyError' +defaultStyle = require '../src/defaultStyle' + +chai.should() + +isFormatted = (exc) -> + exc.stack.indexOf(' \u001b[0m\u001b[97m\u001b[41m') is 0 + +error = (what) -> + if typeof what is 'string' + return error -> throw Error what + + else if what instanceof Function + try + do what + catch e + return e + + throw Error "bad argument for error" + +describe "PrettyError", -> + describe "constructor()", -> + it "should work", -> + new PrettyError + + describe "getObject", -> + it "should return a string", -> + p = new PrettyError + p.getObject(error "hello").should.be.an 'object' + + describe "style", -> + it "should, by default, return the contents in `default-style`", -> + p = new PrettyError + p.style.should.eql defaultStyle() + + it "should return different contents after appending some styles", -> + p = new PrettyError + p.appendStyle 'some selector': 'display': 'block' + p.style.should.not.eql defaultStyle() + + describe "render()", -> + it "should work", -> + p = new PrettyError + p.skipNodeFiles() + p.appendStyle 'pretty-error': marginLeft: 4 + + e = error -> "a".should.equal "b" + console.log p.render e, no + + e2 = error -> Array.split(Object) + console.log p.render e2, no + + e3 = "Plain error message" + console.log p.render e3, no + + e4 = + message: "Custom error message" + kind: "Custom Error" + + console.log p.render e4, no + + e5 = + message: "Error with custom stack" + stack: ['line one', 'line two'] + wrapper: 'UnhandledRejection' + + console.log p.render e5, no + + e6 = error -> PrettyError.someNonExistingFuncion() + console.log p.render e6, no + + it.skip "should render without colors if pe._useColors is false", -> + p = new PrettyError + p.withoutColors() + p.skipNodeFiles() + p.appendStyle 'pretty-error': marginLeft: 4 + + e = error -> "a".should.equal "b" + console.log p.render e, no + + describe "start()", -> + prepareStackTrace = null + + beforeEach -> + {prepareStackTrace} = Error + Error.prepareStackTrace = null + + afterEach -> + Error.prepareStackTrace = prepareStackTrace + + it "throws unformatted error when not started", -> + try + throw new Error "foo bar" + catch exc + + isFormatted(exc).should.be.eql false + + it "throws formatted the error", -> + PrettyError.start() + + try + throw new Error "foo bar" + catch exc + + isFormatted(exc).should.be.eql true + exc.stack.split(/\n/g).length.should.be.above 2 + + PrettyError.stop() diff --git a/node_modules/pretty-error/test/mocha.opts b/node_modules/pretty-error/test/mocha.opts new file mode 100644 index 000000000..63fb383cb --- /dev/null +++ b/node_modules/pretty-error/test/mocha.opts @@ -0,0 +1,5 @@ +--compilers coffee:coffee-script/register +--recursive +--reporter spec +--ui bdd +--timeout 20000 |