-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(testing): support deep piercing with Puppeteer (#5481)
* feat(testing): support deep piercing with Puppeteer * minor clean ups * add e2e tests * rely on puppeteer implementation * revert stencil config * prettier
- Loading branch information
1 parent
404d2ba
commit 13d5d41
Showing
13 changed files
with
217 additions
and
86 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
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> | ||
); | ||
} | ||
} |
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,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> | ||
); | ||
} | ||
} |
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,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> | ||
); | ||
} | ||
} |
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,72 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
|
||
describe('Shadow DOM piercing', () => { | ||
it('can pierce through shadow DOM via Puppeteer primitives', 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'); | ||
}); | ||
|
||
it('can pierce through shadow DOM via Stencil E2E testing API', async () => { | ||
// create a new puppeteer page | ||
const page = await newE2EPage({ | ||
html: ` | ||
<cmp-a></cmp-a> | ||
`, | ||
}); | ||
|
||
const spanCmpA = await page.find('cmp-a >>> span'); | ||
expect(spanCmpA.textContent).toBe('I am in component A'); | ||
const spanCmpB = await page.find('cmp-a >>> cmp-b >>> span'); | ||
expect(spanCmpB.textContent).toBe('I am in component B'); | ||
const spanCmpC = await page.find('cmp-a >>> div > cmp-b >>> div cmp-c >>> span'); | ||
expect(spanCmpC.textContent).toBe('I am in component C'); | ||
|
||
// we skip through the shadow dom | ||
const spanCmp = await page.find('cmp-a >>> cmp-c >>> span'); | ||
expect(spanCmp.textContent).toBe('I am in component C'); | ||
}); | ||
|
||
it('can pierce through shadow DOM via findAll', async () => { | ||
// create a new puppeteer page | ||
const page = await newE2EPage({ | ||
html: ` | ||
<cmp-a></cmp-a> | ||
`, | ||
}); | ||
|
||
const spans = await page.findAll('cmp-a >>> span'); | ||
expect(spans).toHaveLength(3); | ||
expect(spans[0].textContent).toBe('I am in component A'); | ||
expect(spans[1].textContent).toBe('I am in component B'); | ||
expect(spans[2].textContent).toBe('I am in component C'); | ||
|
||
const spansCmpB = await page.findAll('cmp-a >>> cmp-b >>> span'); | ||
expect(spansCmpB).toHaveLength(2); | ||
expect(spansCmpB[0].textContent).toBe('I am in component B'); | ||
expect(spansCmpB[1].textContent).toBe('I am in component C'); | ||
|
||
const spansCmpC = await page.findAll('cmp-a >>> cmp-b >>> cmp-c >>> span'); | ||
expect(spansCmpC).toHaveLength(1); | ||
expect(spansCmpC[0].textContent).toBe('I am in component C'); | ||
|
||
// we skip through the shadow dom | ||
const spansCmp = await page.findAll('cmp-a >>> cmp-c >>> span'); | ||
expect(spansCmp).toHaveLength(1); | ||
expect(spansCmp[0].textContent).toBe('I am in component C'); | ||
}); | ||
}); |
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,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/)* |
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
Oops, something went wrong.