Repository navigation
feat(e2e): reuse the running app between tests through a reset link #1258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| import { test } from '@e2e-dev/mobile'; | ||
| import { APP_ID } from '../../targets.ts'; | ||
| import { test as baseTest } from '@e2e-dev/mobile'; | ||
|
|
||
| export { test }; | ||
| export { expect } from 'e2e'; | ||
| export type { App, Locator, Screen, ScrollDirection, TextMatch } from 'e2e'; | ||
| export type { Device } from '@e2e-dev/mobile'; | ||
|
|
@@ -12,21 +10,49 @@ | |
| }; | ||
|
|
||
| /** | ||
| * Registers a beforeEach that relaunches the app, so every test in the file | ||
| * starts fresh at the home list. Call it at the top of every test file: the | ||
| * engine neither installs nor launches anything on its own, a module-level | ||
| * hook in this shared file would only attach to the first file evaluated in | ||
| * a realm, and the explicit relaunch terminates first where app.open() or | ||
| * app.restart() only resume an app the surface does not know is running. | ||
| * With E2E_IOS_APP_PATH / E2E_ANDROID_APK_PATH set, that build is installed | ||
| * before every relaunch: the install replaces the binary and keeps its data, | ||
| * so it stays correct across device pools and realms without tracking what | ||
| * is already on which device. State survives the relaunch only when the app | ||
| * persists it (the layout direction toggle does). | ||
| * What this realm knows about the running app, while it can be trusted: the | ||
| * layout direction it launched with and the mount id of the example on | ||
| * screen (undefined when it shows home). Undefined means relaunch first. | ||
| */ | ||
| export const appSession: { | ||
| state: { direction: 'ltr' | 'rtl'; mount: string | undefined } | undefined; | ||
| lastTestPassed: boolean; | ||
| } = { state: undefined, lastTestPassed: false }; | ||
|
|
||
| /** | ||
| * The engine's `test`, with every test body wrapped so a test that fails or | ||
| * never finishes (a timeout abandons the body without rejecting it) leaves | ||
| * the app untrusted for the next one: an alert, keyboard or modal it left up | ||
| * would survive an in-app reset. | ||
| */ | ||
| export const test: typeof baseTest = new Proxy(baseTest, { | ||
| apply(target, thisArg, args: unknown[]) { | ||
| const body = args.at(-1) as (fixtures: unknown) => Promise<void>; | ||
| args[args.length - 1] = async (fixtures: unknown) => { | ||
| if (!appSession.lastTestPassed) appSession.state = undefined; | ||
| appSession.lastTestPassed = false; | ||
| await body(fixtures); | ||
| appSession.lastTestPassed = true; | ||
| }; | ||
| return Reflect.apply(target, thisArg, args); | ||
| }, | ||
|
Check warning on line 38 in e2e/tests/support/test.ts
|
||
|
Comment on lines
+29
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Minor · A test.skip inside a body marks the next test's app as dirty
DetailsAlso raised hereAlso raised at this location by persona persona: Useful? Reply Reply |
||
| }); | ||
|
|
||
| /** | ||
| * Registers a beforeEach that installs the build when E2E_IOS_APP_PATH / | ||
| * E2E_ANDROID_APK_PATH is set. Call it at the top of every test file: the | ||
| * engine neither installs nor launches anything on its own, and a | ||
| * module-level hook in this shared file would only attach to the first file | ||
| * evaluated in a realm. The install replaces the binary and keeps its data, so | ||
| * it stays correct across device pools and realms without tracking what is | ||
| * already on which device; it also stops the app. Launching is left to | ||
| * openExample, which reuses a running app it can trust. | ||
| */ | ||
| export function freshAppBeforeEach(): void { | ||
| test.beforeEach(async ({ device, platform }) => { | ||
| if (APP_PATHS[platform]) await device.installApp(); | ||
| await device.openApp(APP_ID, { relaunch: true }); | ||
| if (APP_PATHS[platform]) { | ||
| appSession.state = undefined; | ||
| await device.installApp(); | ||
| } | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.