feat(rstest): add @midscene/rstest package#2450
Draft
fi3ework wants to merge 3 commits into
Draft
Conversation
Introduce @midscene/rstest, a Rstest plugin that drives a Midscene
Agent through a familiar describe / it flow. Each it block gets a
fresh agent; a custom reporter prints the merged Midscene HTML report
path after each test file finishes.
Two browser providers ship behind subpath exports:
- @midscene/rstest/playwright
- @midscene/rstest/puppeteer
createWebTest(url, options?) returns { agent } valid inside it(...).
Options pass directly through to the underlying provider — only
headless and viewport are curated as convenience fields:
- headless / viewport: shortcuts for the highest-frequency knobs.
- launchOptions / contextOptions / gotoOptions: resolvers that forward
to Playwright / Puppeteer's own option types. Object form
shallow-merges over midscene defaults; function form
(defaults) => options takes full control.
- agentOptions: forwarded to PlaywrightAgent / PuppeteerAgent.
- setup: escape hatch for lifecycles the defaults don't cover
(persistent context, CDP connect, fixture reuse, custom trace/video
orchestration).
…face Surface raw browser primitives and a secondary-agent factory on `WebTestContext`, matching the native @midscene/web/playwright fixture: - `ctx.page` — raw Playwright/Puppeteer Page (test-scoped) - `ctx.browser` — file-scoped Browser for spinning up extra contexts - `ctx.agentForPage(page, opts?)` — wrap any page in a midscene agent; its report is auto-merged with the primary's at afterEach Re-export `overrideAIConfig` and `WebPageAgentOpt` from each provider entry so programmatic config overrides don't need a second import from `@midscene/web/*`. Drop the public `AgentBundle` / `PageBundle` types in favor of an internal `TestFixture` shape; the lifecycle bundle is now a provider-implementation detail. Rename the demo to `playground.test.ts` to match the monorepo's `demo/playground.*` convention. Docs (en + zh) gain a new "Configure midscene" section covering env vars, `agentOptions`, `overrideAIConfig`, and `DEBUG=midscene:*,rstest:*`, plus examples for the new context surface.
Reshape the public API from ambient `createWebTest(url)` hooks to
rstest fixtures destructured straight off the test signature:
- `agent`, `page`, `browser`, `context`, `agentForPage` are typed
fixtures composed via dependency injection.
- File-scoped browser is launched lazily — files that don't reach
through to `agent` skip browser startup entirely.
- Per-file URL via `test.extend({ url })`; custom page lifecycles
via overriding the `page` fixture (replaces the `setup` callback).
- Promise-based browser singleton avoids the TOCTOU race that would
double-launch under `test.concurrent`.
- Shared `__reportMeta` private fixture stabilizes the timestamp
embedded in primary + secondary report filenames within one test.
`test-api-types.ts` works around rstest 0.9.9 not exporting its
`TestAPIs` / `TestContext` / `Fixtures` types — delete the file once
they become public.
Drops `createWebTest` and `registerLifecycle` exports.
337625c to
b3c5101
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduce
@midscene/rstest— Midscene exposed as native rstest fixtures. Destructureagent,page,browser,agentForPagedirectly from the test signature; the package handles browser lifecycle, per-test agent construction, and per-file HTML report merging.Two browser providers ship behind subpath exports:
@midscene/rstest/playwright@midscene/rstest/puppeteerFixtures
midsceneOptionsheadless/viewport/launchOptions/contextOptions/gotoOptions/agentOptions. Repo-wide defaults viadefineMidsceneDefaultsin a setupFile; per-file override viatest.extend({ midsceneOptions }).urlpagefixture navigates to. Empty string disables auto-navigation.browsercontext(playwright only)BrowserContextper test. Override for custom storage / state.pageurl. Override the fixture for custom page lifecycles (persistent context, trace orchestration, …). Code afterawait use(page)is teardown.agentPlaywrightAgent/PuppeteerAgentbound topage. Report collection automatic.agentForPage(page, opts?)Reporter
MidsceneReporterprintsMidscene report: midscene_run/report/<file>.htmlafter each test file. Wire intoreporters: ['default', new MidsceneReporter()]inrstest.config.ts.Notes for reviewers
TestAPIs/TestContext/Fixtures— `packages/rstest/src/test-api-types.ts` mirrors the public surface from public types only, so the emitted `.d.ts` doesn't leak unexported internals. Delete the file when rstest exposes those types.Validation
Test plan