-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
remove function export from helper blueprint #15609
Conversation
I disagree with this change, but in the case it is accepted, why have the function at all then? |
Aren't you also missing the necessary tweaks to the generated tests? |
Correct. If accepted I will remove the unit test for helpers. Why do you disagree @locks? Calling the function behind the template helper seems like an anti-pattern to me. |
@locks ping |
For background, I believe that the main reason we do this is because at the time the integration testing system didn't support actually rendering a custom template, so it was nearly impossible to test properly from template land. Unfortunately, we have quite a large divide between the "pure helpers" and "class based helpers" with the current setup. I suspect that that the right path forward may be something of a compromise here. For example, rwjblue/rfc232-demo-app#1 (thanks @spencer516!) that shows a really elegant setup for doing both (leveraging the new ember-qunit API of course): module('helper:sad-color', function() {
module('rendering tests', function(hooks) {
setupRenderingTest(hooks);
test('it renders', async function(assert) {
await render(hbs`{{sad-color}}`);
assert.equal(this.$().text().trim(), '#fff');
});
});
module('unit tests', function(hooks) {
setupTest(hooks);
test('it returns black', function(assert) {
const subject = this.owner.lookup('helper:sad-color');
assert.equal(subject.compute(), '#fff'); });
});
}); Neither case requires the current @locks / @kellyselden / @Turbo87 - Thoughts? |
Seems good to me. In the beginning you mention a compromise, then at the end you seem to say remove the function export is fine. Does this PR need to change in your opinion @rwjblue ? |
ee9088a
to
d9461b1
Compare
If this is the path forward then we should probably not even have the function separated at all. No? |
I'm indifferent to it being separate. It might have a long line if we keep the function name for stack tracing purposes. |
fca971f
to
e540c48
Compare
if "unit" testing via |
Confirm. I’d prefer to land only bugfixes for this stuff at the moment. Saving larger refactors in general until we land new blueprints. |
Can y'all keep this on your radar with your test reworkings? |
@kellyselden wanna revisit this? |
I still think this is a good idea. Helpers should be tested via rendering tests, not unit tests, which is already the current default. So the original rationale for the named export doesn't apply. I would also add that the re-exports of these named exports in the app tree tend to bit rot, because people aren't using them and don't notice when they break them. This generates warning spew in Embroider, which does notice invalid reexports. For example, this: refers to a name that no longer exists in: So every app using ember-truth-helpers ships a bit of unused-and-broken code. |
e540c48
to
0fecb67
Compare
Rebased. I still feel like this should be merged. Side-note, there appears to be a node-tests regression on master. Another PR has the same 31 failed tests. |
@kellyselden think you can rebase this again? I believe the node tests problem has been resolved |
0fecb67
to
254d902
Compare
Rebased. |
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.
If we are going to remove the export, we should also inline the function.
export default helper(function(params /*, hash */) {
return params;
})
@kellyselden - Only had that last tweak/suggestion, then this is good to merge... |
Should it still be a named function for stack trace benefits? |
@kellyselden ya, that makes sense to me So basically: export default helper(function fooBarBaz(params /*, hash */) {
return params;
}) |
do we require named classes too from now on? |
Seems unrelated. I don't think this is about what we require, it's about what we think is a good idea. Having the name of the class or function in the stack trace is very very useful... |
254d902
to
e29a526
Compare
Should be good now. |
I find myself removing this export from every helper I create. Calling this function from component JS is cumbersome as you have to conform with its strict helper argument style. If I ever need to call a helper in JS, I move the code to a util and have the helper also use it.