Skip to content

Commit

Permalink
fix(testing): remove use of emulate field in E2EPage() (#4632)
Browse files Browse the repository at this point in the history
* expose `emulate` on page

* remove previous emulate logic tied to screenshot tests

* re-remove `emulate` method on exposed page

* update documentation on existing `emulate` testing config field
  • Loading branch information
tanner-reits committed Jul 31, 2023
1 parent b088b9e commit 4d7b138
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/declarations/stencil-public-compiler.ts
Expand Up @@ -1806,8 +1806,11 @@ export interface TestingConfig extends JestConfig {
browserDevtools?: boolean;

/**
* Array of browser emulations to be using during e2e tests. A full e2e
* Array of browser emulations to be used during _screenshot_ tests. A full screenshot
* test is ran for each emulation.
*
* To emulate a device display for your e2e tests, use the `setViewport` method on a test's E2E page.
* An example can be found in [the Stencil docs](https://stenciljs.com/docs/end-to-end-testing#emulate-a-display).
*/
emulate?: EmulateConfig[];

Expand Down
25 changes: 2 additions & 23 deletions src/testing/puppeteer/puppeteer-page.ts
@@ -1,5 +1,5 @@
import type { E2EProcessEnv, EmulateConfig, HostElement, JestEnvironmentGlobal } from '@stencil/core/internal';
import type { ConsoleMessage, ConsoleMessageLocation, ElementHandle, JSHandle, Page, WaitForOptions } from 'puppeteer';
import type { E2EProcessEnv, HostElement, JestEnvironmentGlobal } from '@stencil/core/internal';
import type { ConsoleMessage, ConsoleMessageLocation, ElementHandle, JSHandle, WaitForOptions } from 'puppeteer';

import type {
E2EPage,
Expand Down Expand Up @@ -30,7 +30,6 @@ export async function newE2EPage(opts: NewE2EPageOptions = {}): Promise<E2EPage>
page._e2eGoto = page.goto;
page._e2eClose = page.close;

await setPageEmulate(page as any);
await page.setCacheEnabled(false);
await initPageEvents(page);

Expand Down Expand Up @@ -276,26 +275,6 @@ async function waitForStencil(page: E2EPage, options: WaitForOptions) {
}
}

async function setPageEmulate(page: Page) {
if (page.isClosed()) {
return;
}

const emulateJsonContent = env.__STENCIL_EMULATE__;
if (!emulateJsonContent) {
return;
}

const screenshotEmulate = JSON.parse(emulateJsonContent) as EmulateConfig;

const emulateOptions = {
viewport: screenshotEmulate.viewport,
userAgent: screenshotEmulate.userAgent,
};

await (page as Page).emulate(emulateOptions);
}

async function waitForChanges(page: E2EPageInternal) {
try {
if (page.isClosed()) {
Expand Down

0 comments on commit 4d7b138

Please sign in to comment.