Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14130 from emberjs/components-instrumentation
[GLIMMER2] Component instrumentation support
- Loading branch information
Showing
13 changed files
with
253 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
packages/ember-glimmer/tests/integration/components/instrumentation-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { moduleFor, RenderingTest } from '../../utils/test-case'; | ||
import { Component } from '../../utils/helpers'; | ||
import { subscribe, reset } from 'ember-metal/instrumentation'; | ||
import { set } from 'ember-metal/property_set'; | ||
|
||
moduleFor('Components instrumentation', class extends RenderingTest { | ||
constructor() { | ||
super(); | ||
|
||
this.resetEvents(); | ||
|
||
subscribe('render.component', { | ||
before: (name, timestamp, payload) => { | ||
if (payload.view !== this.component) { | ||
this.actual.before.push(payload); | ||
} | ||
}, | ||
after: (name, timestamp, payload) => { | ||
if (payload.view !== this.component) { | ||
this.actual.after.push(payload); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
resetEvents() { | ||
this.expected = { | ||
before: [], | ||
after: [] | ||
}; | ||
|
||
this.actual = { | ||
before: [], | ||
after: [] | ||
}; | ||
} | ||
|
||
teardown() { | ||
this.assert.deepEqual(this.actual.before, [], 'No unexpected events (before)'); | ||
this.assert.deepEqual(this.actual.after, [], 'No unexpected events (after)'); | ||
super.teardown(); | ||
reset(); | ||
} | ||
|
||
['@test zomg'](assert) { assert.ok(true); } | ||
|
||
['@test it should receive an instrumentation event for both initial render and updates'](assert) { | ||
let testCase = this; | ||
|
||
let BaseClass = Component.extend({ | ||
tagName: '', | ||
|
||
willRender() { | ||
testCase.expected.before.push(this); | ||
testCase.expected.after.unshift(this); | ||
} | ||
}); | ||
|
||
this.registerComponent('x-bar', { | ||
template: '[x-bar: {{bar}}] {{yield}}', | ||
ComponentClass: BaseClass.extend() | ||
}); | ||
|
||
this.registerComponent('x-baz', { | ||
template: '[x-baz: {{baz}}]', | ||
ComponentClass: BaseClass.extend() | ||
}); | ||
|
||
this.registerComponent('x-bat', { | ||
template: '[x-bat: {{bat}}]', | ||
ComponentClass: BaseClass.extend() | ||
}); | ||
|
||
this.render(`[-top-level: {{foo}}] {{#x-bar bar=bar}}{{x-baz baz=baz}}{{/x-bar}} {{x-bat bat=bat}}`, { | ||
foo: 'foo', bar: 'bar', baz: 'baz', bat: 'bat' | ||
}); | ||
|
||
this.assertText('[-top-level: foo] [x-bar: bar] [x-baz: baz] [x-bat: bat]'); | ||
|
||
this.assertEvents('after initial render', true); | ||
|
||
this.runTask(() => this.rerender()); | ||
|
||
this.assertEvents('after no-op rerender'); | ||
|
||
this.runTask(() => set(this.context, 'foo', 'FOO')); | ||
|
||
this.assertEvents('after updating top-level'); | ||
|
||
this.runTask(() => set(this.context, 'baz', 'BAZ')); | ||
|
||
this.assertEvents('after updating inner-most'); | ||
|
||
this.runTask(() => { | ||
set(this.context, 'bar', 'BAR'); | ||
set(this.context, 'bat', 'BAT'); | ||
}); | ||
|
||
this.assertEvents('after updating the rest'); | ||
|
||
this.runTask(() => { | ||
set(this.context, 'foo', 'FOO'); | ||
set(this.context, 'bar', 'BAR'); | ||
set(this.context, 'baz', 'BAZ'); | ||
set(this.context, 'bat', 'BAT'); | ||
}); | ||
|
||
this.assertEvents('after reset'); | ||
} | ||
|
||
assertEvents(label, initialRender = false) { | ||
let { actual, expected } = this; | ||
|
||
this.assert.strictEqual(actual.before.length, actual.after.length, `${label}: before and after callbacks should be balanced`); | ||
|
||
this._assertEvents(`${label} (before):`, actual.before, expected.before, initialRender); | ||
this._assertEvents(`${label} (after):`, actual.before, expected.before, initialRender); | ||
|
||
this.resetEvents(); | ||
} | ||
|
||
_assertEvents(label, actual, expected, initialRender) { | ||
this.assert.equal(actual.length, expected.length , `${label}: expected ${expected.length} and got ${actual.length}`); | ||
|
||
actual.forEach((payload, i) => this.assertPayload(payload, expected[i], initialRender)); | ||
} | ||
|
||
assertPayload(payload, component, initialRender) { | ||
this.assert.equal(payload.object, component.toString(), 'payload.object'); | ||
this.assert.equal(payload.containerKey, component._debugContainerKey, 'payload.containerKey'); | ||
this.assert.equal(payload.view, component, 'payload.view'); | ||
|
||
if (this.isGlimmer) { | ||
this.assert.strictEqual(payload.initialRender, initialRender, 'payload.initialRender'); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.