@ricsam/isolate-playwright 0.0.1 → 0.1.2

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 CHANGED
@@ -1,45 +1,116 @@
1
1
  # @ricsam/isolate-playwright
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
4
-
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
-
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
8
-
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@ricsam/isolate-playwright`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
3
+ Playwright bridge for running browser tests in a V8 sandbox. Execute untrusted Playwright test code against a real browser page while keeping the test logic isolated.
4
+
5
+ ```typescript
6
+ import ivm from "isolated-vm";
7
+ import { chromium } from "playwright";
8
+ import { setupPlaywright, runPlaywrightTests } from "@ricsam/isolate-playwright";
9
+
10
+ // Create browser and page
11
+ const browser = await chromium.launch();
12
+ const page = await browser.newPage();
13
+
14
+ // Create isolate and context
15
+ const isolate = new ivm.Isolate();
16
+ const context = await isolate.createContext();
17
+
18
+ // Setup playwright bridge
19
+ const handle = await setupPlaywright(context, {
20
+ page,
21
+ timeout: 30000,
22
+ baseUrl: "https://example.com",
23
+ onNetworkRequest: (info) => console.log("Request:", info.url),
24
+ onNetworkResponse: (info) => console.log("Response:", info.status),
25
+ onConsoleLog: (level, ...args) => console.log(`[${level}]`, ...args),
26
+ });
27
+
28
+ // Load and run untrusted test code
29
+ await context.eval(`
30
+ test("homepage loads correctly", async () => {
31
+ await page.goto("/");
32
+ const heading = page.getByRole("heading", { name: "Example Domain" });
33
+ await expect(heading).toBeVisible();
34
+ });
35
+
36
+ test("can interact with elements", async () => {
37
+ const link = page.locator("a");
38
+ await expect(link).toBeVisible();
39
+ const text = await link.textContent();
40
+ expect(text).toContain("More information");
41
+ });
42
+ `);
43
+
44
+ // Run tests and get results
45
+ const results = await runPlaywrightTests(context);
46
+ console.log(`${results.passed}/${results.total} tests passed`);
47
+
48
+ // Cleanup
49
+ handle.dispose();
50
+ context.release();
51
+ isolate.dispose();
52
+ await browser.close();
53
+ ```
54
+
55
+ **Injected Globals (in isolate):**
56
+ - `page` - Page object with navigation and locator methods
57
+ - `test(name, fn)` - Register a test
58
+ - `expect(actual)` - Assertion helper for locators and primitives
59
+ - `Locator` - Locator class for element interactions
60
+
61
+ **Page Methods:**
62
+ - `page.goto(url, options?)` - Navigate to URL
63
+ - `page.reload()` - Reload page
64
+ - `page.url()` - Get current URL (sync)
65
+ - `page.title()` - Get page title
66
+ - `page.content()` - Get page HTML
67
+ - `page.waitForSelector(selector, options?)` - Wait for element
68
+ - `page.waitForTimeout(ms)` - Wait for milliseconds
69
+ - `page.waitForLoadState(state?)` - Wait for load state
70
+ - `page.evaluate(script)` - Evaluate JS in browser context
71
+ - `page.locator(selector)` - Get locator by CSS selector
72
+ - `page.getByRole(role, options?)` - Get locator by ARIA role
73
+ - `page.getByText(text)` - Get locator by text content
74
+ - `page.getByLabel(label)` - Get locator by label
75
+ - `page.getByPlaceholder(text)` - Get locator by placeholder
76
+ - `page.getByTestId(id)` - Get locator by test ID
77
+
78
+ **Locator Methods:**
79
+ - `click()`, `dblclick()`, `hover()`, `focus()`
80
+ - `fill(text)`, `type(text)`, `clear()`, `press(key)`
81
+ - `check()`, `uncheck()`, `selectOption(value)`
82
+ - `textContent()`, `inputValue()`
83
+ - `isVisible()`, `isEnabled()`, `isChecked()`, `count()`
84
+
85
+ **Expect Matchers (for Locators):**
86
+ - `toBeVisible()`, `toBeEnabled()`, `toBeChecked()`
87
+ - `toContainText(text)`, `toHaveValue(value)`
88
+ - All matchers support `.not` modifier
89
+
90
+ **Expect Matchers (for Primitives):**
91
+ - `toBe(expected)`, `toEqual(expected)`
92
+ - `toBeTruthy()`, `toBeFalsy()`
93
+ - `toContain(item)`
94
+
95
+ **Handle Methods:**
96
+ - `dispose()` - Clean up event listeners
97
+ - `getConsoleLogs()` - Get captured browser console logs
98
+ - `getNetworkRequests()` - Get captured network requests
99
+ - `getNetworkResponses()` - Get captured network responses
100
+ - `clearCollected()` - Clear all collected data
101
+
102
+ **Test Results:**
103
+
104
+ ```typescript
105
+ interface PlaywrightExecutionResult {
106
+ passed: number;
107
+ failed: number;
108
+ total: number;
109
+ results: Array<{
110
+ name: string;
111
+ passed: boolean;
112
+ error?: string;
113
+ duration: number;
114
+ }>;
115
+ }
116
+ ```