-
-
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
[Glimmer2] Port existing custom-helper-tests #13138
Conversation
let count = 0; | ||
let helper; | ||
|
||
this.registerHelper('hello-world', { |
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 helper should probably take some input so that you can perform the I-N-U-R cycle described in #13127.
this.register('hello-world', {
...
compute([value]) {
return `${value}-value`
}
})
This way you can update it and reset it in the tests.
this.render(`{{hello-world foo}}`, {foo: 'hey'});
this.assertText('hey-value');
this.runTask(() => this.rerender());
this.runTask(() => set(this.context, 'foo', 'bye'));
this.assertText('bye-value');
this.runTask(() => set(this.context, 'foo', 'hey'));
this.assertText('hey-value');
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'll add some additional logic like you described above. There are tests specifically for no-arg helpers as well as helpers that take args.
Hey Zack, thanks for doing this. As I mentioned above the tests should follow the cycle. |
Will do. This was a straight port, so I will definitely clean it up per the instructions. I will update the title to indicate this is WIP. |
|
||
this.assertText('bob-value'); | ||
|
||
assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time'); |
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.
After adding a little I-N-R-U into the mix, it appears that helpers are recomputed more often with Glimmer 2 than with HTMLBars. After a call to this.rerender()
it appears to call compute()
two times, based on the test failures.
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.
@chancancode @wycats the number of invocations for helpers is purely an implementation detail, but this seems like a possible performance regression for rerender
if a helper having an unchanged argument value re-computes.
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 just added rerender
s to a few additional places and there is definitely a correlation between rerenders and extra calls to compute
.
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.
@zackthehuman yeah, we have plans to make it work. if anything is failing because of that, feel free to skip with @htmlbars for now. I agree with @mixonic that we have some wiggle room on that, but I think we can/should make it work. Just have to circle back on that a bit later.
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.
skip htmlbars or skip glimmer? The HTMLbars behavior is the one we want?
Or do you propose merging this with different invocation counts and opening a followup? Just want to by sure.
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.
@htmlbars runs just htmlbars and skips glimmer
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.
Yeah, "run it on htmlbars only", keeping the existing invocation count. We can re-visit this on Glimmer 2 and try to match the invocation count (or decide to update the tests at that point).
By the way, the word "dashed helper" doesn't have any significance. You can just remove it from all the test names. You can still keep an dash in the helper name (or not – it doesn't behave any differently on either Glimmer or HTMLBars), that part is fine. |
@chancancode Yeah, I thought the wording was outdated. I had gone through and changed it to "custom helper" but then I wasn't sure if "custom" even made sense. Will update. |
assert.strictEqual(destroyCount, 0, 'destroy is not called on recomputation'); | ||
} | ||
|
||
['@htmlbars helper with arg can recompute a new value']() { |
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 is marked as @htmlbars
because Glimmer2 is causing more recomputes than HTMLBars. Rerendering causes an additional 2 compute
s.
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.
Nit: I would probably call this helper with static arguments can... (and the next test with dynamic arguments can ..., to differentiate but also maintaining the parallel)
equal(hash.last, 'sam', 'hash.last argument is sam'); | ||
}); | ||
|
||
QUnit.test('dashed helper usable in subexpressions', 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.
✔️ helper usable in subexpressions
308a9d7
to
509571c
Compare
@chancancode I believe that I have addressed all of your feedback. Please take a look and see if there are any more remaining items. |
@zackthehuman thank you. Sorry I was in the middle of reviewing this yesterday and ran out of time. I believe it was mostly good to go except some consistency issues (that were in the old tests). I'll come back to this today. |
@@ -22,4 +26,436 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest { | |||
this.assertText('hello world'); | |||
} | |||
|
|||
['@htmlbars helper can recompute a new value']() { |
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.
helper -> class-based helper
Looks great to me! Just some minor naming consistency left (see line comments). When you have fixed those, can you also squash your commits? Thank you! |
509571c
to
201c9e9
Compare
201c9e9
to
ef0aa64
Compare
@zackthehuman Thank you so much! |
This moves the
custom-helper-tests
into the new testing infrastructure for Glimmer 2 support (#13127). 15 of 15 tests were ported, with only a few failures for Glimmer 2.The failing tests mostly have to do with using helpers in block form within elements:
However, there are a few other tests which show that helpers are being recomputed more times than necessary (at least when compared to HTMLBars).