Skip to content

Commit

Permalink
fix(testing): remove use of emulate field in E2EPage()
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduy1407 committed Dec 4, 2023
1 parent ec95b4f commit 8c10e8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/declarations/rindo-public-compiler.ts
Original file line number Diff line number Diff line change
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 Rindo docs](https://rindojs.web.app/docs/end-to-end-testing#emulate-a-display).
*/
emulate?: EmulateConfig[];

Expand Down
25 changes: 2 additions & 23 deletions src/testing/puppeteer/puppeteer-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { E2EProcessEnv, EmulateConfig, HostElement, JestEnvironmentGlobal } from '@rindo/core/internal';
import type { ConsoleMessage, ConsoleMessageLocation, ElementHandle, JSHandle, Page, WaitForOptions } from 'puppeteer';
import type { E2EProcessEnv, HostElement, JestEnvironmentGlobal } from '@rindo/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 waitForRindo(page: E2EPage, options: WaitForOptions) {
}
}

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

const emulateJsonContent = env.__RINDO_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 8c10e8b

Please sign in to comment.