-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: added isNativeError check to assert.js #51250
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -74,6 +74,7 @@ const { | |||||
validateFunction, | ||||||
} = require('internal/validators'); | ||||||
const { fileURLToPath } = require('internal/url'); | ||||||
const { isNativeError } = internalBinding('types'); | ||||||
|
||||||
let isDeepEqual; | ||||||
let isDeepStrictEqual; | ||||||
|
@@ -393,7 +394,7 @@ function innerOk(fn, argLen, value, message) { | |||||
} else if (message == null) { | ||||||
generatedMessage = true; | ||||||
message = getErrMessage(message, fn); | ||||||
} else if (message instanceof Error) { | ||||||
} else if (isNativeError(message) || message instanceof Error) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
throw message; | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -38,7 +38,7 @@ const start = 'Expected values to be strictly deep-equal:'; | |||||||||||||||||||||
const actExp = '+ actual - expected'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
assert.ok(a.AssertionError.prototype instanceof Error, | ||||||||||||||||||||||
'a.AssertionError instanceof Error'); | ||||||||||||||||||||||
'a.AssertionError instanceof Error'); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
assert.throws(() => a(false), a.AssertionError, 'ok(false)'); | ||||||||||||||||||||||
assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)'); | ||||||||||||||||||||||
|
@@ -55,6 +55,27 @@ assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)'); | |||||||||||||||||||||
assert.ok(threw, 'Error: ok(false)'); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Thrown error should be the passed through error instance of the native error | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
const context = vm.createContext(); | ||||||||||||||||||||||
const error = vm.runInContext('new TypeError("custom error")', context); | ||||||||||||||||||||||
|
||||||||||||||||||||||
assert.throws(() => assert(false, error), { | ||||||||||||||||||||||
message: 'custom error', | ||||||||||||||||||||||
name: 'TypeError' | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
Comment on lines
+58
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
// Thrown error should be the passed through error instance of the native error | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
{ | ||||||||||||||||||||||
const context = vm.createContext(); | ||||||||||||||||||||||
const error = vm.runInContext('new SyntaxError("custom error")', context); | ||||||||||||||||||||||
|
||||||||||||||||||||||
assert.throws(() => assert(false, error), { | ||||||||||||||||||||||
message: 'custom error', | ||||||||||||||||||||||
name: 'SyntaxError' | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
a(true); | ||||||||||||||||||||||
a('test', 'ok(\'test\')'); | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.