-
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
Less API using power-assert #46
Conversation
It'd be nice if this translated into some way to hook into Ava to allow it to use any arbitrary assertion library, including support for Side note, power-assert looks badass. |
@uiureo why did you close? :o |
Because I don't intend this PR to be merged. I don't want the opened state to bother you guys.
That's the very thing I want. Related: #25 |
👍 sounds good |
I'd like to keep this open for a while so people can see it. I think |
I agree its output is a little bit noisy. It seems you can write custom output formatter in power-assert. https://github.com/power-assert-js/power-assert#optionsoutput FYI @twada |
Hi, I'm creator of power-assert. power-assert output consists of 4 parts, rendered by 4 renderers ( For example, output below
and
To disable verbose graph, remove var assert = require('power-assert').customize({
output: {
renderers: [
'./built-in/file',
'./built-in/assertion',
'./built-in/binary-expression'
]
}
}); produces output as below.
And of course, I want to hear your request, and create custom formatter for AVA! FYI: |
To be honest, the binary renderer is the part that seems noisy to me. The diagram is what makes it super useful. Thanks for the information @twada :D Very tempting to switch from |
Instead of:
I think I would want something like:
|
Hi @Qix-
Understood. You can disable var assert = require('power-assert').customize({
output: {
renderers: [
'./built-in/file',
'./built-in/assertion',
'./built-in/diagram'
]
}
}); You'll see output like
I'm glad to hear that! 😄 |
Hi @sindresorhus, thank you for your request. |
@twada Any updates? Would really like to use |
@sindresorhus I've extracted power-assert-renderers module out and now creating less-noisy succinct-diagram renderer for AVA. I would like you to see succinct-diagram-test.js. If you like it, I'm going to integrate it into this pull-req and also power-assert master. |
@twada Yes, looks very good :) I'm fine with this for now. Would be awesome if you would integrate it into this PR and fix the merge conflict. |
Really exciting stuff. |
I did quick hack to use the succinct renderer and fixed the merge conflict. Now the output looks like this: ❯ npm test
> ava
✖ [anonymous]
t.ok(a.name === 'bar')
|
"foo"
1 test failed
1. [anonymous]
AssertionError:
t.ok(a.name === 'bar')
|
"foo"
at decoratedAssert (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/power-assert/node_modules/empower/lib/decorate.js:42:30)
at Function.powerAssert (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/power-assert/node_modules/empower/index.js:58:32)
at Test.ok (/Users/zat/.ghq/github.com/sindresorhus/ava/lib/test.js:85:15)
at Test.fn (/Users/zat/.ghq/github.com/uiureo/ava-power-assert-example/test.js:26:5)
at Test.<anonymous> (/Users/zat/.ghq/github.com/sindresorhus/ava/lib/test.js:124:19)
at tryCatcher (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/bluebird/js/main/util.js:26:23)
at Promise._resolveFromResolver (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/bluebird/js/main/promise.js:480:31)
at new Promise (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/bluebird/js/main/promise.js:70:37)
at Test.run (/Users/zat/.ghq/github.com/sindresorhus/ava/lib/test.js:110:9)
at tryCatcher (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/bluebird/js/main/util.js:26:23)
at ReductionPromiseArray._promiseFulfilled (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/bluebird/js/main/reduce.js:105:38)
at ReductionPromiseArray.init [as _init$] (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/bluebird/js/main/promise_array.js:92:18)
at ReductionPromiseArray.init (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/bluebird/js/main/reduce.js:42:10)
at Async._drainQueue (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/bluebird/js/main/async.js:128:12)
at Async._drainQueues (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/bluebird/js/main/async.js:133:10)
at Async.drainQueues (/Users/zat/.ghq/github.com/sindresorhus/ava/node_modules/bluebird/js/main/async.js:15:14)
npm ERR! Test failed. See above for more details. |
@@ -15,7 +17,15 @@ try { | |||
|
|||
require(localBabel)(options); | |||
} catch (err) { | |||
require('babel-core/register')(options); | |||
require('babel-core/register')(assign({}, options, { |
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.
The options here need to be put in a variable and used in line 18 too.
@uiureo Thanks for responding so quickly, nice to see this being merged! |
@@ -70,6 +78,19 @@ Object.keys(assert).forEach(function (el) { | |||
}; | |||
}); | |||
|
|||
Test.prototype.ok = function () { |
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.
This should probably be in the assert.js
file.
@twada Can you review? |
@sindresorhus
You are right. Should be (power-assert overwrites empower's default for ease of use) |
I've tried to add patterns like this: plugins: [
createEspowerPlugin(require('babel-core'), {
patterns: [
't.ok(value, [message])',
't.notOk(value, [message])',
't.true(value, [message])',
't.false(value, [message])',
't.is(value, expected, [message])',
't.not(value, expected, [message])',
't.same(value, expected, [message])',
't.notSame(value, expected, [message])',
't.regexTest(regex, contents, [message])'
]
})
] test((t) => {
var a = 'foo'
t.is(a, 'bar')
t.end()
}) But I got weird output like this.
|
@uiureo Thank you for reporting. function enhanceAssert(assert) {
empower(assert,
powerAssertFormatter({
renderers: [
powerAssertRenderers.AssertionRenderer,
powerAssertRenderers.SuccinctRenderer
]
}),
{
destructive: true,
modifyMessageOnRethrow: true,
saveContextOnRethrow: false,
patterns: [
't.ok(value, [message])',
't.notOk(value, [message])',
't.true(value, [message])',
't.false(value, [message])',
't.is(value, expected, [message])',
't.not(value, expected, [message])',
't.same(value, expected, [message])',
't.notSame(value, expected, [message])',
't.regexTest(regex, contents, [message])'
]
}
);
} |
@twada |
|
||
execCli('fixture/power-assert.js', function (err, stdout, stderr) { | ||
t.ok(err); | ||
t.true(stderr.indexOf('t.ok(a === \'bar\')\n') !== -1); |
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.
How is this testing that it's working? It's only the normals output.
And should be:
t.not(stderr.indexOf('t.ok(a === \'bar\')'), -1);
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.
Without power-assert, the output should be false == true
because this assert is t.ok()
.
I thought probably it renders t.ok(a === 'bar')
only when power-assert works.
test(t => {
const a = 'foo';
t.ok(a === 'bar');
t.end();
});
Should I test this renders the diagram output somehow?
t.ok(a === 'bar')
|
"foo"
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.
I've added a test that it renders diagram output by regexp.
Let me know if you want some changes.
@sindresorhus I've done some tweaks. Can you review again? |
Landed. Woop woop. Great work @uiureo. And thanks for reviewing @twada :) |
Thanks a lot @sindresorhus @twada. I couldn't do this without your great help :) |
@sindresorhus Wow I'm very glad to see this pull-req is getting merged!! 🎉 |
I just want to share my demo, so feel free to close this PR. Just ignore it if you don't like it.
Added
t.ok(value, [message])
using power-assert. It shows descriptive assertion message by parsing the JS expression.example
shows a message like this.
apis
with power-assert:
more example
I know custom assertion is supported on ava and it worked pretty well.
But I wanted to use
t.plan()
and that assertion function with ava's minimal interface.