-
Notifications
You must be signed in to change notification settings - Fork 551
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
feat: port abort-controller.js
tests to node:test
runner
#2564
Changes from 6 commits
620593d
5cf60b7
3abcc63
db57315
7b7b865
1716324
a874a48
88d2c96
bc062c1
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* A port of tap's `t.type` that can be used with `node:assert` | ||
* https://github.com/tapjs/tapjs/blob/511019b2ac0fa014370154c3a341a0e632f50b19/src/asserts/src/index.ts#L199 | ||
*/ | ||
function ttype (plan, obj, klass) { | ||
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. Let's not inject the 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. Sounds good! 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. Done a874a48 |
||
const name = | ||
typeof klass === 'function' | ||
? klass.name || '(anonymous constructor)' | ||
: klass | ||
|
||
if (obj === klass) { | ||
return plan.ok(1) | ||
} | ||
|
||
const tof = typeof obj | ||
const type = | ||
!obj && tof === 'object' | ||
? 'null' | ||
// treat as object, but not Object | ||
// t.type(() => {}, Function) | ||
: tof === 'function' && | ||
typeof klass === 'function' && | ||
klass !== Object | ||
? 'object' | ||
: tof | ||
|
||
if ( | ||
(type === 'number' && klass === Number) || | ||
(type === 'string' && klass === String) || | ||
(type === 'bigint' && klass === BigInt) || | ||
(klass === 'array' && Array.isArray(obj)) || | ||
(type === 'symbol' && klass === Symbol) | ||
) { | ||
return plan.ok(1) | ||
} | ||
|
||
// simplest case, it literally is the same thing | ||
if (type === 'object' && klass !== 'object') { | ||
if (typeof klass === 'function') { | ||
return plan.ok(obj instanceof klass) | ||
} | ||
|
||
// check prototype chain for name | ||
// at this point, we already know klass is not a function | ||
// if the klass specified is an obj in the proto chain, pass | ||
// if the name specified is the name of a ctor in the chain, pass | ||
for (let p = obj; p; p = Object.getPrototypeOf(p)) { | ||
const ctor = p.constructor && p.constructor.name | ||
if (p === klass || ctor === name) { | ||
return plan.ok(1) | ||
} | ||
} | ||
} | ||
|
||
return plan.strictEqual(type, name) | ||
} | ||
|
||
module.exports = { | ||
ttype | ||
} |
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.
Please include the license of that file if copied over.
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.
Thank you, 88d2c96