Skip to content

Commit aa2b138

Browse files
committed
chore: init
1 parent 4d43199 commit aa2b138

File tree

8 files changed

+294
-0
lines changed

8 files changed

+294
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Setup-node and cache"
2+
description: "Base setup for each action"
3+
inputs:
4+
node-version:
5+
required: false
6+
description: "Node version for setup-node"
7+
default: "20"
8+
9+
runs:
10+
using: "composite"
11+
steps:
12+
- name: Install pnpm
13+
uses: pnpm/action-setup@v2
14+
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: ${{ inputs.node-version }}
18+
registry-url: "https://registry.npmjs.org"
19+
20+
- uses: actions/cache@v4
21+
with:
22+
path: |
23+
~/.pnpm-store
24+
**/node_modules
25+
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
26+
restore-keys: |
27+
${{ runner.os }}

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
node-version: [20, 22]
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- uses: ./.github/actions/setup-and-cache
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
26+
- name: Install
27+
run: pnpm install
28+
29+
- name: Build
30+
run: pnpm build
31+
32+
- name: Lint
33+
run: pnpm lint
34+
35+
- name: Typecheck
36+
run: pnpm typecheck
37+
38+
- name: Test
39+
run: pnpm test
40+
41+
publish-preview:
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- uses: actions/checkout@v4
46+
47+
- name: Install pnpm
48+
uses: pnpm/action-setup@v2
49+
50+
- uses: ./.github/actions/setup-and-cache
51+
with:
52+
node-version: 22
53+
54+
- name: Install & Build & Publish
55+
run: |
56+
pnpm install
57+
pnpm build
58+
npx pkg-pr-new publish

.github/workflows/publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release-type:
7+
type: choice
8+
description: Type of the release
9+
options:
10+
- patch
11+
- minor
12+
- major
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
id-token: write
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- uses: ./.github/actions/setup-and-cache
24+
with:
25+
node-version: 22
26+
27+
- name: Install & Build
28+
run: |
29+
pnpm install
30+
pnpm build
31+
32+
- name: Configure github-actions git
33+
run: |
34+
git config --global user.name 'github-actions'
35+
git config --global user.email '[email protected]'
36+
37+
- name: Bump version
38+
run: pnpm version ${{ github.event.inputs.release-type }}
39+
40+
- name: Push release tag
41+
run: git push origin main --follow-tags
42+
43+
- name: Publish to npm
44+
run: pnpm publish --provenance
45+
env:
46+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
dist

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shell-emulator=true

README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# @webcontainer/playwright
2+
3+
[![Version][version-badge]][npm-url]
4+
5+
> Playwright utilities for testing applications in WebContainers
6+
7+
[Installation](#installation) | [API](#api)
8+
9+
---
10+
11+
Test your applications and packages inside WebContainers using Playwright.
12+
13+
## Installation
14+
15+
```sh
16+
$ npm install --save-dev @webcontainer/playwright
17+
```
18+
19+
`@playwright/test` is required as peer dependency:
20+
21+
```sh
22+
$ npm install --save-dev @playwright/test
23+
```
24+
25+
## API
26+
27+
### Fixtures
28+
29+
WebContainer utilities are defined as [Playwright fixtures](https://playwright.dev/docs/test-fixtures). You can import pre-defined `test()`, or import each fixture manually and extend your own `test` with each fixture.
30+
31+
```ts
32+
// Pre-defined test()
33+
import { test } from "@webcontainer/playwright";
34+
```
35+
36+
```ts
37+
// Manual import of each fixture
38+
import {
39+
Editor,
40+
Preview,
41+
Terminal,
42+
WebContainer,
43+
} from "@webcontainer/playwright";
44+
import { test as base } from "@playwright/test";
45+
46+
const test = base.extend<{
47+
editor: Editor;
48+
preview: Preview;
49+
terminal: Terminal;
50+
webcontainer: WebContainer;
51+
}>({
52+
editor: async ({ page }, use) => {
53+
use(new Editor(page));
54+
},
55+
preview: async ({ page }, use) => {
56+
use(new Preview(page));
57+
},
58+
terminal: async ({ page }, use) => {
59+
use(new Terminal(page));
60+
},
61+
webcontainer: async ({ page }, use) => {
62+
use(new WebContainer(page));
63+
},
64+
});
65+
66+
export { test };
67+
```
68+
69+
You can access each fixture in your test cases:
70+
71+
```ts
72+
import { test } from "@webcontainer/playwright"; // or your own `test` setup
73+
74+
test("user can open Vite TypeScript starter", async ({
75+
page,
76+
editor,
77+
preview,
78+
terminal,
79+
}) => {
80+
await page.goto("/");
81+
82+
await editor.getByFile("package.json", /"vite": "^6.0.11"/);
83+
await editor.getByFile("src/main.ts", /<h1>Hello Vite<\/h1>/);
84+
85+
await terminal.getByText("VITE v6.0.11 ready");
86+
87+
await preview.getByRole("heading", { level: 1, name: "Hello Vite" });
88+
});
89+
```
90+
91+
#### Editor
92+
93+
##### `getByFile`
94+
95+
Get file by its name and content.
96+
97+
```ts
98+
async function getByFile(filename: string, content: RegExp | string): Locator;
99+
```
100+
101+
#### Preview
102+
103+
##### `getByRole`
104+
105+
Playwright's [`getByRole`](https://playwright.dev/docs/api/class-framelocator#frame-locator-get-by-role) that's scoped to the preview `<iframe>`.
106+
107+
#### Terminal
108+
109+
##### `getByText`
110+
111+
Playwright's [`getByText`](https://playwright.dev/docs/api/class-framelocator#frame-locator-get-by-role) that's scoped to the terminal.
112+
113+
#### WebContainer
114+
115+
##### `runCommand`
116+
117+
Run command inside WebContainer process.
118+
119+
```ts
120+
async function runCommand(command: string): Promise<void>;
121+
```
122+
123+
[version-badge]: https://img.shields.io/npm/v/@webcontainer/playwright
124+
[npm-url]: https://www.npmjs.com/package/@webcontainer/playwright

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@webcontainer/playwright",
3+
"version": "0.0.1",
4+
"description": "Playwright utilities for testing applications in WebContainers",
5+
"author": "StackBlitz Inc.",
6+
"license": "MIT",
7+
"type": "module",
8+
"exports": "./dist/index.js",
9+
"types": "./dist/index.d.ts",
10+
"files": [
11+
"dist"
12+
],
13+
"homepage": "https://github.com/stackblitz/webcontainer-playwright",
14+
"bugs": "https://github.com/stackblitz/webcontainer-playwright",
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/stackblitz/webcontainer-playwright.git"
18+
},
19+
"keywords": [
20+
"testing",
21+
"webcontainer",
22+
"playwright"
23+
],
24+
"packageManager": "[email protected]",
25+
"scripts": {
26+
"build": "echo \"Error: no build specified\"",
27+
"test": "echo \"Error: no test specified\"",
28+
"lint": "echo \"Error: no linttest specified\"",
29+
"typecheck": "echo \"Error: no typecheck specified\""
30+
},
31+
"dependencies": {},
32+
"peerDependencies": {},
33+
"devDependencies": {}
34+
}

0 commit comments

Comments
 (0)