-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Improve the ergonomics of power-assert #1808
Comments
Interesting. I do agree that @avajs/core? |
@novemberborn I don't think (P.S. I think this is a feature/enhancement request rather than (or as well as) a question :-) |
As a general rule we don't alias assertions, so since we already have However if we were to restrict power-assert to a single assertion, then perhaps
Yes, will add such labels when we come to a satisfactory conclusion on this. |
I think there are already aliases, e.g.
Just to clarify a few things:
|
I believe the purpose of That said, I do not think they communicate power-assert, which I believe is also your motivation for opening this issue. I'm not wedded to Without that restriction I'm not sold on the need to make any changes (documentation improvements aside). But let's hear from @vadimdemedes or @sindresorhus first. |
I don't think that's incompatible with this proposal. Beforet.true(...) // power assert
t.truthy(...) // power assert
t.false(...) // power assert
t.falsy(...) // power assert Aftert.assert(...) // power assert
t(...) // power assert The implicit power-assertion reporting can be uncoupled from |
Since |
I don't think the future direction of AVA is I would personally prefer having a separate assertion method for |
Great! To recap: We're removing power-assert from:
We're adding a new assertion that is power-assert enabled. I think This will require a breaking change to https://github.com/avajs/babel-preset-transform-test-files which encodes the patterns that need replacing. @chocolateboy I think we'll want to keep Are you interested in working on this? |
Sounds good!
Not sure I follow this. Do you have a particular extension/plugin in mind this change would make things harder for? AIUI, extensions wouldn't need to concern themselves with (or even know about) the fact that A function is still an (extensible) object, and this duality appears to be standard for
I'll take a look if I have time, but I'm hoping someone will beat me to it :-) |
Functional composition is a big part of how people use AVA. That may include adding additional fields to Also |
Why wouldn't that still work? let t = () => {}
Object.assign(t, { assign () { }, truthy () { } })
let t2 = { ...t, additional: 42 }
console.log(Object.keys(t2)) // [ 'assign', 'truthy', 'additional' ]
Well, that's a consequence of AVA requiring the name to be |
We need something reasonably unique to hook our transforms on to. We don't have good enough AST / type analysis to see which functions are receiving our execution context, so the best we can do is transform |
If extensions are using a documented API to extend the If they're constructing new import { callable } from 'ava'
function extend (t) {
let t2 = { ...t, additional () { ... } }
return callable(t2)
} In addition to the implementations listed above, there's also the function callable (value, method = 'assert') {
// dummy target as the `apply` trap requires the
// target to be callable
const fn = () => {}
return new Proxy(fn, {
apply (target, ctx, args) {
return value[method].apply(value, args)
},
get (target, name) {
return value[name]
}
})
}
const value = { assert () { return [ "assert called!" ] }, foo: 42 }
const proxy = callable(value)
console.log(proxy.foo) // 42
console.log(proxy()) // [ 'assert called!' ] |
Regardless whether it's possible to use |
Hi! I would like to take a look at this. This is my first time contributing not only to this project but to any project. I will probably need some help at some point. |
Go for it @eemed. Don't hesitate to ask questions 👍 |
@novemberborn So it almost works, but I have 3 tests that won't pass and I can't figure it out. Should we discuss them here or should I make a pull request? |
A PR would be best, thanks @eemed. |
It could be closed? |
The last time I used AVA, I thought power-assert had been disabled by default, as I couldn't see evidence of its helpful diagnostics in the output of various failed assertions. I've only just noticed recently that this is because it's only available via
t.true
(edit: andt.truthy
), which I don't use that often, and which is not a particularly obvious way to unlock it.Other test frameworks force you to use an ever-growing list of assertions and matchers, but power-assert renders almost all of these methods redundant. It would be nice to bring it center stage rather than hiding it behind the facade of its less idiomatic alternatives.
I'd like to suggest two solutions to this:
assert
function:t
itself thet.assert
function:The former can be achieved by adding
assert
as an alias fortrue
truthy
(or vice versa). The latter can be achieved by making thet
object a function, which is trivial if it's a plain object and not hard if it's an instance, e.g. via:The text was updated successfully, but these errors were encountered: