Skip to content

Commit c6bb6f1

Browse files
chore(testing): Extends Coverage #1 (#6457)
* Add a test demonstrating how you can use extends to directly manage state as part of your baseClass * Extend Tests for @method decorator inheritance, super() calls, method override, and method composition. * Extend Tests for @prop and @State inheritance from base classes. * Extend Tests for extending Stencil-decorated classes with render() method inheritance. * Demonstrates base classes triggering host component updates via requestUpdate * Tests demonstrating lifecycle hooks living on the base class * Tests for multi-level lifecycle inheritance * Tests for ReactiveControllerHost pattern - composition based controllers with automatic lifecycle hooking * Run prettier --------- Co-authored-by: John Jenkins <johnljenkins@Hotmail.com>
1 parent 51d0f77 commit c6bb6f1

43 files changed

Lines changed: 2864 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/wdio/ts-target/components.d.ts

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export namespace Components {
5454
*/
5555
"prop2": string;
5656
}
57+
interface ExtendsControllerUpdates {
58+
}
59+
interface ExtendsDirectState {
60+
}
5761
interface ExtendsExternal {
5862
"method1": () => Promise<void>;
5963
"method2": () => Promise<void>;
@@ -66,6 +70,10 @@ export namespace Components {
6670
*/
6771
"prop2": string;
6872
}
73+
interface ExtendsLifecycleBasic {
74+
}
75+
interface ExtendsLifecycleMultilevel {
76+
}
6977
interface ExtendsLocal {
7078
"method1": () => Promise<void>;
7179
"method2": () => Promise<void>;
@@ -78,6 +86,40 @@ export namespace Components {
7886
*/
7987
"prop2": string;
8088
}
89+
interface ExtendsMethods {
90+
/**
91+
* Base method that can be called by child components
92+
*/
93+
"baseMethod": () => Promise<string>;
94+
/**
95+
* Child-specific method that uses parent's protected helper
96+
*/
97+
"childMethod": () => Promise<string>;
98+
/**
99+
* Method that composes parent and child behavior
100+
*/
101+
"composedMethod": () => Promise<string>;
102+
/**
103+
* Method to get the call log for testing
104+
*/
105+
"getCallLog": () => Promise<string[]>;
106+
/**
107+
* Method to get internal value for testing
108+
*/
109+
"getInternalValue": () => Promise<string>;
110+
/**
111+
* Override parent method with super() call
112+
*/
113+
"overridableMethod": () => Promise<string>;
114+
/**
115+
* Method to reset state for testing
116+
*/
117+
"reset": () => Promise<void>;
118+
/**
119+
* Method to trigger display update from test
120+
*/
121+
"updateDisplay": (value: string) => Promise<void>;
122+
}
81123
interface ExtendsMixinCmp {
82124
"method1": () => Promise<void>;
83125
"method2": () => Promise<void>;
@@ -95,6 +137,48 @@ export namespace Components {
95137
*/
96138
"prop3": string;
97139
}
140+
/**
141+
* Test Case #3: Property & State Inheritance Basics
142+
* This component extends PropsStateBase to test:
143+
* -
144+
* @Prop inheritance from base class
145+
* -
146+
* @State inheritance from base class
147+
* - Additional
148+
* @Prop and
149+
* @State without conflicts
150+
* - Property reactivity (inherited props/state trigger re-renders)
151+
*/
152+
interface ExtendsPropsState {
153+
/**
154+
* @default 0
155+
*/
156+
"baseCount": number;
157+
/**
158+
* @default 'base prop value'
159+
*/
160+
"baseProp": string;
161+
/**
162+
* @default 'component prop value'
163+
*/
164+
"componentProp": string;
165+
"incrementBaseCount": () => Promise<void>;
166+
"toggleBaseEnabled": () => Promise<void>;
167+
"updateBaseState": (value: string) => Promise<void>;
168+
"updateComponentState": (value: string) => Promise<void>;
169+
}
170+
/**
171+
* Test Case #5: Render Method Inheritance
172+
* This component extends RenderBase to test:
173+
* - Render Inheritance: Component render() method calls super.render() to include parent template
174+
* - Template Composition: Component composes parent template with additional content and structure
175+
* - Slot Integration: Parent template slots work correctly when inherited and extended
176+
* - CSS Class Inheritance: CSS classes from parent template maintained in component extension
177+
*/
178+
interface ExtendsRender {
179+
}
180+
interface ExtendsViaHostCmp {
181+
}
98182
interface TsTargetProps {
99183
/**
100184
* @default 'basicProp'
@@ -137,12 +221,36 @@ declare global {
137221
prototype: HTMLExtendsCmpCmpElement;
138222
new (): HTMLExtendsCmpCmpElement;
139223
};
224+
interface HTMLExtendsControllerUpdatesElement extends Components.ExtendsControllerUpdates, HTMLStencilElement {
225+
}
226+
var HTMLExtendsControllerUpdatesElement: {
227+
prototype: HTMLExtendsControllerUpdatesElement;
228+
new (): HTMLExtendsControllerUpdatesElement;
229+
};
230+
interface HTMLExtendsDirectStateElement extends Components.ExtendsDirectState, HTMLStencilElement {
231+
}
232+
var HTMLExtendsDirectStateElement: {
233+
prototype: HTMLExtendsDirectStateElement;
234+
new (): HTMLExtendsDirectStateElement;
235+
};
140236
interface HTMLExtendsExternalElement extends Components.ExtendsExternal, HTMLStencilElement {
141237
}
142238
var HTMLExtendsExternalElement: {
143239
prototype: HTMLExtendsExternalElement;
144240
new (): HTMLExtendsExternalElement;
145241
};
242+
interface HTMLExtendsLifecycleBasicElement extends Components.ExtendsLifecycleBasic, HTMLStencilElement {
243+
}
244+
var HTMLExtendsLifecycleBasicElement: {
245+
prototype: HTMLExtendsLifecycleBasicElement;
246+
new (): HTMLExtendsLifecycleBasicElement;
247+
};
248+
interface HTMLExtendsLifecycleMultilevelElement extends Components.ExtendsLifecycleMultilevel, HTMLStencilElement {
249+
}
250+
var HTMLExtendsLifecycleMultilevelElement: {
251+
prototype: HTMLExtendsLifecycleMultilevelElement;
252+
new (): HTMLExtendsLifecycleMultilevelElement;
253+
};
146254
interface HTMLExtendsLocalElementEventMap {
147255
"myEvent": string;
148256
}
@@ -160,12 +268,56 @@ declare global {
160268
prototype: HTMLExtendsLocalElement;
161269
new (): HTMLExtendsLocalElement;
162270
};
271+
interface HTMLExtendsMethodsElement extends Components.ExtendsMethods, HTMLStencilElement {
272+
}
273+
var HTMLExtendsMethodsElement: {
274+
prototype: HTMLExtendsMethodsElement;
275+
new (): HTMLExtendsMethodsElement;
276+
};
163277
interface HTMLExtendsMixinCmpElement extends Components.ExtendsMixinCmp, HTMLStencilElement {
164278
}
165279
var HTMLExtendsMixinCmpElement: {
166280
prototype: HTMLExtendsMixinCmpElement;
167281
new (): HTMLExtendsMixinCmpElement;
168282
};
283+
/**
284+
* Test Case #3: Property & State Inheritance Basics
285+
* This component extends PropsStateBase to test:
286+
* -
287+
* @Prop inheritance from base class
288+
* -
289+
* @State inheritance from base class
290+
* - Additional
291+
* @Prop and
292+
* @State without conflicts
293+
* - Property reactivity (inherited props/state trigger re-renders)
294+
*/
295+
interface HTMLExtendsPropsStateElement extends Components.ExtendsPropsState, HTMLStencilElement {
296+
}
297+
var HTMLExtendsPropsStateElement: {
298+
prototype: HTMLExtendsPropsStateElement;
299+
new (): HTMLExtendsPropsStateElement;
300+
};
301+
/**
302+
* Test Case #5: Render Method Inheritance
303+
* This component extends RenderBase to test:
304+
* - Render Inheritance: Component render() method calls super.render() to include parent template
305+
* - Template Composition: Component composes parent template with additional content and structure
306+
* - Slot Integration: Parent template slots work correctly when inherited and extended
307+
* - CSS Class Inheritance: CSS classes from parent template maintained in component extension
308+
*/
309+
interface HTMLExtendsRenderElement extends Components.ExtendsRender, HTMLStencilElement {
310+
}
311+
var HTMLExtendsRenderElement: {
312+
prototype: HTMLExtendsRenderElement;
313+
new (): HTMLExtendsRenderElement;
314+
};
315+
interface HTMLExtendsViaHostCmpElement extends Components.ExtendsViaHostCmp, HTMLStencilElement {
316+
}
317+
var HTMLExtendsViaHostCmpElement: {
318+
prototype: HTMLExtendsViaHostCmpElement;
319+
new (): HTMLExtendsViaHostCmpElement;
320+
};
169321
interface HTMLTsTargetPropsElement extends Components.TsTargetProps, HTMLStencilElement {
170322
}
171323
var HTMLTsTargetPropsElement: {
@@ -177,9 +329,17 @@ declare global {
177329
"extended-cmp-cmp": HTMLExtendedCmpCmpElement;
178330
"extends-abstract": HTMLExtendsAbstractElement;
179331
"extends-cmp-cmp": HTMLExtendsCmpCmpElement;
332+
"extends-controller-updates": HTMLExtendsControllerUpdatesElement;
333+
"extends-direct-state": HTMLExtendsDirectStateElement;
180334
"extends-external": HTMLExtendsExternalElement;
335+
"extends-lifecycle-basic": HTMLExtendsLifecycleBasicElement;
336+
"extends-lifecycle-multilevel": HTMLExtendsLifecycleMultilevelElement;
181337
"extends-local": HTMLExtendsLocalElement;
338+
"extends-methods": HTMLExtendsMethodsElement;
182339
"extends-mixin-cmp": HTMLExtendsMixinCmpElement;
340+
"extends-props-state": HTMLExtendsPropsStateElement;
341+
"extends-render": HTMLExtendsRenderElement;
342+
"extends-via-host-cmp": HTMLExtendsViaHostCmpElement;
183343
"ts-target-props": HTMLTsTargetPropsElement;
184344
}
185345
}
@@ -224,6 +384,10 @@ declare namespace LocalJSX {
224384
*/
225385
"prop2"?: string;
226386
}
387+
interface ExtendsControllerUpdates {
388+
}
389+
interface ExtendsDirectState {
390+
}
227391
interface ExtendsExternal {
228392
/**
229393
* @default 'default text'
@@ -234,6 +398,10 @@ declare namespace LocalJSX {
234398
*/
235399
"prop2"?: string;
236400
}
401+
interface ExtendsLifecycleBasic {
402+
}
403+
interface ExtendsLifecycleMultilevel {
404+
}
237405
interface ExtendsLocal {
238406
"onMyEvent"?: (event: ExtendsLocalCustomEvent<string>) => void;
239407
/**
@@ -245,6 +413,8 @@ declare namespace LocalJSX {
245413
*/
246414
"prop2"?: string;
247415
}
416+
interface ExtendsMethods {
417+
}
248418
interface ExtendsMixinCmp {
249419
/**
250420
* @default 'default text'
@@ -259,6 +429,44 @@ declare namespace LocalJSX {
259429
*/
260430
"prop3"?: string;
261431
}
432+
/**
433+
* Test Case #3: Property & State Inheritance Basics
434+
* This component extends PropsStateBase to test:
435+
* -
436+
* @Prop inheritance from base class
437+
* -
438+
* @State inheritance from base class
439+
* - Additional
440+
* @Prop and
441+
* @State without conflicts
442+
* - Property reactivity (inherited props/state trigger re-renders)
443+
*/
444+
interface ExtendsPropsState {
445+
/**
446+
* @default 0
447+
*/
448+
"baseCount"?: number;
449+
/**
450+
* @default 'base prop value'
451+
*/
452+
"baseProp"?: string;
453+
/**
454+
* @default 'component prop value'
455+
*/
456+
"componentProp"?: string;
457+
}
458+
/**
459+
* Test Case #5: Render Method Inheritance
460+
* This component extends RenderBase to test:
461+
* - Render Inheritance: Component render() method calls super.render() to include parent template
462+
* - Template Composition: Component composes parent template with additional content and structure
463+
* - Slot Integration: Parent template slots work correctly when inherited and extended
464+
* - CSS Class Inheritance: CSS classes from parent template maintained in component extension
465+
*/
466+
interface ExtendsRender {
467+
}
468+
interface ExtendsViaHostCmp {
469+
}
262470
interface TsTargetProps {
263471
/**
264472
* @default 'basicProp'
@@ -276,9 +484,17 @@ declare namespace LocalJSX {
276484
"extended-cmp-cmp": ExtendedCmpCmp;
277485
"extends-abstract": ExtendsAbstract;
278486
"extends-cmp-cmp": ExtendsCmpCmp;
487+
"extends-controller-updates": ExtendsControllerUpdates;
488+
"extends-direct-state": ExtendsDirectState;
279489
"extends-external": ExtendsExternal;
490+
"extends-lifecycle-basic": ExtendsLifecycleBasic;
491+
"extends-lifecycle-multilevel": ExtendsLifecycleMultilevel;
280492
"extends-local": ExtendsLocal;
493+
"extends-methods": ExtendsMethods;
281494
"extends-mixin-cmp": ExtendsMixinCmp;
495+
"extends-props-state": ExtendsPropsState;
496+
"extends-render": ExtendsRender;
497+
"extends-via-host-cmp": ExtendsViaHostCmp;
282498
"ts-target-props": TsTargetProps;
283499
}
284500
}
@@ -290,9 +506,37 @@ declare module "@stencil/core" {
290506
"extended-cmp-cmp": LocalJSX.ExtendedCmpCmp & JSXBase.HTMLAttributes<HTMLExtendedCmpCmpElement>;
291507
"extends-abstract": LocalJSX.ExtendsAbstract & JSXBase.HTMLAttributes<HTMLExtendsAbstractElement>;
292508
"extends-cmp-cmp": LocalJSX.ExtendsCmpCmp & JSXBase.HTMLAttributes<HTMLExtendsCmpCmpElement>;
509+
"extends-controller-updates": LocalJSX.ExtendsControllerUpdates & JSXBase.HTMLAttributes<HTMLExtendsControllerUpdatesElement>;
510+
"extends-direct-state": LocalJSX.ExtendsDirectState & JSXBase.HTMLAttributes<HTMLExtendsDirectStateElement>;
293511
"extends-external": LocalJSX.ExtendsExternal & JSXBase.HTMLAttributes<HTMLExtendsExternalElement>;
512+
"extends-lifecycle-basic": LocalJSX.ExtendsLifecycleBasic & JSXBase.HTMLAttributes<HTMLExtendsLifecycleBasicElement>;
513+
"extends-lifecycle-multilevel": LocalJSX.ExtendsLifecycleMultilevel & JSXBase.HTMLAttributes<HTMLExtendsLifecycleMultilevelElement>;
294514
"extends-local": LocalJSX.ExtendsLocal & JSXBase.HTMLAttributes<HTMLExtendsLocalElement>;
515+
"extends-methods": LocalJSX.ExtendsMethods & JSXBase.HTMLAttributes<HTMLExtendsMethodsElement>;
295516
"extends-mixin-cmp": LocalJSX.ExtendsMixinCmp & JSXBase.HTMLAttributes<HTMLExtendsMixinCmpElement>;
517+
/**
518+
* Test Case #3: Property & State Inheritance Basics
519+
* This component extends PropsStateBase to test:
520+
* -
521+
* @Prop inheritance from base class
522+
* -
523+
* @State inheritance from base class
524+
* - Additional
525+
* @Prop and
526+
* @State without conflicts
527+
* - Property reactivity (inherited props/state trigger re-renders)
528+
*/
529+
"extends-props-state": LocalJSX.ExtendsPropsState & JSXBase.HTMLAttributes<HTMLExtendsPropsStateElement>;
530+
/**
531+
* Test Case #5: Render Method Inheritance
532+
* This component extends RenderBase to test:
533+
* - Render Inheritance: Component render() method calls super.render() to include parent template
534+
* - Template Composition: Component composes parent template with additional content and structure
535+
* - Slot Integration: Parent template slots work correctly when inherited and extended
536+
* - CSS Class Inheritance: CSS classes from parent template maintained in component extension
537+
*/
538+
"extends-render": LocalJSX.ExtendsRender & JSXBase.HTMLAttributes<HTMLExtendsRenderElement>;
539+
"extends-via-host-cmp": LocalJSX.ExtendsViaHostCmp & JSXBase.HTMLAttributes<HTMLExtendsViaHostCmpElement>;
296540
"ts-target-props": LocalJSX.TsTargetProps & JSXBase.HTMLAttributes<HTMLTsTargetPropsElement>;
297541
}
298542
}

0 commit comments

Comments
 (0)