@autometa/playwright-loader 1.0.0-rc.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 +97 -0
- package/dist/bridge-generator.d.ts +41 -0
- package/dist/index.cjs +636 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +627 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.cjs +635 -0
- package/dist/loader.cjs.map +1 -0
- package/dist/loader.d.ts +47 -0
- package/dist/loader.js +627 -0
- package/dist/loader.js.map +1 -0
- package/dist/register.cjs +8 -0
- package/dist/register.cjs.map +1 -0
- package/dist/register.d.ts +15 -0
- package/dist/register.js +6 -0
- package/dist/register.js.map +1 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @autometa/playwright-loader
|
|
2
|
+
|
|
3
|
+
Node.js module loader hooks for transforming `.feature` files into Playwright test suites.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides the infrastructure to run Gherkin feature files directly with Playwright by leveraging Node.js customization hooks to transform `.feature` imports on-the-fly.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @autometa/playwright-loader @playwright/test
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Option 1: Import in playwright.config.ts
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import '@autometa/playwright-loader/register';
|
|
21
|
+
import { defineConfig } from '@playwright/test';
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
testMatch: '**/*.feature',
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Option 2: Use with NODE_OPTIONS
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
NODE_OPTIONS="--import @autometa/playwright-loader/register" npx playwright test
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Option 3: Use with autometa CLI
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// autometa.config.ts
|
|
38
|
+
import { defineConfig } from '@autometa/app';
|
|
39
|
+
|
|
40
|
+
export default defineConfig({
|
|
41
|
+
runner: 'playwright',
|
|
42
|
+
roots: {
|
|
43
|
+
features: ['features'],
|
|
44
|
+
steps: ['steps'],
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Then run:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pnpm autometa run
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## How It Works
|
|
56
|
+
|
|
57
|
+
1. **Node.js Module Hooks**: The loader uses Node.js's `module.register()` API to intercept `.feature` file imports.
|
|
58
|
+
|
|
59
|
+
2. **Resolve Hook**: When a `.feature` file is imported, the resolve hook marks it with a custom format.
|
|
60
|
+
|
|
61
|
+
3. **Load Hook**: The load hook transforms the `.feature` content into a Playwright test module:
|
|
62
|
+
- Parses the Gherkin content
|
|
63
|
+
- Loads step definitions from `autometa.config.ts`
|
|
64
|
+
- Generates `test.describe()` and `test()` blocks
|
|
65
|
+
|
|
66
|
+
4. **Playwright Integration**: The generated code uses Playwright's fixtures (`page`, `context`, etc.) and assertions.
|
|
67
|
+
|
|
68
|
+
## Requirements
|
|
69
|
+
|
|
70
|
+
- Node.js 18.19+ or 20.6+ (for module customization hooks)
|
|
71
|
+
- Playwright 1.40+
|
|
72
|
+
- TypeScript (recommended)
|
|
73
|
+
|
|
74
|
+
## Architecture
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
.feature file import
|
|
78
|
+
│
|
|
79
|
+
▼
|
|
80
|
+
┌───────────────────┐
|
|
81
|
+
│ resolve hook │ ← Intercepts .feature specifiers
|
|
82
|
+
└───────────────────┘
|
|
83
|
+
│
|
|
84
|
+
▼
|
|
85
|
+
┌───────────────────┐
|
|
86
|
+
│ load hook │ ← Transforms to Playwright test code
|
|
87
|
+
└───────────────────┘
|
|
88
|
+
│
|
|
89
|
+
▼
|
|
90
|
+
┌───────────────────┐
|
|
91
|
+
│ Playwright test │ ← Native execution with fixtures
|
|
92
|
+
└───────────────────┘
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge Code Generator for Playwright.
|
|
3
|
+
*
|
|
4
|
+
* Generates JavaScript/TypeScript code that transforms a Gherkin feature file
|
|
5
|
+
* into a Playwright test suite using `test.describe` and `test()`.
|
|
6
|
+
*
|
|
7
|
+
* This is heavily based on the vitest-plugins transform but adapted for
|
|
8
|
+
* Playwright's test runner and Node.js module loader hooks.
|
|
9
|
+
*/
|
|
10
|
+
import type { Config } from "@autometa/config";
|
|
11
|
+
export interface BridgeGeneratorOptions {
|
|
12
|
+
/** The absolute path to the .feature file */
|
|
13
|
+
featurePath: string;
|
|
14
|
+
/** The raw content of the .feature file */
|
|
15
|
+
featureContent: string;
|
|
16
|
+
/** The resolved autometa config (optional, will be loaded if not provided) */
|
|
17
|
+
config?: Config;
|
|
18
|
+
/** The path to the autometa config file */
|
|
19
|
+
configPath?: string;
|
|
20
|
+
/** The project root directory */
|
|
21
|
+
projectRoot?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generate Playwright bridge code for a .feature file.
|
|
25
|
+
*
|
|
26
|
+
* The generated code:
|
|
27
|
+
* 1. Imports Playwright's test runner and Autometa executors
|
|
28
|
+
* 2. Uses glob imports to load step definition modules
|
|
29
|
+
* 3. Parses the feature file at runtime
|
|
30
|
+
* 4. Coordinates the runner and executes tests
|
|
31
|
+
*
|
|
32
|
+
* @param featurePath - Absolute path to the .feature file
|
|
33
|
+
* @param featureContent - Raw content of the .feature file
|
|
34
|
+
* @param runtimeProjectRoot - The project root where packages should be resolved from (usually process.cwd())
|
|
35
|
+
* @returns Generated ESM module code
|
|
36
|
+
*/
|
|
37
|
+
export declare function generateBridgeCode(featurePath: string, featureContent: string, runtimeProjectRoot?: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Escape a string for use in generated code.
|
|
40
|
+
*/
|
|
41
|
+
export declare function escapeString(str: string): string;
|