playwright-test-explorer 0.0.1
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 +363 -0
- package/dist/api-DuYXKbq5.js +965 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +89 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +3 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
# Playwright Test Explorer
|
|
2
|
+
|
|
3
|
+
A CLI tool and library for exploring Playwright tests. This tool provides easy access to test structure, test files, and test cases in your Playwright projects.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 📋 List all test files in a Playwright project
|
|
8
|
+
- 🔍 List test cases with detailed information (location, tags, annotations)
|
|
9
|
+
- 🌳 Display test structure as a tree
|
|
10
|
+
- 💻 Easy-to-use CLI interface
|
|
11
|
+
- 📦 Can be used as a library in your Node.js projects
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
### Global Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g playwright-test-explorer
|
|
19
|
+
# or
|
|
20
|
+
pnpm add -g playwright-test-explorer
|
|
21
|
+
# or
|
|
22
|
+
yarn global add playwright-test-explorer
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Local Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install playwright-test-explorer
|
|
29
|
+
# or
|
|
30
|
+
pnpm add playwright-test-explorer
|
|
31
|
+
# or
|
|
32
|
+
yarn add playwright-test-explorer
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## CLI Usage
|
|
36
|
+
|
|
37
|
+
### List Test Files
|
|
38
|
+
|
|
39
|
+
List all test files in the Playwright project:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pw-test-explorer list-files
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
With custom workspace and config:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pw-test-explorer list-files -w /path/to/project -c e2e/playwright.config.ts
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Save results to a JSON file:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pw-test-explorer list-files -o output.json
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Options:
|
|
58
|
+
- `-w, --workspace <path>` - Workspace folder path (default: current directory)
|
|
59
|
+
- `-c, --config <file>` - Config file path relative to workspace (default: `playwright.config.ts`)
|
|
60
|
+
- `-o, --output <file>` - Output file path to save JSON results (optional)
|
|
61
|
+
|
|
62
|
+
### List Test Cases
|
|
63
|
+
|
|
64
|
+
List all test cases in specified files:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pw-test-explorer list-tests -f tests/example.spec.ts tests/another.spec.ts
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
With custom workspace:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pw-test-explorer list-tests -w /path/to/project -f e2e/tests/example.spec.ts
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Save results to a JSON file:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pw-test-explorer list-tests -f tests/example.spec.ts -o tests.json
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Options:
|
|
83
|
+
- `-w, --workspace <path>` - Workspace folder path (default: current directory)
|
|
84
|
+
- `-c, --config <file>` - Config file path relative to workspace (default: `playwright.config.ts`)
|
|
85
|
+
- `-f, --files <files...>` - Test file paths relative to workspace (required)
|
|
86
|
+
- `-o, --output <file>` - Output file path to save JSON results (optional)
|
|
87
|
+
|
|
88
|
+
### Display Test Tree
|
|
89
|
+
|
|
90
|
+
Display the complete test structure as a tree:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pw-test-explorer tree
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
With custom workspace:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pw-test-explorer tree -w /path/to/project -c playwright.config.ts
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Save results to a JSON file:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pw-test-explorer tree -o tree.json
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Options:
|
|
109
|
+
- `-w, --workspace <path>` - Workspace folder path (default: current directory)
|
|
110
|
+
- `-c, --config <file>` - Config file path relative to workspace (default: `playwright.config.ts`)
|
|
111
|
+
- `-o, --output <file>` - Output file path to save JSON results (optional)
|
|
112
|
+
|
|
113
|
+
## Library Usage
|
|
114
|
+
|
|
115
|
+
This package provides three simple APIs for exploring Playwright tests:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import {
|
|
119
|
+
listTestFile,
|
|
120
|
+
listTestCase,
|
|
121
|
+
treeStructure
|
|
122
|
+
} from 'playwright-test-explorer';
|
|
123
|
+
|
|
124
|
+
// 1. List all test files in a project (output to console)
|
|
125
|
+
await listTestFile('/path/to/project', 'playwright.config.ts');
|
|
126
|
+
|
|
127
|
+
// List all test files and save to a file
|
|
128
|
+
await listTestFile('/path/to/project', 'playwright.config.ts', 'output.json');
|
|
129
|
+
|
|
130
|
+
// 2. List test cases in specific files (output to console)
|
|
131
|
+
await listTestCase(
|
|
132
|
+
'/path/to/project',
|
|
133
|
+
'playwright.config.ts',
|
|
134
|
+
['tests/example.spec.ts', 'tests/another.spec.ts']
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// List test cases and save to a file
|
|
138
|
+
await listTestCase(
|
|
139
|
+
'/path/to/project',
|
|
140
|
+
'playwright.config.ts',
|
|
141
|
+
['tests/example.spec.ts', 'tests/another.spec.ts'],
|
|
142
|
+
'tests.json'
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// 3. Display complete test structure as a tree (output to console)
|
|
146
|
+
await treeStructure('/path/to/project', 'playwright.config.ts');
|
|
147
|
+
|
|
148
|
+
// Display test tree and save to a file
|
|
149
|
+
await treeStructure(
|
|
150
|
+
'/path/to/project',
|
|
151
|
+
'playwright.config.ts',
|
|
152
|
+
undefined, // cancellationToken
|
|
153
|
+
'tree.json'
|
|
154
|
+
);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
All three functions output results in JSON format - either to `console.log` or to a specified file.
|
|
158
|
+
|
|
159
|
+
## API Reference
|
|
160
|
+
|
|
161
|
+
### `listTestFile(workspaceFolder, configFile, outputFile?)`
|
|
162
|
+
|
|
163
|
+
Lists all test files in the Playwright project and outputs the result to console or a file.
|
|
164
|
+
|
|
165
|
+
**Parameters:**
|
|
166
|
+
- `workspaceFolder`: `string` - Path to the workspace folder (default: `process.cwd()`)
|
|
167
|
+
- `configFile`: `string` - Config file path relative to workspace (default: `'playwright.config.ts'`)
|
|
168
|
+
- `outputFile`: `string` (optional) - Path to save JSON output. If not provided, outputs to console.
|
|
169
|
+
|
|
170
|
+
**Returns:** `Promise<void>`
|
|
171
|
+
|
|
172
|
+
**Output Example:**
|
|
173
|
+
```json
|
|
174
|
+
{
|
|
175
|
+
"projects": [
|
|
176
|
+
{
|
|
177
|
+
"name": "chromium",
|
|
178
|
+
"testDir": "/path/to/tests",
|
|
179
|
+
"use": { "browserName": "chromium" },
|
|
180
|
+
"files": [
|
|
181
|
+
"/path/to/tests/example.spec.ts",
|
|
182
|
+
"/path/to/tests/another.spec.ts"
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### `listTestCase(workspaceFolder, configFile, relativePaths, outputFile?)`
|
|
190
|
+
|
|
191
|
+
Lists all test cases in specified files and outputs the result to console or a file.
|
|
192
|
+
|
|
193
|
+
**Parameters:**
|
|
194
|
+
- `workspaceFolder`: `string` - Path to the workspace folder (default: `process.cwd()`)
|
|
195
|
+
- `configFile`: `string` - Config file path relative to workspace (default: `'playwright.config.ts'`)
|
|
196
|
+
- `relativePaths`: `string[]` - Array of test file paths relative to workspace
|
|
197
|
+
- `outputFile`: `string` (optional) - Path to save JSON output. If not provided, outputs to console.
|
|
198
|
+
|
|
199
|
+
**Returns:** `Promise<void>`
|
|
200
|
+
|
|
201
|
+
**Output Example:**
|
|
202
|
+
```json
|
|
203
|
+
{
|
|
204
|
+
"tests": [
|
|
205
|
+
{
|
|
206
|
+
"title": "should login successfully",
|
|
207
|
+
"file": "/path/to/tests/login.spec.ts",
|
|
208
|
+
"line": 10,
|
|
209
|
+
"column": 3,
|
|
210
|
+
"tags": ["@smoke"],
|
|
211
|
+
"annotations": [],
|
|
212
|
+
"expectedStatus": "passed",
|
|
213
|
+
"timeout": 30000,
|
|
214
|
+
"titlePath": ["Login Tests", "should login successfully"]
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### `treeStructure(workspaceFolder, configFile, cancellationToken?, outputFile?)`
|
|
221
|
+
|
|
222
|
+
Displays the complete test structure as a tree and outputs the result to console or a file.
|
|
223
|
+
|
|
224
|
+
**Parameters:**
|
|
225
|
+
- `workspaceFolder`: `string` - Path to the workspace folder (default: `process.cwd()`)
|
|
226
|
+
- `configFile`: `string` - Config file path relative to workspace (default: `'playwright.config.ts'`)
|
|
227
|
+
- `cancellationToken`: `CancellationToken` (optional) - Optional cancellation token for cancelling the operation
|
|
228
|
+
- `outputFile`: `string` (optional) - Path to save JSON output. If not provided, outputs to console.
|
|
229
|
+
|
|
230
|
+
**Returns:** `Promise<void>`
|
|
231
|
+
|
|
232
|
+
**Output Example:**
|
|
233
|
+
```json
|
|
234
|
+
{
|
|
235
|
+
"type": "suite",
|
|
236
|
+
"title": "Root",
|
|
237
|
+
"children": [
|
|
238
|
+
{
|
|
239
|
+
"type": "suite",
|
|
240
|
+
"title": "Login Tests",
|
|
241
|
+
"file": "/path/to/tests/login.spec.ts",
|
|
242
|
+
"children": [
|
|
243
|
+
{
|
|
244
|
+
"type": "test",
|
|
245
|
+
"title": "should login successfully",
|
|
246
|
+
"location": {
|
|
247
|
+
"file": "/path/to/tests/login.spec.ts",
|
|
248
|
+
"line": 10,
|
|
249
|
+
"column": 3
|
|
250
|
+
},
|
|
251
|
+
"tags": ["@smoke"],
|
|
252
|
+
"expectedStatus": "passed",
|
|
253
|
+
"timeout": 30000
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
]
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Requirements
|
|
262
|
+
|
|
263
|
+
- Node.js 16 or higher
|
|
264
|
+
- `@playwright/test` installed in your project
|
|
265
|
+
|
|
266
|
+
## Testing
|
|
267
|
+
|
|
268
|
+
The project includes comprehensive tests using Vitest and an example Playwright project.
|
|
269
|
+
|
|
270
|
+
### Run All Tests
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# Install dependencies and build
|
|
274
|
+
pnpm install
|
|
275
|
+
pnpm run build
|
|
276
|
+
|
|
277
|
+
# Run vitest tests (includes API and CLI tests)
|
|
278
|
+
pnpm test
|
|
279
|
+
|
|
280
|
+
# Run tests in watch mode
|
|
281
|
+
pnpm test -- --watch
|
|
282
|
+
|
|
283
|
+
# Run with coverage
|
|
284
|
+
pnpm test -- --coverage
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Example Project
|
|
288
|
+
|
|
289
|
+
The `example/` directory contains a sample Playwright project with:
|
|
290
|
+
- 4 projects (chromium, firefox, webkit, mobile)
|
|
291
|
+
- 3 test files with 18+ tests
|
|
292
|
+
- Various test scenarios (UI, API, authentication)
|
|
293
|
+
|
|
294
|
+
### Test Suites
|
|
295
|
+
|
|
296
|
+
The project includes two comprehensive test suites:
|
|
297
|
+
|
|
298
|
+
1. **API Tests** (`tests/api.test.ts`) - Tests the JavaScript API functions
|
|
299
|
+
- listTestFile functionality
|
|
300
|
+
- listTestCase functionality
|
|
301
|
+
- treeStructure functionality
|
|
302
|
+
- File output capabilities
|
|
303
|
+
|
|
304
|
+
2. **CLI Tests** (`tests/cli.test.ts`) - Tests the command-line interface
|
|
305
|
+
- list-files command
|
|
306
|
+
- list-tests command
|
|
307
|
+
- tree command
|
|
308
|
+
- Help and version commands
|
|
309
|
+
- File output functionality
|
|
310
|
+
|
|
311
|
+
All tests use the example Playwright project in `example/` directory.
|
|
312
|
+
|
|
313
|
+
### Manual Testing
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
# List test files
|
|
317
|
+
pnpm run test:list-files
|
|
318
|
+
|
|
319
|
+
# List test cases
|
|
320
|
+
pnpm run test:list-tests
|
|
321
|
+
|
|
322
|
+
# Display test tree
|
|
323
|
+
pnpm run test:example
|
|
324
|
+
|
|
325
|
+
# Save results to files
|
|
326
|
+
pnpm run test:save-files
|
|
327
|
+
pnpm run test:save-tree
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
See [TESTING.md](TESTING.md) for comprehensive testing documentation.
|
|
331
|
+
|
|
332
|
+
## Development
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
# Install dependencies
|
|
336
|
+
pnpm install
|
|
337
|
+
|
|
338
|
+
# Build the project
|
|
339
|
+
pnpm run build
|
|
340
|
+
|
|
341
|
+
# Run in development mode
|
|
342
|
+
pnpm run dev
|
|
343
|
+
|
|
344
|
+
# Type check
|
|
345
|
+
pnpm run typecheck
|
|
346
|
+
|
|
347
|
+
# Run tests
|
|
348
|
+
pnpm test
|
|
349
|
+
|
|
350
|
+
# Run tests in watch mode
|
|
351
|
+
pnpm run test:watch
|
|
352
|
+
|
|
353
|
+
# Run tests with coverage
|
|
354
|
+
pnpm run test:coverage
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
## License
|
|
358
|
+
|
|
359
|
+
MIT
|
|
360
|
+
|
|
361
|
+
## Credits
|
|
362
|
+
|
|
363
|
+
Based on the test server implementation from [Microsoft's playwright-vscode](https://github.com/microsoft/playwright-vscode).
|