@restormel/testing-browser-playwright 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Allotment Technology Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @restormel/testing-browser-playwright — Playwright-backed browser adapter for Restormel / Testing (MVP).
3
+ */
4
+ export declare const testingBrowserPlaywrightPackage: "@restormel/testing-browser-playwright";
5
+ export { createPlaywrightTestingSession, PlaywrightTestingSession } from "./playwright-session.js";
6
+ export { resolveLocator } from "./locator.js";
7
+ export { browserTracesToCoreEvents } from "./trace-bridge.js";
8
+ export type { BrowserConsoleLine, BrowserNetworkLine, BrowserSessionTraceEntry, PlaywrightTestingSessionOptions, TestingBrowserSession, TestingLocator, } from "./types.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,+BAA+B,EAAG,uCAAgD,CAAC;AAEhG,OAAO,EAAE,8BAA8B,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,+BAA+B,EAC/B,qBAAqB,EACrB,cAAc,GACf,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @restormel/testing-browser-playwright — Playwright-backed browser adapter for Restormel / Testing (MVP).
3
+ */
4
+ export const testingBrowserPlaywrightPackage = "@restormel/testing-browser-playwright";
5
+ export { createPlaywrightTestingSession, PlaywrightTestingSession } from "./playwright-session.js";
6
+ export { resolveLocator } from "./locator.js";
7
+ export { browserTracesToCoreEvents } from "./trace-bridge.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,uCAAgD,CAAC;AAEhG,OAAO,EAAE,8BAA8B,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Page } from "playwright";
2
+ import type { TestingLocator } from "./types.js";
3
+ export declare function resolveLocator(page: Page, loc: TestingLocator): import("playwright").Locator;
4
+ //# sourceMappingURL=locator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locator.d.ts","sourceRoot":"","sources":["../src/locator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,cAAc,gCAM7D"}
@@ -0,0 +1,8 @@
1
+ export function resolveLocator(page, loc) {
2
+ if (loc.kind === "css") {
3
+ return page.locator(loc.selector);
4
+ }
5
+ const { role, name } = loc;
6
+ return name === undefined ? page.getByRole(role) : page.getByRole(role, { name });
7
+ }
8
+ //# sourceMappingURL=locator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locator.js","sourceRoot":"","sources":["../src/locator.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,cAAc,CAAC,IAAU,EAAE,GAAmB;IAC5D,IAAI,GAAG,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAC3B,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACpF,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { ArtifactRef } from "@restormel/testing-core";
2
+ import { type Page } from "playwright";
3
+ import type { BrowserConsoleLine, BrowserNetworkLine, BrowserSessionTraceEntry, PlaywrightTestingSessionOptions, TestingBrowserSession, TestingLocator } from "./types.js";
4
+ export declare class PlaywrightTestingSession implements TestingBrowserSession {
5
+ readonly page: Page;
6
+ private readonly browser;
7
+ private readonly context;
8
+ private readonly defaultTimeoutMs;
9
+ private readonly consoleLines;
10
+ private readonly networkLines;
11
+ private readonly traceBuffer;
12
+ private disposed;
13
+ private constructor();
14
+ static create(options?: PlaywrightTestingSessionOptions): Promise<PlaywrightTestingSession>;
15
+ private pushTrace;
16
+ navigate(url: string, options?: {
17
+ timeoutMs?: number;
18
+ waitUntil?: "load" | "domcontentloaded" | "networkidle";
19
+ }): Promise<void>;
20
+ click(locator: TestingLocator, options?: {
21
+ timeoutMs?: number;
22
+ }): Promise<void>;
23
+ fill(locator: TestingLocator, value: string, options?: {
24
+ timeoutMs?: number;
25
+ }): Promise<void>;
26
+ waitForLoad(state?: "load" | "domcontentloaded" | "networkidle"): Promise<void>;
27
+ waitForVisible(locator: TestingLocator, options?: {
28
+ timeoutMs?: number;
29
+ }): Promise<void>;
30
+ getVisibleText(locator: TestingLocator): Promise<string>;
31
+ screenshot(path: string): Promise<ArtifactRef>;
32
+ getConsoleSnapshot(): readonly BrowserConsoleLine[];
33
+ getNetworkSnapshot(): readonly BrowserNetworkLine[];
34
+ drainTraceEntries(): BrowserSessionTraceEntry[];
35
+ dispose(): Promise<void>;
36
+ private assertAlive;
37
+ }
38
+ /**
39
+ * Launch Chromium and return a narrow testing session (one page).
40
+ */
41
+ export declare function createPlaywrightTestingSession(options?: PlaywrightTestingSessionOptions): Promise<TestingBrowserSession>;
42
+ //# sourceMappingURL=playwright-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-session.d.ts","sourceRoot":"","sources":["../src/playwright-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAA+C,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAEpF,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,+BAA+B,EAC/B,qBAAqB,EACrB,cAAc,EACf,MAAM,YAAY,CAAC;AAepB,qBAAa,wBAAyB,YAAW,qBAAqB;IACpE,QAAQ,CAAC,IAAI,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IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAOpD,kBAAkB,IAAI,SAAS,kBAAkB,EAAE;IAInD,kBAAkB,IAAI,SAAS,kBAAkB,EAAE;IAInD,iBAAiB,IAAI,wBAAwB,EAAE;IAMzC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAe9B,OAAO,CAAC,WAAW;CAKpB;AAUD;;GAEG;AACH,wBAAsB,8BAA8B,CAClD,OAAO,CAAC,EAAE,+BAA+B,GACxC,OAAO,CAAC,qBAAqB,CAAC,CAEhC"}
@@ -0,0 +1,175 @@
1
+ import { chromium } from "playwright";
2
+ import { resolveLocator } from "./locator.js";
3
+ const MAX_CONSOLE = 200;
4
+ const MAX_NETWORK = 120;
5
+ const MAX_TEXT_SNIPPET = 2000;
6
+ function nowIso() {
7
+ return new Date().toISOString();
8
+ }
9
+ function truncate(s, max) {
10
+ if (s.length <= max)
11
+ return s;
12
+ return `${s.slice(0, max)}…`;
13
+ }
14
+ export class PlaywrightTestingSession {
15
+ page;
16
+ browser;
17
+ context;
18
+ defaultTimeoutMs;
19
+ consoleLines = [];
20
+ networkLines = [];
21
+ traceBuffer = [];
22
+ disposed = false;
23
+ constructor(browser, context, page, defaultTimeoutMs) {
24
+ this.browser = browser;
25
+ this.context = context;
26
+ this.page = page;
27
+ this.defaultTimeoutMs = defaultTimeoutMs;
28
+ }
29
+ static async create(options = {}) {
30
+ const defaultTimeoutMs = options.timeoutMs ?? 30_000;
31
+ const browser = await chromium.launch({
32
+ headless: options.headless ?? true,
33
+ });
34
+ const context = await browser.newContext({
35
+ viewport: options.viewport ?? { width: 1280, height: 720 },
36
+ ...(options.storageState !== undefined && options.storageState.length > 0
37
+ ? { storageState: options.storageState }
38
+ : {}),
39
+ });
40
+ const page = await context.newPage();
41
+ page.setDefaultTimeout(defaultTimeoutMs);
42
+ page.setDefaultNavigationTimeout(defaultTimeoutMs);
43
+ const session = new PlaywrightTestingSession(browser, context, page, defaultTimeoutMs);
44
+ page.on("console", (msg) => {
45
+ if (session.consoleLines.length >= MAX_CONSOLE) {
46
+ session.consoleLines.shift();
47
+ }
48
+ session.consoleLines.push({
49
+ type: msg.type(),
50
+ text: truncate(msg.text(), MAX_TEXT_SNIPPET),
51
+ });
52
+ });
53
+ page.on("requestfinished", async (req) => {
54
+ if (session.networkLines.length >= MAX_NETWORK) {
55
+ session.networkLines.shift();
56
+ }
57
+ let status = 0;
58
+ try {
59
+ const res = await req.response();
60
+ status = res?.status() ?? 0;
61
+ }
62
+ catch {
63
+ status = 0;
64
+ }
65
+ session.networkLines.push({
66
+ url: truncate(req.url(), 500),
67
+ method: req.method(),
68
+ status,
69
+ });
70
+ });
71
+ return session;
72
+ }
73
+ pushTrace(kind, summary, metadata) {
74
+ this.traceBuffer.push({
75
+ timestamp: nowIso(),
76
+ kind,
77
+ summary,
78
+ metadata,
79
+ });
80
+ }
81
+ async navigate(url, options) {
82
+ this.assertAlive();
83
+ const waitUntil = options?.waitUntil ?? "load";
84
+ await this.page.goto(url, {
85
+ timeout: options?.timeoutMs ?? this.defaultTimeoutMs,
86
+ waitUntil,
87
+ });
88
+ this.pushTrace("navigation", `navigate ${truncate(url, 300)}`, { waitUntil });
89
+ }
90
+ async click(locator, options) {
91
+ this.assertAlive();
92
+ const loc = resolveLocator(this.page, locator);
93
+ const desc = locatorSummary(locator);
94
+ await loc.click({ timeout: options?.timeoutMs ?? this.defaultTimeoutMs });
95
+ this.pushTrace("action", `click ${desc}`);
96
+ }
97
+ async fill(locator, value, options) {
98
+ this.assertAlive();
99
+ const loc = resolveLocator(this.page, locator);
100
+ const desc = locatorSummary(locator);
101
+ await loc.fill(value, { timeout: options?.timeoutMs ?? this.defaultTimeoutMs });
102
+ this.pushTrace("action", `fill ${desc}`, { valueLength: value.length });
103
+ }
104
+ async waitForLoad(state = "load") {
105
+ this.assertAlive();
106
+ await this.page.waitForLoadState(state);
107
+ this.pushTrace("action", `waitForLoadState ${state}`);
108
+ }
109
+ async waitForVisible(locator, options) {
110
+ this.assertAlive();
111
+ const loc = resolveLocator(this.page, locator);
112
+ await loc.waitFor({ state: "visible", timeout: options?.timeoutMs ?? this.defaultTimeoutMs });
113
+ this.pushTrace("action", `wait visible ${locatorSummary(locator)}`);
114
+ }
115
+ async getVisibleText(locator) {
116
+ this.assertAlive();
117
+ const loc = resolveLocator(this.page, locator);
118
+ const text = await loc.innerText();
119
+ this.pushTrace("observation", `text ${locatorSummary(locator)}`, { length: text.length });
120
+ return text;
121
+ }
122
+ async screenshot(path) {
123
+ this.assertAlive();
124
+ await this.page.screenshot({ path, type: "png", fullPage: false });
125
+ this.pushTrace("observation", `screenshot ${path}`, { path });
126
+ return { kind: "screenshot", path, mimeType: "image/png" };
127
+ }
128
+ getConsoleSnapshot() {
129
+ return [...this.consoleLines];
130
+ }
131
+ getNetworkSnapshot() {
132
+ return [...this.networkLines];
133
+ }
134
+ drainTraceEntries() {
135
+ const out = [...this.traceBuffer];
136
+ this.traceBuffer.length = 0;
137
+ return out;
138
+ }
139
+ async dispose() {
140
+ if (this.disposed)
141
+ return;
142
+ this.disposed = true;
143
+ try {
144
+ await this.context.close();
145
+ }
146
+ catch {
147
+ /* ignore */
148
+ }
149
+ try {
150
+ await this.browser.close();
151
+ }
152
+ catch {
153
+ /* ignore */
154
+ }
155
+ }
156
+ assertAlive() {
157
+ if (this.disposed) {
158
+ throw new Error("PlaywrightTestingSession is disposed");
159
+ }
160
+ }
161
+ }
162
+ function locatorSummary(loc) {
163
+ if (loc.kind === "css") {
164
+ return `css:${truncate(loc.selector, 120)}`;
165
+ }
166
+ const name = loc.name === undefined ? "" : typeof loc.name === "string" ? ` "${truncate(loc.name, 80)}"` : " /RegExp/";
167
+ return `role:${loc.role}${name}`;
168
+ }
169
+ /**
170
+ * Launch Chromium and return a narrow testing session (one page).
171
+ */
172
+ export async function createPlaywrightTestingSession(options) {
173
+ return PlaywrightTestingSession.create(options);
174
+ }
175
+ //# sourceMappingURL=playwright-session.js.map
@@ -0,0 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O,wBAAwB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { TraceEvent } from "@restormel/testing-core";
2
+ import type { BrowserSessionTraceEntry } from "./types.js";
3
+ /** Map browser adapter trace lines into core `TraceEvent` records for run reports. */
4
+ export declare function browserTracesToCoreEvents(entries: readonly BrowserSessionTraceEntry[], ctx: {
5
+ runId: string;
6
+ goalId: string;
7
+ startingStepIndex: number;
8
+ }): TraceEvent[];
9
+ //# sourceMappingURL=trace-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-bridge.d.ts","sourceRoot":"","sources":["../src/trace-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D,sFAAsF;AACtF,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,SAAS,wBAAwB,EAAE,EAC5C,GAAG,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,GAChE,UAAU,EAAE,CAWd"}
@@ -0,0 +1,15 @@
1
+ import { randomUUID } from "node:crypto";
2
+ /** Map browser adapter trace lines into core `TraceEvent` records for run reports. */
3
+ export function browserTracesToCoreEvents(entries, ctx) {
4
+ return entries.map((e, i) => ({
5
+ id: randomUUID(),
6
+ runId: ctx.runId,
7
+ goalId: ctx.goalId,
8
+ stepIndex: ctx.startingStepIndex + i,
9
+ kind: e.kind,
10
+ timestamp: e.timestamp,
11
+ summary: e.summary,
12
+ metadata: e.metadata,
13
+ }));
14
+ }
15
+ //# sourceMappingURL=trace-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-bridge.js","sourceRoot":"","sources":["../src/trace-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,sFAAsF;AACtF,MAAM,UAAU,yBAAyB,CACvC,OAA4C,EAC5C,GAAiE;IAEjE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5B,EAAE,EAAE,UAAU,EAAE;QAChB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,SAAS,EAAE,GAAG,CAAC,iBAAiB,GAAG,CAAC;QACpC,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;KACrB,CAAC,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,74 @@
1
+ import type { ArtifactRef, TraceEventKind } from "@restormel/testing-core";
2
+ /**
3
+ * Narrow locators for deterministic tests — not a general Playwright selector DSL.
4
+ */
5
+ export type TestingLocator = {
6
+ kind: "css";
7
+ selector: string;
8
+ } | {
9
+ kind: "role";
10
+ role: "button" | "link" | "textbox" | "heading" | "main" | "navigation" | "checkbox" | "radio";
11
+ name?: string | RegExp;
12
+ };
13
+ export interface BrowserConsoleLine {
14
+ type: string;
15
+ text: string;
16
+ }
17
+ export interface BrowserNetworkLine {
18
+ url: string;
19
+ method: string;
20
+ status: number;
21
+ }
22
+ /**
23
+ * Action-level trace lines for the runner to merge into {@link TraceEvent} (ids/runId/goalId/stepIndex added upstream).
24
+ */
25
+ export interface BrowserSessionTraceEntry {
26
+ timestamp: string;
27
+ kind: TraceEventKind;
28
+ summary: string;
29
+ metadata?: Record<string, unknown>;
30
+ }
31
+ export interface PlaywrightTestingSessionOptions {
32
+ headless?: boolean;
33
+ /** Default navigation / action timeout (ms). */
34
+ timeoutMs?: number;
35
+ viewport?: {
36
+ width: number;
37
+ height: number;
38
+ };
39
+ /** Path to Playwright `storageState` JSON (saved cookies/localStorage). */
40
+ storageState?: string;
41
+ }
42
+ /**
43
+ * Minimal browser surface for Restormel / Testing runners (single page, one context).
44
+ */
45
+ export interface TestingBrowserSession {
46
+ readonly page: import("playwright").Page;
47
+ navigate(url: string, options?: {
48
+ timeoutMs?: number;
49
+ waitUntil?: "load" | "domcontentloaded" | "networkidle";
50
+ }): Promise<void>;
51
+ click(locator: TestingLocator, options?: {
52
+ timeoutMs?: number;
53
+ }): Promise<void>;
54
+ fill(locator: TestingLocator, value: string, options?: {
55
+ timeoutMs?: number;
56
+ }): Promise<void>;
57
+ waitForLoad(state?: "load" | "domcontentloaded" | "networkidle"): Promise<void>;
58
+ waitForVisible(locator: TestingLocator, options?: {
59
+ timeoutMs?: number;
60
+ }): Promise<void>;
61
+ getVisibleText(locator: TestingLocator): Promise<string>;
62
+ /**
63
+ * Writes PNG to `path` (caller chooses artefact directory). Returns a core {@link ArtifactRef}.
64
+ */
65
+ screenshot(path: string): Promise<ArtifactRef>;
66
+ /** Bounded snapshot (oldest dropped). */
67
+ getConsoleSnapshot(): readonly BrowserConsoleLine[];
68
+ /** Bounded snapshot of finished requests (URL, method, status). */
69
+ getNetworkSnapshot(): readonly BrowserNetworkLine[];
70
+ /** Drain accumulated trace entries since last drain (or since start if never drained). */
71
+ drainTraceEntries(): BrowserSessionTraceEntry[];
72
+ dispose(): Promise<void>;
73
+ }
74
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACjC;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,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,IAAI,CAAC,CAAC;IAEhF,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9F,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhF,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzF,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzD;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAE/C,yCAAyC;IACzC,kBAAkB,IAAI,SAAS,kBAAkB,EAAE,CAAC;IAEpD,mEAAmE;IACnE,kBAAkB,IAAI,SAAS,kBAAkB,EAAE,CAAC;IAEpD,0FAA0F;IAC1F,iBAAiB,IAAI,wBAAwB,EAAE,CAAC;IAEhD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@restormel/testing-browser-playwright",
3
+ "version": "0.1.0",
4
+ "description": "Narrow Playwright session API for Restormel / Testing (launch, navigate, act, observe, artefacts).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/Allotment-Technology-Ltd/restormel-testing.git",
9
+ "directory": "packages/browser-playwright"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/Allotment-Technology-Ltd/restormel-testing/issues"
13
+ },
14
+ "homepage": "https://github.com/Allotment-Technology-Ltd/restormel-testing/tree/main/packages/browser-playwright#readme",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "type": "module",
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "engines": {
31
+ "node": ">=20"
32
+ },
33
+ "dependencies": {
34
+ "playwright": "^1.49.0",
35
+ "@restormel/testing-core": "0.1.0"
36
+ },
37
+ "devDependencies": {
38
+ "typescript": "^5.7.0"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc -b tsconfig.json",
42
+ "typecheck": "tsc -b tsconfig.json"
43
+ }
44
+ }