-
Notifications
You must be signed in to change notification settings - Fork 393
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
feat: log shadow mode through engine reporting API #3878
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { createElement, __unstable__ReportingControl as reportingControl } from 'lwc'; | ||
import { nonStandardAriaProperties } from 'test-utils'; | ||
import { createElement } from 'lwc'; | ||
import { | ||
attachReportingControlDispatcher, | ||
detachReportingControlDispatcher, | ||
nonStandardAriaProperties, | ||
} from 'test-utils'; | ||
import Light from 'x/light'; | ||
import Shadow from 'x/shadow'; | ||
|
||
|
@@ -10,11 +14,11 @@ if (process.env.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL) { | |
|
||
beforeEach(() => { | ||
dispatcher = jasmine.createSpy(); | ||
reportingControl.attachDispatcher(dispatcher); | ||
attachReportingControlDispatcher(dispatcher, ['NonStandardAriaReflection']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome!! |
||
}); | ||
|
||
afterEach(() => { | ||
reportingControl.detachDispatcher(); | ||
detachReportingControlDispatcher(); | ||
}); | ||
|
||
nonStandardAriaProperties.forEach((prop) => { | ||
|
@@ -61,7 +65,6 @@ if (process.env.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL) { | |
elm.getPropOnElement(prop); | ||
}).toLogWarningDev(inComponentWarning); | ||
|
||
expect(dispatcher).toHaveBeenCalledTimes(2); | ||
expect(dispatcher.calls.allArgs()).toEqual([ | ||
[ | ||
'NonStandardAriaReflection', | ||
|
@@ -93,7 +96,6 @@ if (process.env.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL) { | |
return unused; // remove lint warning | ||
}).toLogWarningDev(outsideComponentWarning); | ||
|
||
expect(dispatcher).toHaveBeenCalledTimes(2); | ||
expect(dispatcher.calls.allArgs()).toEqual([ | ||
[ | ||
'NonStandardAriaReflection', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { createElement } from 'lwc'; | ||
import { attachReportingControlDispatcher, detachReportingControlDispatcher } from 'test-utils'; | ||
|
||
import Component from 'x/component'; | ||
import Parent from 'x/parent'; | ||
import Light from 'x/light'; | ||
|
||
// Should be kept in sync with the enum in vm.ts | ||
const ShadowMode = { | ||
Native: 0, | ||
Synthetic: 1, | ||
}; | ||
|
||
describe('ShadowModeUsage', () => { | ||
let dispatcher; | ||
|
||
beforeEach(() => { | ||
dispatcher = jasmine.createSpy(); | ||
attachReportingControlDispatcher(dispatcher, ['ShadowModeUsage']); | ||
}); | ||
|
||
afterEach(() => { | ||
detachReportingControlDispatcher(); | ||
}); | ||
|
||
it('should report the shadow mode for the rendered component', () => { | ||
const element = createElement('x-component', { is: Component }); | ||
document.body.appendChild(element); | ||
|
||
expect(dispatcher).toHaveBeenCalledWith('ShadowModeUsage', { | ||
tagName: 'x-component', | ||
mode: process.env.NATIVE_SHADOW ? ShadowMode.Native : ShadowMode.Synthetic, | ||
}); | ||
}); | ||
|
||
it('should report the shadow mode for all rendered components', () => { | ||
const element = createElement('x-parent', { is: Parent }); | ||
document.body.appendChild(element); | ||
|
||
expect(dispatcher).toHaveBeenCalledTimes(3); | ||
// x-parent depends on environment | ||
expect(dispatcher).toHaveBeenCalledWith('ShadowModeUsage', { | ||
tagName: 'x-parent', | ||
mode: process.env.NATIVE_SHADOW ? ShadowMode.Native : ShadowMode.Synthetic, | ||
}); | ||
// x-native should be set to native always | ||
expect(dispatcher).toHaveBeenCalledWith('ShadowModeUsage', { | ||
tagName: 'x-native', | ||
mode: ShadowMode.Native, | ||
}); | ||
// x-component depends on environment | ||
expect(dispatcher).toHaveBeenCalledWith('ShadowModeUsage', { | ||
tagName: 'x-component', | ||
mode: process.env.NATIVE_SHADOW ? ShadowMode.Native : ShadowMode.Synthetic, | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add a test here for It would also make sense to add a test for a light-DOM component, to ensure that it reports nothing. |
||
|
||
it('should report the shadow mode for components when created using CustomElementConstructor', () => { | ||
const ParentCustomElement = Parent.CustomElementConstructor; | ||
customElements.define('x-parent-custom-element', ParentCustomElement); | ||
|
||
const element = document.createElement('x-parent-custom-element'); | ||
document.body.appendChild(element); | ||
|
||
expect(dispatcher).toHaveBeenCalledTimes(3); | ||
// x-parent depends on environment | ||
expect(dispatcher).toHaveBeenCalledWith('ShadowModeUsage', { | ||
tagName: 'X-PARENT-CUSTOM-ELEMENT', | ||
mode: process.env.NATIVE_SHADOW ? ShadowMode.Native : ShadowMode.Synthetic, | ||
}); | ||
// x-native should be set to native always | ||
expect(dispatcher).toHaveBeenCalledWith('ShadowModeUsage', { | ||
tagName: 'x-native', | ||
mode: ShadowMode.Native, | ||
}); | ||
// x-component depends on environment | ||
expect(dispatcher).toHaveBeenCalledWith('ShadowModeUsage', { | ||
tagName: 'x-component', | ||
mode: process.env.NATIVE_SHADOW ? ShadowMode.Native : ShadowMode.Synthetic, | ||
}); | ||
}); | ||
|
||
it('should report no shadow mode for light DOM components', () => { | ||
const element = createElement('x-light', { is: Light }); | ||
document.body.appendChild(element); | ||
|
||
expect(dispatcher).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<div>default component</div> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class extends LightningElement {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template lwc:render-mode="light"> | ||
<p>Hello, Light DOM</p> | ||
</template> |
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 checked, and this gets tree-shaken if the customer is not using the reporting API! 🎉