Skip to content
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

Merged
merged 1 commit into from
Mar 24, 2016

Conversation

zackthehuman
Copy link
Contributor

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:

  • dashed shorthand helper not usable with a block
  • dashed helper not usable with a block
  • dashed shorthand helper not usable within element
  • dashed helper not usable within element

However, there are a few other tests which show that helpers are being recomputed more times than necessary (at least when compared to HTMLBars).

let count = 0;
let helper;

this.registerHelper('hello-world', {
Copy link
Contributor

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');

Copy link
Contributor Author

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.

@chadhietala
Copy link
Contributor

Hey Zack, thanks for doing this. As I mentioned above the tests should follow the cycle.

@zackthehuman
Copy link
Contributor Author

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.

@zackthehuman zackthehuman changed the title [Glimmer2] Port existing custom-helper-tests [Glimmer2] WIP - Port existing custom-helper-tests Mar 20, 2016

this.assertText('bob-value');

assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time');
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added rerenders to a few additional places and there is definitely a correlation between rerenders and extra calls to compute.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Member

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).

@chancancode
Copy link
Member

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.

@zackthehuman
Copy link
Contributor Author

@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.

@zackthehuman zackthehuman changed the title [Glimmer2] WIP - Port existing custom-helper-tests [Glimmer2] Port existing custom-helper-tests Mar 21, 2016
assert.strictEqual(destroyCount, 0, 'destroy is not called on recomputation');
}

['@htmlbars helper with arg can recompute a new value']() {
Copy link
Contributor Author

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 computes.

Copy link
Member

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️ helper usable in subexpressions

@zackthehuman
Copy link
Contributor Author

@chancancode I believe that I have addressed all of your feedback. Please take a look and see if there are any more remaining items.

@chancancode
Copy link
Member

@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']() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helper -> class-based helper

@chancancode
Copy link
Member

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!

@chancancode chancancode merged commit 0569af0 into emberjs:master Mar 24, 2016
@chancancode
Copy link
Member

@zackthehuman Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants