aboutsummaryrefslogtreecommitdiff
path: root/node_modules/errno/test.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/errno/test.js
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/errno/test.js')
-rw-r--r--[-rwxr-xr-x]node_modules/errno/test.js69
1 files changed, 63 insertions, 6 deletions
diff --git a/node_modules/errno/test.js b/node_modules/errno/test.js
index 3a0ef7013..1c046357b 100755..100644
--- a/node_modules/errno/test.js
+++ b/node_modules/errno/test.js
@@ -1,7 +1,7 @@
-#!/usr/bin/env node
-
-var test = require('tape')
- , errno = require('./')
+var test = require('tape')
+ , inherits = require('inherits')
+ , ErrorStackParser = require('error-stack-parser')
+ , errno = require('./')
test('sanity checks', function (t) {
t.ok(errno.all, 'errno.all not found')
@@ -20,8 +20,8 @@ test('sanity checks', function (t) {
})
test('custom errors', function (t) {
- var Cust = errno.create('FooNotBarError')
- var cust = new Cust('foo is not bar')
+ const Cust = errno.create('FooNotBarError')
+ const cust = new Cust('foo is not bar')
t.equal(cust.name, 'FooNotBarError', 'correct custom name')
t.equal(cust.type, 'FooNotBarError', 'correct custom type')
@@ -29,3 +29,60 @@ test('custom errors', function (t) {
t.notOk(cust.cause, 'no cause')
t.end()
})
+
+test('callstack', function (t) {
+ const MyError = errno.create('MyError')
+
+ function lastFunction (ErrorType, cb) {
+ process.nextTick(cb, new ErrorType('oh noes!'))
+ }
+
+ function secondLastFunction (ErrorType, cb) {
+ lastFunction(ErrorType, cb)
+ }
+
+ function testFrames (t) {
+ return function (err) {
+ const stack = ErrorStackParser.parse(err)
+ t.same(stack[0].functionName, 'lastFunction', 'last stack frame ok')
+ t.same(stack[1].functionName, 'secondLastFunction', 'second last stack frame ok')
+ t.end()
+ }
+ }
+
+ t.test('custom error, default prototype', function (t) {
+ secondLastFunction(MyError, testFrames(t))
+ })
+
+ t.test('custom error, custom prototype', function (t) {
+ const MyError2 = errno.create('MyError2', MyError)
+ secondLastFunction(MyError2, testFrames(t))
+ })
+
+ t.test('custom error, using inheritance', function (t) {
+ const CustomError = errno.custom.CustomError
+
+ function MyError3 (message, cause) {
+ CustomError.call(this, message, cause)
+ }
+
+ inherits(MyError3, CustomError)
+
+ secondLastFunction(MyError3, testFrames(t))
+ })
+})
+
+test('error without message', function (t) {
+ const Cust = errno.create('WriteError')
+ const cust = new Cust({
+ code: 22,
+ message: '',
+ name: 'QuotaExceededError'
+ })
+
+ t.equal(cust.name, 'WriteError', 'correct custom name')
+ t.equal(cust.type, 'WriteError', 'correct custom type')
+ t.equal(cust.message, 'QuotaExceededError', 'message is the name')
+ t.notOk(cust.cause, 'no cause')
+ t.end()
+})