[79a0317] | 1 | chai = require 'chai'
|
---|
| 2 | ParsedError = require '../src/ParsedError'
|
---|
| 3 |
|
---|
| 4 | chai.should()
|
---|
| 5 |
|
---|
| 6 | error = (what) ->
|
---|
| 7 | if typeof what is 'string'
|
---|
| 8 | return error -> throw Error what
|
---|
| 9 |
|
---|
| 10 | else if what instanceof Function
|
---|
| 11 | try
|
---|
| 12 | do what
|
---|
| 13 | return null
|
---|
| 14 | catch e
|
---|
| 15 | return e
|
---|
| 16 |
|
---|
| 17 | else
|
---|
| 18 | throw Error "bad argument for error"
|
---|
| 19 |
|
---|
| 20 | describe "ParsedError", ->
|
---|
| 21 | describe "constructor()", ->
|
---|
| 22 | it "should accept Error() instances", ->
|
---|
| 23 | (-> new ParsedError error -> throw Error "some message").should.not.throw()
|
---|
| 24 |
|
---|
| 25 | it "should accept ReferenceError() and other derivatives of Error()", ->
|
---|
| 26 | (-> new ParsedError error -> throw ReferenceError "some message").should.not.throw()
|
---|
| 27 |
|
---|
| 28 | it "should accept non errors", ->
|
---|
| 29 | (-> e = new ParsedError 'some string').should.not.throw()
|
---|
| 30 |
|
---|
| 31 | describe "message", ->
|
---|
| 32 | it "should return the original error message", ->
|
---|
| 33 | e = new ParsedError error 'a'
|
---|
| 34 | e.message.should.equal 'a'
|
---|
| 35 |
|
---|
| 36 | describe "multiline message", ->
|
---|
| 37 | it "should return the original error message", ->
|
---|
| 38 | e = new ParsedError error 'a \n b \n c'
|
---|
| 39 | e.message.should.equal 'a \n b \n c'
|
---|
| 40 |
|
---|
| 41 | describe "kind", ->
|
---|
| 42 | it "should return 'Error' for normal error", ->
|
---|
| 43 | e = new ParsedError error 'a'
|
---|
| 44 | e.kind.should.equal 'Error'
|
---|
| 45 |
|
---|
| 46 | it "should recognize 'ReferenceError'", ->
|
---|
| 47 | e = new ParsedError error -> a.b = c
|
---|
| 48 | e.kind.should.equal 'ReferenceError'
|
---|
| 49 |
|
---|
| 50 | describe "type", ->
|
---|
| 51 | it.skip "should return original error type", ->
|
---|
| 52 | e = new ParsedError error -> a.b = c
|
---|
| 53 | e.type.should.be.equal 'not_defined'
|
---|
| 54 |
|
---|
| 55 | describe "arguments", ->
|
---|
| 56 | it.skip "should return original error arguments", ->
|
---|
| 57 | e = new ParsedError error -> a.b = c
|
---|
| 58 | e.arguments.should.be.eql ['a']
|
---|
| 59 |
|
---|
| 60 | describe "stack", ->
|
---|
| 61 | it "should return original error stack", ->
|
---|
| 62 | e = new ParsedError error -> a.b = c
|
---|
| 63 | e.stack.should.be.equal e.error.stack
|
---|
| 64 |
|
---|
| 65 | describe "trace", ->
|
---|
| 66 | it "should include correct information about each trace item", ->
|
---|
| 67 | e = new ParsedError error -> a.b = c
|
---|
| 68 | e.trace.should.have.length.above 2
|
---|
| 69 |
|
---|
| 70 | item = e.trace[0]
|
---|
| 71 | item.should.include.keys 'original',
|
---|
| 72 | 'what', 'path', 'addr',
|
---|
| 73 | 'file', 'dir', 'col',
|
---|
| 74 | 'line', 'jsCol', 'jsLine'
|
---|
| 75 | 'packageName', 'shortenedPath', 'shortenedAddr'
|
---|
| 76 |
|
---|
| 77 | item.path.should.equal module.filename.replace(/[\\]+/g, '/')
|
---|
| 78 |
|
---|
| 79 | item.line.should.be.a 'number'
|
---|
| 80 | item.col.should.be.a 'number'
|
---|
| 81 |
|
---|
| 82 | describe "_rectifyPath()", ->
|
---|
| 83 | it "should work", ->
|
---|
| 84 | ParsedError::_rectifyPath('F:/a/node_modules/b/node_modules/d/node_modules/e/f.js').path.should.equal '[a]/[b]/[d]/[e]/f.js'
|
---|
| 85 |
|
---|
| 86 | it "should return path when `node_modules` is not present", ->
|
---|
| 87 | ParsedError::_rectifyPath('a/b/c').path.should.equal 'a/b/c'
|
---|