Skip to content

Commit

Permalink
add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Mar 26, 2024
1 parent 37db3d2 commit 600d5c8
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 17 deletions.
6 changes: 1 addition & 5 deletions src/testing/puppeteer/puppeteer-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,7 @@ async function findWithCssSelector(
* @param selector the selector to query
* @returns the element handle
*/
async function shadowQuerySelector (
page: pd.E2EPageInternal,
rootHandle: puppeteer.ElementHandle,
selector: string,
) {
async function shadowQuerySelector(page: pd.E2EPageInternal, rootHandle: puppeteer.ElementHandle, selector: string) {
const shadowHandle = await page.evaluateHandle(
(elm: Element, shadowSelector: string) => {
if (!elm.shadowRoot) {
Expand Down
39 changes: 39 additions & 0 deletions test/end-to-end/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export namespace Components {
"cars": CarData[];
"selected": CarData;
}
interface CmpA {
}
interface CmpB {
}
interface CmpC {
}
interface DomApi {
}
interface DomInteraction {
Expand Down Expand Up @@ -139,6 +145,24 @@ declare global {
prototype: HTMLCarListElement;
new (): HTMLCarListElement;
};
interface HTMLCmpAElement extends Components.CmpA, HTMLStencilElement {
}
var HTMLCmpAElement: {
prototype: HTMLCmpAElement;
new (): HTMLCmpAElement;
};
interface HTMLCmpBElement extends Components.CmpB, HTMLStencilElement {
}
var HTMLCmpBElement: {
prototype: HTMLCmpBElement;
new (): HTMLCmpBElement;
};
interface HTMLCmpCElement extends Components.CmpC, HTMLStencilElement {
}
var HTMLCmpCElement: {
prototype: HTMLCmpCElement;
new (): HTMLCmpCElement;
};
interface HTMLDomApiElement extends Components.DomApi, HTMLStencilElement {
}
var HTMLDomApiElement: {
Expand Down Expand Up @@ -253,6 +277,9 @@ declare global {
"build-data": HTMLBuildDataElement;
"car-detail": HTMLCarDetailElement;
"car-list": HTMLCarListElement;
"cmp-a": HTMLCmpAElement;
"cmp-b": HTMLCmpBElement;
"cmp-c": HTMLCmpCElement;
"dom-api": HTMLDomApiElement;
"dom-interaction": HTMLDomInteractionElement;
"dom-visible": HTMLDomVisibleElement;
Expand Down Expand Up @@ -287,6 +314,12 @@ declare namespace LocalJSX {
"onCarSelected"?: (event: CarListCustomEvent<CarData>) => void;
"selected"?: CarData;
}
interface CmpA {
}
interface CmpB {
}
interface CmpC {
}
interface DomApi {
}
interface DomInteraction {
Expand Down Expand Up @@ -336,6 +369,9 @@ declare namespace LocalJSX {
"build-data": BuildData;
"car-detail": CarDetail;
"car-list": CarList;
"cmp-a": CmpA;
"cmp-b": CmpB;
"cmp-c": CmpC;
"dom-api": DomApi;
"dom-interaction": DomInteraction;
"dom-visible": DomVisible;
Expand Down Expand Up @@ -365,6 +401,9 @@ declare module "@stencil/core" {
* Component that helps display a list of cars
*/
"car-list": LocalJSX.CarList & JSXBase.HTMLAttributes<HTMLCarListElement>;
"cmp-a": LocalJSX.CmpA & JSXBase.HTMLAttributes<HTMLCmpAElement>;
"cmp-b": LocalJSX.CmpB & JSXBase.HTMLAttributes<HTMLCmpBElement>;
"cmp-c": LocalJSX.CmpC & JSXBase.HTMLAttributes<HTMLCmpCElement>;
"dom-api": LocalJSX.DomApi & JSXBase.HTMLAttributes<HTMLDomApiElement>;
"dom-interaction": LocalJSX.DomInteraction & JSXBase.HTMLAttributes<HTMLDomInteractionElement>;
"dom-visible": LocalJSX.DomVisible & JSXBase.HTMLAttributes<HTMLDomVisibleElement>;
Expand Down
18 changes: 18 additions & 0 deletions test/end-to-end/src/deep-selector/cmpA.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, h } from '@stencil/core';

@Component({
tag: 'cmp-a',
shadow: true,
})
export class ComponentA {
render() {
return (
<div>
<section>
<span>I am in component A</span>
</section>
<cmp-b></cmp-b>
</div>
);
}
}
18 changes: 18 additions & 0 deletions test/end-to-end/src/deep-selector/cmpB.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, h } from '@stencil/core';

@Component({
tag: 'cmp-b',
shadow: true,
})
export class ComponentB {
render() {
return (
<div>
<section>
<span>I am in component B</span>
</section>
<cmp-c></cmp-c>
</div>
);
}
}
15 changes: 15 additions & 0 deletions test/end-to-end/src/deep-selector/cmpC.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, h } from '@stencil/core';

@Component({
tag: 'cmp-c',
shadow: true,
})
export class ComponentC {
render() {
return (
<div>
<span>I am in component C</span>
</div>
);
}
}
23 changes: 23 additions & 0 deletions test/end-to-end/src/deep-selector/deep-selector.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { newE2EPage } from '@stencil/core/testing';

describe('goto root url', () => {
it('have custom hydrate flags and css', async () => {
// create a new puppeteer page
const page = await newE2EPage({
html: `
<cmp-a></cmp-a>
`,
});

const spanCmpA = await page.$('cmp-a >>> span');
expect(await spanCmpA.evaluate((el) => el.textContent)).toBe('I am in component A');
const spanCmpB = await page.$('cmp-a >>> cmp-b >>> span');
expect(await spanCmpB.evaluate((el) => el.textContent)).toBe('I am in component B');
const spanCmpC = await page.$('cmp-a >>> cmp-b >>> cmp-c >>> span');
expect(await spanCmpC.evaluate((el) => el.textContent)).toBe('I am in component C');

// we skip through the shadow dom
const spanCmp = await page.$('cmp-a >>> cmp-c >>> span');
expect(await spanCmp.evaluate((el) => el.textContent)).toBe('I am in component C');
});
});
23 changes: 23 additions & 0 deletions test/end-to-end/src/deep-selector/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# cmp-c



<!-- Auto Generated Below -->


## Dependencies

### Used by

- [cmp-b](.)

### Graph
```mermaid
graph TD;
cmp-b --> cmp-c
style cmp-c fill:#f9f,stroke:#333,stroke-width:4px
```

----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export class ReflectNanAttributeHyphen {
// for this test, it's necessary that 'reflect' is true, the class member is camel-cased, and is of type 'number'
@Prop({ reflect: true }) valNum: number;

// counter to proxy the number of times a render has occurred, since we don't have access to those dev tools during
// karma tests
// counter to proxy the number of times a render has occurred
renderCount = 0;

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export class ChildReflectNanAttribute {
// for this test, it's necessary that 'reflect' is true, the class member is not camel-cased, and is of type 'number'
@Prop({ reflect: true }) val: number;

// counter to proxy the number of times a render has occurred, since we don't have access to those dev tools during
// karma tests
// counter to proxy the number of times a render has occurred
renderCount = 0;

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { Component, h } from '@stencil/core';
shadow: true,
})
export class ParentReflectNanAttribute {
// counter to proxy the number of times a render has occurred, since we don't have access to those dev tools during
// karma tests
// counter to proxy the number of times a render has occurred
renderCount = 0;

render() {
Expand Down
3 changes: 1 addition & 2 deletions test/wdio/reflect-nan-attribute/reflect-nan-attribute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export class ReflectNanAttribute {
// for this test, it's necessary that 'reflect' is true, the class member is not camel-cased, and is of type 'number'
@Prop({ reflect: true }) val: number;

// counter to proxy the number of times a render has occurred, since we don't have access to those dev tools during
// karma tests
// counter to proxy the number of times a render has occurred
renderCount = 0;

render() {
Expand Down
3 changes: 1 addition & 2 deletions test/wdio/reflect-single-render/child-with-reflection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { Component, h, Prop } from '@stencil/core';
shadow: true,
})
export class ChildWithReflection {
// counter to proxy the number of times a render has occurred, since we don't have access to those dev tools during
// karma tests
// counter to proxy the number of times a render has occurred
renderCount = 0;

// to properly replicate the issue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { Component, h } from '@stencil/core';
shadow: true,
})
export class MyComponent {
// counter to proxy the number of times a render has occurred, since we don't have access to those dev tools during
// karma tests
// counter to proxy the number of times a render has occurred
renderCount = 0;

render() {
Expand Down

0 comments on commit 600d5c8

Please sign in to comment.