@ralphralphai/playwright 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.mjs +1 -1
- package/dist/{upload-FIxKqKb3.cjs → upload-D40MqSQa.cjs} +215 -19
- package/dist/upload-D40MqSQa.cjs.map +1 -0
- package/dist/{upload-CUtC_rnN.mjs → upload-jup_jLlm.mjs} +215 -19
- package/dist/upload-jup_jLlm.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/upload-CUtC_rnN.mjs.map +0 -1
- package/dist/upload-FIxKqKb3.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -93,6 +93,44 @@ CSS animations and transitions are frozen for the screenshot. For animations
|
|
|
93
93
|
driven from JavaScript, set `reduceMotion` if your app honors
|
|
94
94
|
`prefers-reduced-motion`.
|
|
95
95
|
|
|
96
|
+
To hold timers and animations at the same position across the screenshot,
|
|
97
|
+
tracked-element geometry, and ARIA snapshot, enable:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
ralphOptions: {
|
|
101
|
+
freezeDuringCapture: true,
|
|
102
|
+
},
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Ralph installs Playwright's clock before the app loads. Before capture it
|
|
106
|
+
finishes running finite CSS transitions, CSS animations, and Web Animations,
|
|
107
|
+
and watches DOM changes in the page, its frames, and open shadow roots. Timers
|
|
108
|
+
and animation frames keep running while it waits for 150 ms without changes,
|
|
109
|
+
so JavaScript-driven animations can finish without adding callbacks or markers
|
|
110
|
+
to your app. Animations started by completion callbacks are checked again.
|
|
111
|
+
|
|
112
|
+
This extra settling wait is capped at 1.5 seconds, or half the remaining
|
|
113
|
+
`recordTimeoutMs` budget, whichever is smaller. Looping browser animations are
|
|
114
|
+
temporarily paused while settling. Then timers and all remaining browser
|
|
115
|
+
animations pause during capture and resume afterward, including on failure.
|
|
116
|
+
Animations already paused by the app stay paused; finished animations stay
|
|
117
|
+
finished.
|
|
118
|
+
|
|
119
|
+
The DOM quiet check is a heuristic, not a guarantee that every animation has
|
|
120
|
+
ended. Long-running JavaScript animations can be captured midway when the
|
|
121
|
+
budget expires. Future delayed work and drawing inside canvas or WebGL aren't
|
|
122
|
+
detected by this check.
|
|
123
|
+
|
|
124
|
+
This option defaults to `false`. The clock replaces the native timer APIs for
|
|
125
|
+
the lifetime of the context, so don't combine it with manual `page.clock` or
|
|
126
|
+
`context.clock` control. Playwright requires a future pause time: Ralph uses
|
|
127
|
+
the page's current time plus 100 ms, which advances the clock and can fire due
|
|
128
|
+
callbacks once before freezing. Time resumes from there without catching up
|
|
129
|
+
through the capture duration. All tabs in a context share the clock, so their
|
|
130
|
+
timers pause together and their captures run one at a time. Network responses,
|
|
131
|
+
workers, and media playback are not frozen, so unrelated updates can still
|
|
132
|
+
change the page.
|
|
133
|
+
|
|
96
134
|
### Explicitly, once the page is ready
|
|
97
135
|
|
|
98
136
|
A capture taken when the URL or the declared conditions change can catch the
|
|
@@ -190,12 +228,16 @@ not record the current page.
|
|
|
190
228
|
|
|
191
229
|
```ts
|
|
192
230
|
const context = await browser.newContext();
|
|
193
|
-
ralph.observe(context);
|
|
231
|
+
await ralph.observe(context);
|
|
194
232
|
// ...
|
|
195
233
|
await ralph.waitForCapture();
|
|
196
234
|
await context.close();
|
|
197
235
|
```
|
|
198
236
|
|
|
237
|
+
With `freezeDuringCapture`, await `ralph.observe(context)` before creating or
|
|
238
|
+
navigating any pages, so no app scripts schedule native timers first. A context
|
|
239
|
+
with an already navigated page cannot be enrolled with this option enabled.
|
|
240
|
+
|
|
199
241
|
### What happened between two nodes
|
|
200
242
|
|
|
201
243
|
The Playwright actions a test takes on the way from one node to the next are
|
|
@@ -371,6 +413,7 @@ export default defineConfig<RalphFixtures>({
|
|
|
371
413
|
| `recordTimeoutMs` | 5000 | Budget for one recording, including `settleMs` and `ready`. Must exceed `settleMs`. |
|
|
372
414
|
| `ready` | | `(page, signal) => Promise<void>`. Waits for your app before an automatic recording. Honor `signal`. |
|
|
373
415
|
| `reduceMotion` | `false` | Emulates `prefers-reduced-motion: reduce` and waits for finite animations before recording. |
|
|
416
|
+
| `freezeDuringCapture` | `false` | Finishes finite browser animations, allows JS-driven DOM changes to settle within a bounded wait, then freezes timers and animations across capture. |
|
|
374
417
|
| `strictNodeTags` | `false` | Fails the test when the app reports a tag outside what `ralph.setNodeConditions` declared. |
|
|
375
418
|
| `ignoreUntaggedCalls` | `false` | Makes `recordNode`, `setNodeConditions`, and `observe` no-ops in untagged tests instead of throwing. |
|
|
376
419
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_upload = require("./upload-
|
|
2
|
+
const require_upload = require("./upload-D40MqSQa.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_upload.__toESM(node_path, 1);
|
|
5
5
|
let _playwright_test = require("@playwright/test");
|
|
@@ -108,7 +108,7 @@ const test = _playwright_test.test.extend({
|
|
|
108
108
|
visitAllLinks: (links, options) => require_upload.visitAllLinks(links, async () => {}, options),
|
|
109
109
|
pause: () => {},
|
|
110
110
|
resume: () => {},
|
|
111
|
-
observe: () => {
|
|
111
|
+
observe: async () => {
|
|
112
112
|
checkOptIn();
|
|
113
113
|
}
|
|
114
114
|
});
|
|
@@ -120,7 +120,7 @@ const test = _playwright_test.test.extend({
|
|
|
120
120
|
} : contextOptions);
|
|
121
121
|
},
|
|
122
122
|
context: async ({ context, _ralphRecorder }, use) => {
|
|
123
|
-
_ralphRecorder?.observe(context);
|
|
123
|
+
await _ralphRecorder?.observe(context);
|
|
124
124
|
try {
|
|
125
125
|
await use(context);
|
|
126
126
|
} finally {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["loadConfigSync","base","resolveMode","path","loadConfig","Recorder","visitAllLinks"],"sources":["../src/screens.ts","../src/index.ts"],"sourcesContent":["import type {\n PlaywrightTestOptions,\n PlaywrightWorkerOptions,\n Project,\n TestInfo,\n} from '@playwright/test';\nimport type { ScreenSize } from '@ralphralphai/config';\n\nimport { loadConfigSync } from './config';\nimport type { RalphOptions } from './types';\n\ntype RalphProject = Project<\n PlaywrightTestOptions & { ralphOptions: RalphOptions },\n PlaywrightWorkerOptions\n>;\n\nexport const SCREEN_TAG_PREFIX = '@ralph-screen:';\n\nexport type RalphProjectOptions = Pick<\n RalphOptions,\n 'config' | 'configPath'\n> & {\n /** Resolves a relative `configPath`; defaults to the current directory. */\n root?: string;\n};\n\ntype ScreenMetadata = { screenSize: ScreenSize; screenSizes: ScreenSize[] };\n\nexport function screenLabel(size: ScreenSize): string {\n return size.width + 'x' + size.height;\n}\n\n/**\n * Expands `base` into one project per `screenSizes` entry of the Ralph config.\n * Each project's viewport is that screen size.\n */\nexport function ralphProjects(\n base: RalphProject = {},\n options: RalphProjectOptions = {},\n): RalphProject[] {\n const { screenSizes } = loadConfigSync(\n options,\n options.root ?? process.cwd(),\n ).config;\n if (!screenSizes.length) {\n throw new Error('The Ralph config declares no screenSizes.');\n }\n return screenSizes.map((screenSize) => {\n const label = screenLabel(screenSize);\n const ralph: ScreenMetadata = { screenSize, screenSizes };\n return {\n ...base,\n name: base.name ? base.name + ' ' + label : label,\n use: {\n ...base.use,\n viewport: { width: screenSize.width, height: screenSize.height },\n },\n metadata: { ...base.metadata, ralph },\n };\n });\n}\n\n/**\n * Skips a test whose `@ralph-screen:WxH` tags exclude the current project's\n * screen size. Untagged tests run at every size; other projects are untouched.\n */\nexport function applyScreenSelection(testInfo: TestInfo): void {\n const selected = testInfo.tags\n .filter((tag) => tag.startsWith(SCREEN_TAG_PREFIX))\n .map((tag) => tag.slice(SCREEN_TAG_PREFIX.length));\n const metadata = (testInfo.project.metadata as { ralph?: ScreenMetadata })\n .ralph;\n if (!selected.length || !metadata) {\n return;\n }\n const known = metadata.screenSizes.map(screenLabel);\n const unknown = selected.filter((label) => !known.includes(label));\n if (unknown.length) {\n throw new Error(\n 'Unknown Ralph screen size ' +\n unknown.join(', ') +\n '; the config declares ' +\n known.join(', ') +\n '.',\n );\n }\n const current = screenLabel(metadata.screenSize);\n testInfo.skip(\n !selected.includes(current),\n 'Not selected for Ralph screen size ' + current + '.',\n );\n}\n","import path from 'node:path';\n\nimport { test as base } from '@playwright/test';\nimport type {\n PlaywrightTestArgs,\n PlaywrightTestOptions,\n PlaywrightWorkerArgs,\n PlaywrightWorkerOptions,\n TestType,\n} from '@playwright/test';\n\nimport { loadConfig, resolveMode } from './config';\nimport { Recorder, REPORTER_ENV } from './recorder';\nimport { applyScreenSelection } from './screens';\nimport type { ConfigSnapshot, Ralph, RalphOptions } from './types';\nimport { visitAllLinks } from './visit_links';\n\nexport { expect, mergeTests } from '@playwright/test';\nexport type { WebRalphConfig } from '@ralphralphai/config';\nexport {\n createRawGraphBundle,\n prepareArtifactUpload,\n uploadRawGraph,\n} from './upload';\nexport type {\n PreparedUpload,\n UploadOptions,\n UploadReceipt,\n RawGraphScreenshot,\n RawGraphBundleIndex,\n} from './upload';\nexport { MANIFEST_ATTACHMENT } from './recorder';\nexport { ralphProjects, SCREEN_TAG_PREFIX } from './screens';\nexport type { RalphProjectOptions } from './screens';\nexport type { RalphReporterOptions } from './reporter';\nexport type {\n RawGraphManifest,\n RawGraph,\n RawGraphFile,\n RawPage,\n RawNode,\n RawAction,\n ActionKind,\n ActionTarget,\n ConditionsDeclaration,\n NodeConditions,\n RecordedTags,\n RecordNodeOptions,\n TagConditions,\n TagDeclaration,\n TagValue,\n ConfigSnapshot,\n PageLayout,\n Ralph,\n RalphOptions,\n TrackedElement,\n VisitAllLinksOptions,\n} from './types';\n\nexport type RalphFixtures = { ralph: Ralph; ralphOptions: RalphOptions };\n\ntype InternalFixtures = {\n _ralphScreen: void;\n _ralphRecorder: Recorder | null;\n};\ntype WorkerFixtures = { _ralphConfigs: Map<string, Promise<ConfigSnapshot>> };\n\nexport const test: TestType<\n PlaywrightTestArgs & PlaywrightTestOptions & RalphFixtures,\n PlaywrightWorkerArgs & PlaywrightWorkerOptions\n> = base.extend<RalphFixtures & InternalFixtures, WorkerFixtures>({\n ralphOptions: [{}, { option: true }],\n _ralphConfigs: [\n // Playwright requires destructuring here to discover fixture dependencies.\n // oxlint-disable-next-line no-empty-pattern\n async ({}, use) => {\n await use(new Map());\n },\n { scope: 'worker' },\n ],\n _ralphScreen: [\n // Playwright requires destructuring here to discover fixture dependencies.\n // oxlint-disable-next-line no-empty-pattern\n async ({}, use, testInfo) => {\n // Screen selection chooses which flows run, so it applies in every mode.\n applyScreenSelection(testInfo);\n await use();\n },\n { auto: true },\n ],\n _ralphRecorder: [\n // _ralphScreen is specified here so that the playwright treat that it is\n // a dependency of this fixture.\n async (\n { ralphOptions, _ralphConfigs, _ralphScreen, playwright },\n use,\n testInfo,\n ) => {\n const mode = resolveMode(ralphOptions);\n if (!testInfo.tags.includes('@ralph') || mode === 'off') {\n await use(null);\n return;\n }\n\n // A sharded run's blob reports are merged, and uploaded by the Ralph\n // reporter, in `playwright merge-reports`.\n const reported =\n process.env[REPORTER_ENV] ||\n testInfo.config.reporter.some(([name]) => name === 'blob');\n if (mode === 'upload' && !reported) {\n throw new Error(\n \"Ralph uploads one merged graph per run from its reporter. Add ['@ralphralphai/playwright/reporter'] to `reporter` in playwright.config, or use the blob reporter and merge-reports when sharding.\",\n );\n }\n\n const root = testInfo.config.configFile\n ? path.dirname(testInfo.config.configFile)\n : process.cwd();\n\n const key = JSON.stringify({\n root,\n config: ralphOptions.config,\n configPath: ralphOptions.configPath,\n });\n\n let pending = _ralphConfigs.get(key);\n if (!pending) {\n pending = loadConfig(ralphOptions, root);\n _ralphConfigs.set(key, pending);\n }\n\n const recorder = new Recorder(\n ralphOptions,\n await pending,\n testInfo,\n mode,\n playwright,\n );\n\n try {\n await use(recorder);\n } finally {\n await recorder.finish();\n }\n },\n { auto: true, timeout: 30_000 },\n ],\n ralph: async ({ _ralphRecorder, ralphOptions }, use) => {\n const checkOptIn = () => {\n if (\n resolveMode(ralphOptions) !== 'off' &&\n !ralphOptions.ignoreUntaggedCalls\n ) {\n throw new Error('Opt this test into Ralph with the @ralph tag.');\n }\n };\n\n await use(\n _ralphRecorder ?? {\n recordNode: async () => {\n checkOptIn();\n },\n setNodeConditions: async () => {\n checkOptIn();\n return async () => {};\n },\n waitForCapture: async () => {},\n visitAllLinks: (links, options) =>\n visitAllLinks(links, async () => {}, options),\n pause: () => {},\n resume: () => {},\n observe: () => {\n checkOptIn();\n },\n },\n );\n },\n // On the context rather than per page, so popups start out reduced too.\n contextOptions: async ({ contextOptions, ralphOptions }, use, testInfo) => {\n const recording =\n testInfo.tags.includes('@ralph') && resolveMode(ralphOptions) !== 'off';\n await use(\n recording && ralphOptions.reduceMotion\n ? { ...contextOptions, reducedMotion: 'reduce' }\n : contextOptions,\n );\n },\n context: async ({ context, _ralphRecorder }, use) => {\n _ralphRecorder?.observe(context);\n try {\n await use(context);\n } finally {\n // The base context fixture closes its pages next; pending recordings still need them alive.\n await _ralphRecorder?.stopContext(context);\n }\n },\n});\n"],"mappings":";;;;;;AAgBA,MAAa,oBAAoB;AAYjC,SAAgB,YAAY,MAA0B;CACpD,OAAO,KAAK,QAAQ,MAAM,KAAK;AACjC;;;;;AAMA,SAAgB,cACd,OAAqB,CAAC,GACtB,UAA+B,CAAC,GAChB;CAChB,MAAM,EAAE,gBAAgBA,eAAAA,eACtB,SACA,QAAQ,QAAQ,QAAQ,IAAI,CAC9B,CAAC,CAAC;CACF,IAAI,CAAC,YAAY,QACf,MAAM,IAAI,MAAM,2CAA2C;CAE7D,OAAO,YAAY,KAAK,eAAe;EACrC,MAAM,QAAQ,YAAY,UAAU;EACpC,MAAM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B,OAAO,EAAE,gBAAgB,gBAAgB,KAAK,aAAa;EAGzE,MAAM,IADJ,SAAS,KAAK,SAAS,QAAQ,KAAKJ,eAAAA,YAAY,YAAY,MAAM,SAErD,aAAa,eACtB;GAAE,GAAG;GAAgB,eAAe;EAAS,IAC7C,cACN;CACF;CACA,SAAS,OAAO,EAAE,SAAS,kBAAkB,QAAQ;EACnD,gBAAgB,QAAQ,OAAO;EAC/B,IAAI;GACF,MAAM,IAAI,OAAO;EACnB,UAAU;GAER,MAAM,gBAAgB,YAAY,OAAO;EAC3C;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["loadConfigSync","base","resolveMode","path","loadConfig","Recorder","visitAllLinks"],"sources":["../src/screens.ts","../src/index.ts"],"sourcesContent":["import type {\n PlaywrightTestOptions,\n PlaywrightWorkerOptions,\n Project,\n TestInfo,\n} from '@playwright/test';\nimport type { ScreenSize } from '@ralphralphai/config';\n\nimport { loadConfigSync } from './config';\nimport type { RalphOptions } from './types';\n\ntype RalphProject = Project<\n PlaywrightTestOptions & { ralphOptions: RalphOptions },\n PlaywrightWorkerOptions\n>;\n\nexport const SCREEN_TAG_PREFIX = '@ralph-screen:';\n\nexport type RalphProjectOptions = Pick<\n RalphOptions,\n 'config' | 'configPath'\n> & {\n /** Resolves a relative `configPath`; defaults to the current directory. */\n root?: string;\n};\n\ntype ScreenMetadata = { screenSize: ScreenSize; screenSizes: ScreenSize[] };\n\nexport function screenLabel(size: ScreenSize): string {\n return size.width + 'x' + size.height;\n}\n\n/**\n * Expands `base` into one project per `screenSizes` entry of the Ralph config.\n * Each project's viewport is that screen size.\n */\nexport function ralphProjects(\n base: RalphProject = {},\n options: RalphProjectOptions = {},\n): RalphProject[] {\n const { screenSizes } = loadConfigSync(\n options,\n options.root ?? process.cwd(),\n ).config;\n if (!screenSizes.length) {\n throw new Error('The Ralph config declares no screenSizes.');\n }\n return screenSizes.map((screenSize) => {\n const label = screenLabel(screenSize);\n const ralph: ScreenMetadata = { screenSize, screenSizes };\n return {\n ...base,\n name: base.name ? base.name + ' ' + label : label,\n use: {\n ...base.use,\n viewport: { width: screenSize.width, height: screenSize.height },\n },\n metadata: { ...base.metadata, ralph },\n };\n });\n}\n\n/**\n * Skips a test whose `@ralph-screen:WxH` tags exclude the current project's\n * screen size. Untagged tests run at every size; other projects are untouched.\n */\nexport function applyScreenSelection(testInfo: TestInfo): void {\n const selected = testInfo.tags\n .filter((tag) => tag.startsWith(SCREEN_TAG_PREFIX))\n .map((tag) => tag.slice(SCREEN_TAG_PREFIX.length));\n const metadata = (testInfo.project.metadata as { ralph?: ScreenMetadata })\n .ralph;\n if (!selected.length || !metadata) {\n return;\n }\n const known = metadata.screenSizes.map(screenLabel);\n const unknown = selected.filter((label) => !known.includes(label));\n if (unknown.length) {\n throw new Error(\n 'Unknown Ralph screen size ' +\n unknown.join(', ') +\n '; the config declares ' +\n known.join(', ') +\n '.',\n );\n }\n const current = screenLabel(metadata.screenSize);\n testInfo.skip(\n !selected.includes(current),\n 'Not selected for Ralph screen size ' + current + '.',\n );\n}\n","import path from 'node:path';\n\nimport { test as base } from '@playwright/test';\nimport type {\n PlaywrightTestArgs,\n PlaywrightTestOptions,\n PlaywrightWorkerArgs,\n PlaywrightWorkerOptions,\n TestType,\n} from '@playwright/test';\n\nimport { loadConfig, resolveMode } from './config';\nimport { Recorder, REPORTER_ENV } from './recorder';\nimport { applyScreenSelection } from './screens';\nimport type { ConfigSnapshot, Ralph, RalphOptions } from './types';\nimport { visitAllLinks } from './visit_links';\n\nexport { expect, mergeTests } from '@playwright/test';\nexport type { WebRalphConfig } from '@ralphralphai/config';\nexport {\n createRawGraphBundle,\n prepareArtifactUpload,\n uploadRawGraph,\n} from './upload';\nexport type {\n PreparedUpload,\n UploadOptions,\n UploadReceipt,\n RawGraphScreenshot,\n RawGraphBundleIndex,\n} from './upload';\nexport { MANIFEST_ATTACHMENT } from './recorder';\nexport { ralphProjects, SCREEN_TAG_PREFIX } from './screens';\nexport type { RalphProjectOptions } from './screens';\nexport type { RalphReporterOptions } from './reporter';\nexport type {\n RawGraphManifest,\n RawGraph,\n RawGraphFile,\n RawPage,\n RawNode,\n RawAction,\n ActionKind,\n ActionTarget,\n ConditionsDeclaration,\n NodeConditions,\n RecordedTags,\n RecordNodeOptions,\n TagConditions,\n TagDeclaration,\n TagValue,\n ConfigSnapshot,\n PageLayout,\n Ralph,\n RalphOptions,\n TrackedElement,\n VisitAllLinksOptions,\n} from './types';\n\nexport type RalphFixtures = { ralph: Ralph; ralphOptions: RalphOptions };\n\ntype InternalFixtures = {\n _ralphScreen: void;\n _ralphRecorder: Recorder | null;\n};\ntype WorkerFixtures = { _ralphConfigs: Map<string, Promise<ConfigSnapshot>> };\n\nexport const test: TestType<\n PlaywrightTestArgs & PlaywrightTestOptions & RalphFixtures,\n PlaywrightWorkerArgs & PlaywrightWorkerOptions\n> = base.extend<RalphFixtures & InternalFixtures, WorkerFixtures>({\n ralphOptions: [{}, { option: true }],\n _ralphConfigs: [\n // Playwright requires destructuring here to discover fixture dependencies.\n // oxlint-disable-next-line no-empty-pattern\n async ({}, use) => {\n await use(new Map());\n },\n { scope: 'worker' },\n ],\n _ralphScreen: [\n // Playwright requires destructuring here to discover fixture dependencies.\n // oxlint-disable-next-line no-empty-pattern\n async ({}, use, testInfo) => {\n // Screen selection chooses which flows run, so it applies in every mode.\n applyScreenSelection(testInfo);\n await use();\n },\n { auto: true },\n ],\n _ralphRecorder: [\n // _ralphScreen is specified here so that the playwright treat that it is\n // a dependency of this fixture.\n async (\n { ralphOptions, _ralphConfigs, _ralphScreen, playwright },\n use,\n testInfo,\n ) => {\n const mode = resolveMode(ralphOptions);\n if (!testInfo.tags.includes('@ralph') || mode === 'off') {\n await use(null);\n return;\n }\n\n // A sharded run's blob reports are merged, and uploaded by the Ralph\n // reporter, in `playwright merge-reports`.\n const reported =\n process.env[REPORTER_ENV] ||\n testInfo.config.reporter.some(([name]) => name === 'blob');\n if (mode === 'upload' && !reported) {\n throw new Error(\n \"Ralph uploads one merged graph per run from its reporter. Add ['@ralphralphai/playwright/reporter'] to `reporter` in playwright.config, or use the blob reporter and merge-reports when sharding.\",\n );\n }\n\n const root = testInfo.config.configFile\n ? path.dirname(testInfo.config.configFile)\n : process.cwd();\n\n const key = JSON.stringify({\n root,\n config: ralphOptions.config,\n configPath: ralphOptions.configPath,\n });\n\n let pending = _ralphConfigs.get(key);\n if (!pending) {\n pending = loadConfig(ralphOptions, root);\n _ralphConfigs.set(key, pending);\n }\n\n const recorder = new Recorder(\n ralphOptions,\n await pending,\n testInfo,\n mode,\n playwright,\n );\n\n try {\n await use(recorder);\n } finally {\n await recorder.finish();\n }\n },\n { auto: true, timeout: 30_000 },\n ],\n ralph: async ({ _ralphRecorder, ralphOptions }, use) => {\n const checkOptIn = () => {\n if (\n resolveMode(ralphOptions) !== 'off' &&\n !ralphOptions.ignoreUntaggedCalls\n ) {\n throw new Error('Opt this test into Ralph with the @ralph tag.');\n }\n };\n\n await use(\n _ralphRecorder ?? {\n recordNode: async () => {\n checkOptIn();\n },\n setNodeConditions: async () => {\n checkOptIn();\n return async () => {};\n },\n waitForCapture: async () => {},\n visitAllLinks: (links, options) =>\n visitAllLinks(links, async () => {}, options),\n pause: () => {},\n resume: () => {},\n observe: async () => {\n checkOptIn();\n },\n },\n );\n },\n // On the context rather than per page, so popups start out reduced too.\n contextOptions: async ({ contextOptions, ralphOptions }, use, testInfo) => {\n const recording =\n testInfo.tags.includes('@ralph') && resolveMode(ralphOptions) !== 'off';\n await use(\n recording && ralphOptions.reduceMotion\n ? { ...contextOptions, reducedMotion: 'reduce' }\n : contextOptions,\n );\n },\n context: async ({ context, _ralphRecorder }, use) => {\n await _ralphRecorder?.observe(context);\n try {\n await use(context);\n } finally {\n // The base context fixture closes its pages next; pending recordings still need them alive.\n await _ralphRecorder?.stopContext(context);\n }\n },\n});\n"],"mappings":";;;;;;AAgBA,MAAa,oBAAoB;AAYjC,SAAgB,YAAY,MAA0B;CACpD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+C;EAEnE;EAEA,MAAM,IACJ,kBAAkB;GAChB,YAAY,YAAY;IACtB,WAAW;GACb;GACA,mBAAmB,YAAY;IAC7B,WAAW;IACX,OAAO,YAAY,CAAC;GACtB;GACA,gBAAgB,YAAY,CAAC;GAC7B,gBAAgB,OAAO,YACrBI,eAAAA,cAAc,OAAO,YAAY,CAAC,GAAG,OAAO;GAC9C,aAAa,CAAC;GACd,cAAc,CAAC;GACf,SAAS,YAAY;IACnB,WAAW;GACb;EACF,CACF;CACF;CAEA,gBAAgB,OAAO,EAAE,gBAAgB,gBAAgB,KAAK,aAAa;EAGzE,MAAM,IADJ,SAAS,KAAK,SAAS,QAAQ,KAAKJ,eAAAA,YAAY,YAAY,MAAM,SAErD,aAAa,eACtB;GAAE,GAAG;GAAgB,eAAe;EAAS,IAC7C,cACN;CACF;CACA,SAAS,OAAO,EAAE,SAAS,kBAAkB,QAAQ;EACnD,MAAM,gBAAgB,QAAQ,OAAO;EACrC,IAAI;GACF,MAAM,IAAI,OAAO;EACnB,UAAU;GAER,MAAM,gBAAgB,YAAY,OAAO;EAC3C;CACF;AACF,CAAC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,13 @@ type RalphOptions = {
|
|
|
10
10
|
buildId?: string;
|
|
11
11
|
settleMs?: number;
|
|
12
12
|
reduceMotion?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Install Playwright's clock before navigation. Before capture, finish finite
|
|
15
|
+
* browser animations and allow JS-driven DOM changes to settle within a
|
|
16
|
+
* bounded wait, then pause timers and remaining animations. Defaults to false.
|
|
17
|
+
* Owns the context's clock; do not combine with manual page.clock control.
|
|
18
|
+
*/
|
|
19
|
+
freezeDuringCapture?: boolean;
|
|
13
20
|
recordTimeoutMs?: number;
|
|
14
21
|
ready?: (page: Page, signal: AbortSignal) => Promise<void>;
|
|
15
22
|
/**
|
|
@@ -87,7 +94,8 @@ type Ralph = {
|
|
|
87
94
|
visitAllLinks(links: Locator, options?: VisitAllLinksOptions): Promise<void>;
|
|
88
95
|
pause(): void;
|
|
89
96
|
resume(): void;
|
|
90
|
-
|
|
97
|
+
/** With freezeDuringCapture, await this before any scripts run in a custom context. */
|
|
98
|
+
observe(context: BrowserContext): Promise<void>;
|
|
91
99
|
};
|
|
92
100
|
type TrackedElement = {
|
|
93
101
|
trackId: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as resolveMode, a as prepareArtifactUpload, f as Recorder, g as loadConfigSync, h as loadConfig, i as createRawGraphBundle, l as uploadRawGraph, p as visitAllLinks, u as MANIFEST_ATTACHMENT } from "./upload-
|
|
1
|
+
import { _ as resolveMode, a as prepareArtifactUpload, f as Recorder, g as loadConfigSync, h as loadConfig, i as createRawGraphBundle, l as uploadRawGraph, p as visitAllLinks, u as MANIFEST_ATTACHMENT } from "./upload-jup_jLlm.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { expect, mergeTests, test as test$1 } from "@playwright/test";
|
|
4
4
|
//#region src/screens.ts
|
|
@@ -106,7 +106,7 @@ const test = test$1.extend({
|
|
|
106
106
|
visitAllLinks: (links, options) => visitAllLinks(links, async () => {}, options),
|
|
107
107
|
pause: () => {},
|
|
108
108
|
resume: () => {},
|
|
109
|
-
observe: () => {
|
|
109
|
+
observe: async () => {
|
|
110
110
|
checkOptIn();
|
|
111
111
|
}
|
|
112
112
|
});
|
|
@@ -118,7 +118,7 @@ const test = test$1.extend({
|
|
|
118
118
|
} : contextOptions);
|
|
119
119
|
},
|
|
120
120
|
context: async ({ context, _ralphRecorder }, use) => {
|
|
121
|
-
_ralphRecorder?.observe(context);
|
|
121
|
+
await _ralphRecorder?.observe(context);
|
|
122
122
|
try {
|
|
123
123
|
await use(context);
|
|
124
124
|
} finally {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["base"],"sources":["../src/screens.ts","../src/index.ts"],"sourcesContent":["import type {\n PlaywrightTestOptions,\n PlaywrightWorkerOptions,\n Project,\n TestInfo,\n} from '@playwright/test';\nimport type { ScreenSize } from '@ralphralphai/config';\n\nimport { loadConfigSync } from './config';\nimport type { RalphOptions } from './types';\n\ntype RalphProject = Project<\n PlaywrightTestOptions & { ralphOptions: RalphOptions },\n PlaywrightWorkerOptions\n>;\n\nexport const SCREEN_TAG_PREFIX = '@ralph-screen:';\n\nexport type RalphProjectOptions = Pick<\n RalphOptions,\n 'config' | 'configPath'\n> & {\n /** Resolves a relative `configPath`; defaults to the current directory. */\n root?: string;\n};\n\ntype ScreenMetadata = { screenSize: ScreenSize; screenSizes: ScreenSize[] };\n\nexport function screenLabel(size: ScreenSize): string {\n return size.width + 'x' + size.height;\n}\n\n/**\n * Expands `base` into one project per `screenSizes` entry of the Ralph config.\n * Each project's viewport is that screen size.\n */\nexport function ralphProjects(\n base: RalphProject = {},\n options: RalphProjectOptions = {},\n): RalphProject[] {\n const { screenSizes } = loadConfigSync(\n options,\n options.root ?? process.cwd(),\n ).config;\n if (!screenSizes.length) {\n throw new Error('The Ralph config declares no screenSizes.');\n }\n return screenSizes.map((screenSize) => {\n const label = screenLabel(screenSize);\n const ralph: ScreenMetadata = { screenSize, screenSizes };\n return {\n ...base,\n name: base.name ? base.name + ' ' + label : label,\n use: {\n ...base.use,\n viewport: { width: screenSize.width, height: screenSize.height },\n },\n metadata: { ...base.metadata, ralph },\n };\n });\n}\n\n/**\n * Skips a test whose `@ralph-screen:WxH` tags exclude the current project's\n * screen size. Untagged tests run at every size; other projects are untouched.\n */\nexport function applyScreenSelection(testInfo: TestInfo): void {\n const selected = testInfo.tags\n .filter((tag) => tag.startsWith(SCREEN_TAG_PREFIX))\n .map((tag) => tag.slice(SCREEN_TAG_PREFIX.length));\n const metadata = (testInfo.project.metadata as { ralph?: ScreenMetadata })\n .ralph;\n if (!selected.length || !metadata) {\n return;\n }\n const known = metadata.screenSizes.map(screenLabel);\n const unknown = selected.filter((label) => !known.includes(label));\n if (unknown.length) {\n throw new Error(\n 'Unknown Ralph screen size ' +\n unknown.join(', ') +\n '; the config declares ' +\n known.join(', ') +\n '.',\n );\n }\n const current = screenLabel(metadata.screenSize);\n testInfo.skip(\n !selected.includes(current),\n 'Not selected for Ralph screen size ' + current + '.',\n );\n}\n","import path from 'node:path';\n\nimport { test as base } from '@playwright/test';\nimport type {\n PlaywrightTestArgs,\n PlaywrightTestOptions,\n PlaywrightWorkerArgs,\n PlaywrightWorkerOptions,\n TestType,\n} from '@playwright/test';\n\nimport { loadConfig, resolveMode } from './config';\nimport { Recorder, REPORTER_ENV } from './recorder';\nimport { applyScreenSelection } from './screens';\nimport type { ConfigSnapshot, Ralph, RalphOptions } from './types';\nimport { visitAllLinks } from './visit_links';\n\nexport { expect, mergeTests } from '@playwright/test';\nexport type { WebRalphConfig } from '@ralphralphai/config';\nexport {\n createRawGraphBundle,\n prepareArtifactUpload,\n uploadRawGraph,\n} from './upload';\nexport type {\n PreparedUpload,\n UploadOptions,\n UploadReceipt,\n RawGraphScreenshot,\n RawGraphBundleIndex,\n} from './upload';\nexport { MANIFEST_ATTACHMENT } from './recorder';\nexport { ralphProjects, SCREEN_TAG_PREFIX } from './screens';\nexport type { RalphProjectOptions } from './screens';\nexport type { RalphReporterOptions } from './reporter';\nexport type {\n RawGraphManifest,\n RawGraph,\n RawGraphFile,\n RawPage,\n RawNode,\n RawAction,\n ActionKind,\n ActionTarget,\n ConditionsDeclaration,\n NodeConditions,\n RecordedTags,\n RecordNodeOptions,\n TagConditions,\n TagDeclaration,\n TagValue,\n ConfigSnapshot,\n PageLayout,\n Ralph,\n RalphOptions,\n TrackedElement,\n VisitAllLinksOptions,\n} from './types';\n\nexport type RalphFixtures = { ralph: Ralph; ralphOptions: RalphOptions };\n\ntype InternalFixtures = {\n _ralphScreen: void;\n _ralphRecorder: Recorder | null;\n};\ntype WorkerFixtures = { _ralphConfigs: Map<string, Promise<ConfigSnapshot>> };\n\nexport const test: TestType<\n PlaywrightTestArgs & PlaywrightTestOptions & RalphFixtures,\n PlaywrightWorkerArgs & PlaywrightWorkerOptions\n> = base.extend<RalphFixtures & InternalFixtures, WorkerFixtures>({\n ralphOptions: [{}, { option: true }],\n _ralphConfigs: [\n // Playwright requires destructuring here to discover fixture dependencies.\n // oxlint-disable-next-line no-empty-pattern\n async ({}, use) => {\n await use(new Map());\n },\n { scope: 'worker' },\n ],\n _ralphScreen: [\n // Playwright requires destructuring here to discover fixture dependencies.\n // oxlint-disable-next-line no-empty-pattern\n async ({}, use, testInfo) => {\n // Screen selection chooses which flows run, so it applies in every mode.\n applyScreenSelection(testInfo);\n await use();\n },\n { auto: true },\n ],\n _ralphRecorder: [\n // _ralphScreen is specified here so that the playwright treat that it is\n // a dependency of this fixture.\n async (\n { ralphOptions, _ralphConfigs, _ralphScreen, playwright },\n use,\n testInfo,\n ) => {\n const mode = resolveMode(ralphOptions);\n if (!testInfo.tags.includes('@ralph') || mode === 'off') {\n await use(null);\n return;\n }\n\n // A sharded run's blob reports are merged, and uploaded by the Ralph\n // reporter, in `playwright merge-reports`.\n const reported =\n process.env[REPORTER_ENV] ||\n testInfo.config.reporter.some(([name]) => name === 'blob');\n if (mode === 'upload' && !reported) {\n throw new Error(\n \"Ralph uploads one merged graph per run from its reporter. Add ['@ralphralphai/playwright/reporter'] to `reporter` in playwright.config, or use the blob reporter and merge-reports when sharding.\",\n );\n }\n\n const root = testInfo.config.configFile\n ? path.dirname(testInfo.config.configFile)\n : process.cwd();\n\n const key = JSON.stringify({\n root,\n config: ralphOptions.config,\n configPath: ralphOptions.configPath,\n });\n\n let pending = _ralphConfigs.get(key);\n if (!pending) {\n pending = loadConfig(ralphOptions, root);\n _ralphConfigs.set(key, pending);\n }\n\n const recorder = new Recorder(\n ralphOptions,\n await pending,\n testInfo,\n mode,\n playwright,\n );\n\n try {\n await use(recorder);\n } finally {\n await recorder.finish();\n }\n },\n { auto: true, timeout: 30_000 },\n ],\n ralph: async ({ _ralphRecorder, ralphOptions }, use) => {\n const checkOptIn = () => {\n if (\n resolveMode(ralphOptions) !== 'off' &&\n !ralphOptions.ignoreUntaggedCalls\n ) {\n throw new Error('Opt this test into Ralph with the @ralph tag.');\n }\n };\n\n await use(\n _ralphRecorder ?? {\n recordNode: async () => {\n checkOptIn();\n },\n setNodeConditions: async () => {\n checkOptIn();\n return async () => {};\n },\n waitForCapture: async () => {},\n visitAllLinks: (links, options) =>\n visitAllLinks(links, async () => {}, options),\n pause: () => {},\n resume: () => {},\n observe: () => {\n checkOptIn();\n },\n },\n );\n },\n // On the context rather than per page, so popups start out reduced too.\n contextOptions: async ({ contextOptions, ralphOptions }, use, testInfo) => {\n const recording =\n testInfo.tags.includes('@ralph') && resolveMode(ralphOptions) !== 'off';\n await use(\n recording && ralphOptions.reduceMotion\n ? { ...contextOptions, reducedMotion: 'reduce' }\n : contextOptions,\n );\n },\n context: async ({ context, _ralphRecorder }, use) => {\n _ralphRecorder?.observe(context);\n try {\n await use(context);\n } finally {\n // The base context fixture closes its pages next; pending recordings still need them alive.\n await _ralphRecorder?.stopContext(context);\n }\n },\n});\n"],"mappings":";;;;AAgBA,MAAa,oBAAoB;AAYjC,SAAgB,YAAY,MAA0B;CACpD,OAAO,KAAK,QAAQ,MAAM,KAAK;AACjC;;;;;AAMA,SAAgB,cACd,OAAqB,CAAC,GACtB,UAA+B,CAAC,GAChB;CAChB,MAAM,EAAE,gBAAgB,eACtB,SACA,QAAQ,QAAQ,QAAQ,IAAI,CAC9B,CAAC,CAAC;CACF,IAAI,CAAC,YAAY,QACf,MAAM,IAAI,MAAM,2CAA2C;CAE7D,OAAO,YAAY,KAAK,eAAe;EACrC,MAAM,QAAQ,YAAY,UAAU;EACpC,MAAM,QAAwB;GAAE;GAAY;EAAY;EACxD,OAAO;GACL,GAAG;GACH,MAAM,KAAK,OAAO,KAAK,OAAO,MAAM,QAAQ;GAC5C,KAAK;IACH,GAAG,KAAK;IACR,UAAU;KAAE,OAAO,WAAW;KAAO,QAAQ,WAAW;IAAO;G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,OAAO;EAC/B,IAAI;GACF,MAAM,IAAI,OAAO;EACnB,UAAU;GAER,MAAM,gBAAgB,YAAY,OAAO;EAC3C;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["base"],"sources":["../src/screens.ts","../src/index.ts"],"sourcesContent":["import type {\n PlaywrightTestOptions,\n PlaywrightWorkerOptions,\n Project,\n TestInfo,\n} from '@playwright/test';\nimport type { ScreenSize } from '@ralphralphai/config';\n\nimport { loadConfigSync } from './config';\nimport type { RalphOptions } from './types';\n\ntype RalphProject = Project<\n PlaywrightTestOptions & { ralphOptions: RalphOptions },\n PlaywrightWorkerOptions\n>;\n\nexport const SCREEN_TAG_PREFIX = '@ralph-screen:';\n\nexport type RalphProjectOptions = Pick<\n RalphOptions,\n 'config' | 'configPath'\n> & {\n /** Resolves a relative `configPath`; defaults to the current directory. */\n root?: string;\n};\n\ntype ScreenMetadata = { screenSize: ScreenSize; screenSizes: ScreenSize[] };\n\nexport function screenLabel(size: ScreenSize): string {\n return size.width + 'x' + size.height;\n}\n\n/**\n * Expands `base` into one project per `screenSizes` entry of the Ralph config.\n * Each project's viewport is that screen size.\n */\nexport function ralphProjects(\n base: RalphProject = {},\n options: RalphProjectOptions = {},\n): RalphProject[] {\n const { screenSizes } = loadConfigSync(\n options,\n options.root ?? process.cwd(),\n ).config;\n if (!screenSizes.length) {\n throw new Error('The Ralph config declares no screenSizes.');\n }\n return screenSizes.map((screenSize) => {\n const label = screenLabel(screenSize);\n const ralph: ScreenMetadata = { screenSize, screenSizes };\n return {\n ...base,\n name: base.name ? base.name + ' ' + label : label,\n use: {\n ...base.use,\n viewport: { width: screenSize.width, height: screenSize.height },\n },\n metadata: { ...base.metadata, ralph },\n };\n });\n}\n\n/**\n * Skips a test whose `@ralph-screen:WxH` tags exclude the current project's\n * screen size. Untagged tests run at every size; other projects are untouched.\n */\nexport function applyScreenSelection(testInfo: TestInfo): void {\n const selected = testInfo.tags\n .filter((tag) => tag.startsWith(SCREEN_TAG_PREFIX))\n .map((tag) => tag.slice(SCREEN_TAG_PREFIX.length));\n const metadata = (testInfo.project.metadata as { ralph?: ScreenMetadata })\n .ralph;\n if (!selected.length || !metadata) {\n return;\n }\n const known = metadata.screenSizes.map(screenLabel);\n const unknown = selected.filter((label) => !known.includes(label));\n if (unknown.length) {\n throw new Error(\n 'Unknown Ralph screen size ' +\n unknown.join(', ') +\n '; the config declares ' +\n known.join(', ') +\n '.',\n );\n }\n const current = screenLabel(metadata.screenSize);\n testInfo.skip(\n !selected.includes(current),\n 'Not selected for Ralph screen size ' + current + '.',\n );\n}\n","import path from 'node:path';\n\nimport { test as base } from '@playwright/test';\nimport type {\n PlaywrightTestArgs,\n PlaywrightTestOptions,\n PlaywrightWorkerArgs,\n PlaywrightWorkerOptions,\n TestType,\n} from '@playwright/test';\n\nimport { loadConfig, resolveMode } from './config';\nimport { Recorder, REPORTER_ENV } from './recorder';\nimport { applyScreenSelection } from './screens';\nimport type { ConfigSnapshot, Ralph, RalphOptions } from './types';\nimport { visitAllLinks } from './visit_links';\n\nexport { expect, mergeTests } from '@playwright/test';\nexport type { WebRalphConfig } from '@ralphralphai/config';\nexport {\n createRawGraphBundle,\n prepareArtifactUpload,\n uploadRawGraph,\n} from './upload';\nexport type {\n PreparedUpload,\n UploadOptions,\n UploadReceipt,\n RawGraphScreenshot,\n RawGraphBundleIndex,\n} from './upload';\nexport { MANIFEST_ATTACHMENT } from './recorder';\nexport { ralphProjects, SCREEN_TAG_PREFIX } from './screens';\nexport type { RalphProjectOptions } from './screens';\nexport type { RalphReporterOptions } from './reporter';\nexport type {\n RawGraphManifest,\n RawGraph,\n RawGraphFile,\n RawPage,\n RawNode,\n RawAction,\n ActionKind,\n ActionTarget,\n ConditionsDeclaration,\n NodeConditions,\n RecordedTags,\n RecordNodeOptions,\n TagConditions,\n TagDeclaration,\n TagValue,\n ConfigSnapshot,\n PageLayout,\n Ralph,\n RalphOptions,\n TrackedElement,\n VisitAllLinksOptions,\n} from './types';\n\nexport type RalphFixtures = { ralph: Ralph; ralphOptions: RalphOptions };\n\ntype InternalFixtures = {\n _ralphScreen: void;\n _ralphRecorder: Recorder | null;\n};\ntype WorkerFixtures = { _ralphConfigs: Map<string, Promise<ConfigSnapshot>> };\n\nexport const test: TestType<\n PlaywrightTestArgs & PlaywrightTestOptions & RalphFixtures,\n PlaywrightWorkerArgs & PlaywrightWorkerOptions\n> = base.extend<RalphFixtures & InternalFixtures, WorkerFixtures>({\n ralphOptions: [{}, { option: true }],\n _ralphConfigs: [\n // Playwright requires destructuring here to discover fixture dependencies.\n // oxlint-disable-next-line no-empty-pattern\n async ({}, use) => {\n await use(new Map());\n },\n { scope: 'worker' },\n ],\n _ralphScreen: [\n // Playwright requires destructuring here to discover fixture dependencies.\n // oxlint-disable-next-line no-empty-pattern\n async ({}, use, testInfo) => {\n // Screen selection chooses which flows run, so it applies in every mode.\n applyScreenSelection(testInfo);\n await use();\n },\n { auto: true },\n ],\n _ralphRecorder: [\n // _ralphScreen is specified here so that the playwright treat that it is\n // a dependency of this fixture.\n async (\n { ralphOptions, _ralphConfigs, _ralphScreen, playwright },\n use,\n testInfo,\n ) => {\n const mode = resolveMode(ralphOptions);\n if (!testInfo.tags.includes('@ralph') || mode === 'off') {\n await use(null);\n return;\n }\n\n // A sharded run's blob reports are merged, and uploaded by the Ralph\n // reporter, in `playwright merge-reports`.\n const reported =\n process.env[REPORTER_ENV] ||\n testInfo.config.reporter.some(([name]) => name === 'blob');\n if (mode === 'upload' && !reported) {\n throw new Error(\n \"Ralph uploads one merged graph per run from its reporter. Add ['@ralphralphai/playwright/reporter'] to `reporter` in playwright.config, or use the blob reporter and merge-reports when sharding.\",\n );\n }\n\n const root = testInfo.config.configFile\n ? path.dirname(testInfo.config.configFile)\n : process.cwd();\n\n const key = JSON.stringify({\n root,\n config: ralphOptions.config,\n configPath: ralphOptions.configPath,\n });\n\n let pending = _ralphConfigs.get(key);\n if (!pending) {\n pending = loadConfig(ralphOptions, root);\n _ralphConfigs.set(key, pending);\n }\n\n const recorder = new Recorder(\n ralphOptions,\n await pending,\n testInfo,\n mode,\n playwright,\n );\n\n try {\n await use(recorder);\n } finally {\n await recorder.finish();\n }\n },\n { auto: true, timeout: 30_000 },\n ],\n ralph: async ({ _ralphRecorder, ralphOptions }, use) => {\n const checkOptIn = () => {\n if (\n resolveMode(ralphOptions) !== 'off' &&\n !ralphOptions.ignoreUntaggedCalls\n ) {\n throw new Error('Opt this test into Ralph with the @ralph tag.');\n }\n };\n\n await use(\n _ralphRecorder ?? {\n recordNode: async () => {\n checkOptIn();\n },\n setNodeConditions: async () => {\n checkOptIn();\n return async () => {};\n },\n waitForCapture: async () => {},\n visitAllLinks: (links, options) =>\n visitAllLinks(links, async () => {}, options),\n pause: () => {},\n resume: () => {},\n observe: async () => {\n checkOptIn();\n },\n },\n );\n },\n // On the context rather than per page, so popups start out reduced too.\n contextOptions: async ({ contextOptions, ralphOptions }, use, testInfo) => {\n const recording =\n testInfo.tags.includes('@ralph') && resolveMode(ralphOptions) !== 'off';\n await use(\n recording && ralphOptions.reduceMotion\n ? { ...contextOptions, reducedMotion: 'reduce' }\n : contextOptions,\n );\n },\n context: async ({ context, _ralphRecorder }, use) => {\n await _ralphRecorder?.observe(context);\n try {\n await use(context);\n } finally {\n // The base context fixture closes its pages next; pending recordings still need them alive.\n await _ralphRecorder?.stopContext(context);\n }\n },\n});\n"],"mappings":";;;;AAgBA,MAAa,oBAAoB;AAYjC,SAAgB,YAAY,MAA0B;CACpD,OAAO,KAAK,QAAQ,MAAM,KAAK;AACjC;;;;;AAMA,SAAgB,cACd,OAAqB,CAAC,GACtB,UAA+B,CAAC,GAChB;CAChB,MAAM,EAAE,gBAAgB,eACtB,SACA,QAAQ,QAAQ,QAAQ,IAAI,CAC9B,CAAC,CAAC;CACF,IAAI,CAAC,YAAY,QACf,MAAM,IAAI,MAAM,2CAA2C;CAE7D,OAAO,YAAY,KAAK,eAAe;EACrC,MAAM,QAAQ,YAAY,U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,aAAa;EAGzE,MAAM,IADJ,SAAS,KAAK,SAAS,QAAQ,KAAK,YAAY,YAAY,MAAM,SAErD,aAAa,eACtB;GAAE,GAAG;GAAgB,eAAe;EAAS,IAC7C,cACN;CACF;CACA,SAAS,OAAO,EAAE,SAAS,kBAAkB,QAAQ;EACnD,MAAM,gBAAgB,QAAQ,OAAO;EACrC,IAAI;GACF,MAAM,IAAI,OAAO;EACnB,UAAU;GAER,MAAM,gBAAgB,YAAY,OAAO;EAC3C;CACF;AACF,CAAC"}
|
package/dist/reporter.cjs
CHANGED
package/dist/reporter.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as resolveMode, a as prepareArtifactUpload, c as resultLink, d as REPORTER_ENV, l as uploadRawGraph, m as version, n as bundleImagePath, o as registerDeployment, r as bundleSnapshotPath, s as resolveUploadOptions, t as RAW_GRAPH_BUNDLE_INDEX, u as MANIFEST_ATTACHMENT } from "./upload-
|
|
1
|
+
import { _ as resolveMode, a as prepareArtifactUpload, c as resultLink, d as REPORTER_ENV, l as uploadRawGraph, m as version, n as bundleImagePath, o as registerDeployment, r as bundleSnapshotPath, s as resolveUploadOptions, t as RAW_GRAPH_BUNDLE_INDEX, u as MANIFEST_ATTACHMENT } from "./upload-jup_jLlm.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
@@ -70,7 +70,7 @@ function snapshot(value) {
|
|
|
70
70
|
}
|
|
71
71
|
//#endregion
|
|
72
72
|
//#region package.json
|
|
73
|
-
var version = "2.
|
|
73
|
+
var version = "2.5.0";
|
|
74
74
|
//#endregion
|
|
75
75
|
//#region src/actions.ts
|
|
76
76
|
const BINDING = "__ralphAction";
|
|
@@ -728,6 +728,8 @@ function keepShown(node, viewportWidth) {
|
|
|
728
728
|
return kept === void 0 ? [] : [kept];
|
|
729
729
|
});
|
|
730
730
|
if (!shown && children.length === 0) return;
|
|
731
|
+
const [only] = children;
|
|
732
|
+
if (node.role === "generic" && !node.name && (node.children?.length ?? 0) > 1 && children.length === 1 && typeof only !== "string" && only?.ref !== void 0) return only;
|
|
731
733
|
return node.children === void 0 ? node : {
|
|
732
734
|
...node,
|
|
733
735
|
children
|
|
@@ -825,6 +827,179 @@ async function describe(page, child, inherited, insideDynamic) {
|
|
|
825
827
|
};
|
|
826
828
|
}
|
|
827
829
|
//#endregion
|
|
830
|
+
//#region src/animation_observer.ts
|
|
831
|
+
/** Runs in the page. Keeps native animations and DOM changes observable without app hooks. */
|
|
832
|
+
function observeAnimations() {
|
|
833
|
+
const paused = /* @__PURE__ */ new Set();
|
|
834
|
+
const roots = /* @__PURE__ */ new Set();
|
|
835
|
+
let dirty = true;
|
|
836
|
+
const observer = new MutationObserver(() => {
|
|
837
|
+
dirty = true;
|
|
838
|
+
});
|
|
839
|
+
const collect = (root, all) => {
|
|
840
|
+
if (!roots.has(root)) {
|
|
841
|
+
roots.add(root);
|
|
842
|
+
observer.observe(root, {
|
|
843
|
+
subtree: true,
|
|
844
|
+
childList: true,
|
|
845
|
+
attributes: true,
|
|
846
|
+
characterData: true
|
|
847
|
+
});
|
|
848
|
+
dirty = true;
|
|
849
|
+
}
|
|
850
|
+
root.getAnimations().forEach((animation) => all.add(animation));
|
|
851
|
+
for (const element of root.querySelectorAll("*")) if (element.shadowRoot) collect(element.shadowRoot, all);
|
|
852
|
+
};
|
|
853
|
+
return {
|
|
854
|
+
sample(finishFinite) {
|
|
855
|
+
const all = /* @__PURE__ */ new Set();
|
|
856
|
+
collect(document, all);
|
|
857
|
+
let changed = dirty;
|
|
858
|
+
dirty = false;
|
|
859
|
+
for (const animation of all) {
|
|
860
|
+
if (animation.playState !== "running") continue;
|
|
861
|
+
if (finishFinite && animation.playbackRate !== 0 && Number.isFinite(animation.effect?.getComputedTiming().endTime)) animation.finish();
|
|
862
|
+
else {
|
|
863
|
+
animation.pause();
|
|
864
|
+
paused.add(animation);
|
|
865
|
+
}
|
|
866
|
+
changed = true;
|
|
867
|
+
}
|
|
868
|
+
return changed;
|
|
869
|
+
},
|
|
870
|
+
async ready() {
|
|
871
|
+
await Promise.all([...paused].map((animation) => animation.ready));
|
|
872
|
+
},
|
|
873
|
+
resume() {
|
|
874
|
+
observer.disconnect();
|
|
875
|
+
for (const animation of paused) if (animation.playState === "paused") animation.play();
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
//#endregion
|
|
880
|
+
//#region src/capture_freezer.ts
|
|
881
|
+
const PAUSE_LEAD_MS = 100;
|
|
882
|
+
const ANIMATION_QUIET_MS = 150;
|
|
883
|
+
const MAX_ANIMATION_SETTLE_MS = 1500;
|
|
884
|
+
/** One owner of the context-wide clock; captures in different tabs queue here. */
|
|
885
|
+
var CaptureFreezer = class {
|
|
886
|
+
context;
|
|
887
|
+
tail = Promise.resolve();
|
|
888
|
+
closed = false;
|
|
889
|
+
constructor(context) {
|
|
890
|
+
this.context = context;
|
|
891
|
+
context.once("close", () => {
|
|
892
|
+
this.closed = true;
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
install() {
|
|
896
|
+
if (this.context.pages().some((page) => page.url() !== "about:blank")) throw new Error("Ralph freezeDuringCapture requires the clock before page scripts run. Await ralph.observe(context) before creating or navigating pages in a custom context.");
|
|
897
|
+
return this.context.clock.install();
|
|
898
|
+
}
|
|
899
|
+
async capture(page, signal, capture, deadline = Date.now() + 5e3) {
|
|
900
|
+
const task = this.tail.then(async () => {
|
|
901
|
+
signal.throwIfAborted();
|
|
902
|
+
const animations = /* @__PURE__ */ new Map();
|
|
903
|
+
try {
|
|
904
|
+
await this.settleAnimations(page, animations, signal, deadline);
|
|
905
|
+
await this.pauseClock(page, signal);
|
|
906
|
+
signal.throwIfAborted();
|
|
907
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
908
|
+
await this.sampleAnimations(page, animations, signal, false);
|
|
909
|
+
await this.waitForAnimationsReady(animations, signal);
|
|
910
|
+
}
|
|
911
|
+
return await capture();
|
|
912
|
+
} finally {
|
|
913
|
+
try {
|
|
914
|
+
await this.resumeAnimations(animations);
|
|
915
|
+
} finally {
|
|
916
|
+
if (!this.closed) await this.context.clock.resume();
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
this.tail = task.catch(() => void 0);
|
|
921
|
+
return task;
|
|
922
|
+
}
|
|
923
|
+
async settleAnimations(page, animations, signal, deadline) {
|
|
924
|
+
const now = Date.now();
|
|
925
|
+
const endsAt = now + Math.min(MAX_ANIMATION_SETTLE_MS, Math.max(0, (deadline - now) / 2));
|
|
926
|
+
let quietSince = now;
|
|
927
|
+
while (Date.now() < endsAt) {
|
|
928
|
+
if (await this.sampleAnimations(page, animations, signal, true)) quietSince = Date.now();
|
|
929
|
+
if (Date.now() - quietSince >= ANIMATION_QUIET_MS) return;
|
|
930
|
+
await (0, node_timers_promises.setTimeout)(Math.max(0, Math.min(50, endsAt - Date.now())), void 0, { signal }).catch((error) => {
|
|
931
|
+
signal.throwIfAborted();
|
|
932
|
+
throw error;
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
async sampleAnimations(page, animations, signal, finishFinite) {
|
|
937
|
+
let changed = false;
|
|
938
|
+
for (const frame of page.frames()) {
|
|
939
|
+
signal.throwIfAborted();
|
|
940
|
+
try {
|
|
941
|
+
let handle = animations.get(frame);
|
|
942
|
+
if (!handle) {
|
|
943
|
+
handle = await frame.evaluateHandle(observeAnimations);
|
|
944
|
+
animations.set(frame, handle);
|
|
945
|
+
}
|
|
946
|
+
changed = await handle.evaluate((state, finish) => state.sample(finish), finishFinite) || changed;
|
|
947
|
+
} catch (error) {
|
|
948
|
+
if (!frame.isDetached()) throw error;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
signal.throwIfAborted();
|
|
952
|
+
return changed;
|
|
953
|
+
}
|
|
954
|
+
async waitForAnimationsReady(animations, signal) {
|
|
955
|
+
signal.throwIfAborted();
|
|
956
|
+
let onAbort;
|
|
957
|
+
const aborted = new Promise((_, reject) => {
|
|
958
|
+
onAbort = () => reject(signal.reason);
|
|
959
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
960
|
+
});
|
|
961
|
+
try {
|
|
962
|
+
await Promise.race([Promise.all([...animations].map(async ([frame, handle]) => {
|
|
963
|
+
if (frame.isDetached()) return;
|
|
964
|
+
try {
|
|
965
|
+
await handle.evaluate((state) => state.ready());
|
|
966
|
+
} catch (error) {
|
|
967
|
+
if (!frame.isDetached()) throw error;
|
|
968
|
+
}
|
|
969
|
+
})), aborted]);
|
|
970
|
+
} finally {
|
|
971
|
+
signal.removeEventListener("abort", onAbort);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
async resumeAnimations(animations) {
|
|
975
|
+
const restored = await Promise.allSettled([...animations.values()].map(async (handle) => {
|
|
976
|
+
try {
|
|
977
|
+
await handle.evaluate((state) => state.resume());
|
|
978
|
+
} catch (error) {
|
|
979
|
+
if (!destroyedContext(error)) throw error;
|
|
980
|
+
} finally {
|
|
981
|
+
await handle.dispose();
|
|
982
|
+
}
|
|
983
|
+
}));
|
|
984
|
+
for (const result of restored) if (result.status === "rejected") throw result.reason;
|
|
985
|
+
}
|
|
986
|
+
async pauseClock(page, signal) {
|
|
987
|
+
for (let attempt = 0;; attempt++) {
|
|
988
|
+
const time = await page.evaluate(() => Date.now());
|
|
989
|
+
signal.throwIfAborted();
|
|
990
|
+
try {
|
|
991
|
+
await this.context.clock.pauseAt(time + PAUSE_LEAD_MS);
|
|
992
|
+
return;
|
|
993
|
+
} catch (error) {
|
|
994
|
+
if (attempt > 0 || !(error instanceof Error) || !error.message.includes("Cannot fast-forward to the past")) throw error;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
function destroyedContext(error) {
|
|
1000
|
+
return error instanceof Error && /Execution context was destroyed|Cannot find context|Target page, context or browser has been closed|Frame was detached/.test(error.message);
|
|
1001
|
+
}
|
|
1002
|
+
//#endregion
|
|
828
1003
|
//#region src/conditions.ts
|
|
829
1004
|
const declared = (declaration = {}) => {
|
|
830
1005
|
const conditions = {};
|
|
@@ -886,11 +1061,11 @@ function nodeKey(conditions) {
|
|
|
886
1061
|
*/
|
|
887
1062
|
const WEBP_QUALITY = 80;
|
|
888
1063
|
const WEBP_MAX_DIMENSION = 16383;
|
|
889
|
-
async function takeScreenshot(page, deadline) {
|
|
1064
|
+
async function takeScreenshot(page, deadline, frozen = false) {
|
|
890
1065
|
const options = {
|
|
891
1066
|
fullPage: true,
|
|
892
1067
|
scale: "css",
|
|
893
|
-
animations: "disabled"
|
|
1068
|
+
animations: frozen ? "allow" : "disabled"
|
|
894
1069
|
};
|
|
895
1070
|
const webp = await page.screenshot({
|
|
896
1071
|
...options,
|
|
@@ -1119,22 +1294,30 @@ var Recorder = class {
|
|
|
1119
1294
|
/** Starts recording URL changes in every current and future tab of `context`. */
|
|
1120
1295
|
observe(context) {
|
|
1121
1296
|
if (this.closed) throw new Error("The Ralph recorder has finished.");
|
|
1122
|
-
|
|
1297
|
+
const existing = this.contexts.get(context);
|
|
1298
|
+
if (existing) return existing.ready;
|
|
1299
|
+
const freezer = this.options.freezeDuringCapture ? new CaptureFreezer(context) : void 0;
|
|
1300
|
+
const ready = freezer?.install() ?? Promise.resolve();
|
|
1123
1301
|
const onPage = (page) => this.watchPage(page);
|
|
1124
|
-
this.contexts.set(context,
|
|
1302
|
+
this.contexts.set(context, {
|
|
1303
|
+
onPage,
|
|
1304
|
+
ready,
|
|
1305
|
+
freezer
|
|
1306
|
+
});
|
|
1125
1307
|
this.actions.observe(context);
|
|
1126
1308
|
context.on("page", onPage);
|
|
1127
1309
|
for (const page of context.pages()) onPage(page);
|
|
1310
|
+
return ready;
|
|
1128
1311
|
}
|
|
1129
1312
|
async recordNode(page, options) {
|
|
1130
|
-
this.observe(page.context());
|
|
1313
|
+
await this.observe(page.context());
|
|
1131
1314
|
const state = this.pages.get(page);
|
|
1132
1315
|
if (!state) throw new Error("Cannot record a closed browser page.");
|
|
1133
1316
|
if (this.paused) return;
|
|
1134
1317
|
await this.enqueueCreateNodeRequest(state, "explicit", options);
|
|
1135
1318
|
}
|
|
1136
1319
|
async setNodeConditions(page, declaration) {
|
|
1137
|
-
this.observe(page.context());
|
|
1320
|
+
await this.observe(page.context());
|
|
1138
1321
|
const state = this.pages.get(page);
|
|
1139
1322
|
if (!state) throw new Error("Cannot tag a closed browser page.");
|
|
1140
1323
|
const key = Symbol();
|
|
@@ -1165,8 +1348,11 @@ var Recorder = class {
|
|
|
1165
1348
|
}
|
|
1166
1349
|
/** Stops watching `context` and waits for its queued recordings. */
|
|
1167
1350
|
async stopContext(context) {
|
|
1168
|
-
const
|
|
1169
|
-
if (
|
|
1351
|
+
const observed = this.contexts.get(context);
|
|
1352
|
+
if (observed) {
|
|
1353
|
+
context.off("page", observed.onPage);
|
|
1354
|
+
await observed.ready;
|
|
1355
|
+
}
|
|
1170
1356
|
const states = [...this.pages.values()].filter((state) => state.page.context() === context);
|
|
1171
1357
|
for (const state of states) state.page.off("framenavigated", state.onNavigation);
|
|
1172
1358
|
await Promise.all(states.map((state) => state.tail));
|
|
@@ -1282,6 +1468,7 @@ var Recorder = class {
|
|
|
1282
1468
|
};
|
|
1283
1469
|
try {
|
|
1284
1470
|
check();
|
|
1471
|
+
await wait(this.contexts.get(page.context()).ready);
|
|
1285
1472
|
if (request.trigger !== "explicit") await this.waitForPageToSettle(page, deadline, check);
|
|
1286
1473
|
check();
|
|
1287
1474
|
const conditions = this.declaredConditions(state);
|
|
@@ -1294,18 +1481,27 @@ var Recorder = class {
|
|
|
1294
1481
|
warnedNoTracker = true;
|
|
1295
1482
|
console.warn("Ralph: this page runs no tracker, so the node conditions the test declares cannot be checked against the tags the app reports. Production events must carry the same tags, or these nodes will match no visitors.");
|
|
1296
1483
|
}
|
|
1297
|
-
|
|
1484
|
+
const freezer = this.contexts.get(page.context()).freezer;
|
|
1485
|
+
if (this.options.reduceMotion && !freezer) {
|
|
1298
1486
|
check();
|
|
1299
1487
|
await wait(waitForAnimations(page, (deadline.endsAt - Date.now()) / 2));
|
|
1300
1488
|
}
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1489
|
+
const capture = async () => {
|
|
1490
|
+
check();
|
|
1491
|
+
const before = await wait(readLayout(page));
|
|
1492
|
+
check();
|
|
1493
|
+
const image = await wait(takeScreenshot(page, deadline.endsAt, !!freezer));
|
|
1494
|
+
check();
|
|
1495
|
+
const after = await wait(readLayout(page));
|
|
1496
|
+
check();
|
|
1497
|
+
return {
|
|
1498
|
+
before,
|
|
1499
|
+
image,
|
|
1500
|
+
after,
|
|
1501
|
+
snapshot: await Promise.race([captureAriaSnapshot(page, after).catch(() => void 0), (0, node_timers_promises.setTimeout)(Math.max(0, deadline.endsAt - Date.now()), void 0, { ref: false })])
|
|
1502
|
+
};
|
|
1503
|
+
};
|
|
1504
|
+
const { before, image, after, snapshot } = freezer ? await freezer.capture(page, deadline.signal, capture, deadline.endsAt) : await capture();
|
|
1309
1505
|
checkPage();
|
|
1310
1506
|
const recorded = {
|
|
1311
1507
|
...request,
|
|
@@ -1843,4 +2039,4 @@ Object.defineProperty(exports, "visitAllLinks", {
|
|
|
1843
2039
|
}
|
|
1844
2040
|
});
|
|
1845
2041
|
|
|
1846
|
-
//# sourceMappingURL=upload-
|
|
2042
|
+
//# sourceMappingURL=upload-D40MqSQa.cjs.map
|