@sun-asterisk/sungen 2.0.0 → 2.0.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.
Files changed (39) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/generators/test-generator/adapters/playwright/templates/steps/actions/table-action-in-row.hbs +2 -2
  3. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-cell-by-filter.hbs +2 -2
  4. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-cell-by-index.hbs +2 -2
  5. package/dist/generators/test-generator/code-generator.d.ts.map +1 -1
  6. package/dist/generators/test-generator/code-generator.js +10 -0
  7. package/dist/generators/test-generator/code-generator.js.map +1 -1
  8. package/dist/generators/test-generator/step-mapper.d.ts +4 -0
  9. package/dist/generators/test-generator/step-mapper.d.ts.map +1 -1
  10. package/dist/generators/test-generator/step-mapper.js +8 -0
  11. package/dist/generators/test-generator/step-mapper.js.map +1 -1
  12. package/dist/orchestrator/project-initializer.d.ts +4 -0
  13. package/dist/orchestrator/project-initializer.d.ts.map +1 -1
  14. package/dist/orchestrator/project-initializer.js +11 -410
  15. package/dist/orchestrator/project-initializer.js.map +1 -1
  16. package/dist/orchestrator/templates/ai-rules.md +189 -0
  17. package/dist/orchestrator/templates/gitignore +16 -0
  18. package/dist/orchestrator/templates/playwright.config.d.ts +10 -0
  19. package/dist/orchestrator/templates/playwright.config.d.ts.map +1 -0
  20. package/dist/orchestrator/templates/playwright.config.js +77 -0
  21. package/dist/orchestrator/templates/playwright.config.js.map +1 -0
  22. package/dist/orchestrator/templates/playwright.config.ts +80 -0
  23. package/dist/orchestrator/templates/readme.md +197 -0
  24. package/docs/gherkin standards/gherkin-core-standard.md +377 -0
  25. package/docs/gherkin standards/gherkin-core-standard.vi.md +303 -0
  26. package/docs/gherkin-dictionary.md +1071 -0
  27. package/docs/makeauth.md +225 -0
  28. package/package.json +3 -2
  29. package/src/cli/index.ts +1 -1
  30. package/src/generators/test-generator/adapters/playwright/templates/steps/actions/table-action-in-row.hbs +2 -2
  31. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-cell-by-filter.hbs +2 -2
  32. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-cell-by-index.hbs +2 -2
  33. package/src/generators/test-generator/code-generator.ts +11 -0
  34. package/src/generators/test-generator/step-mapper.ts +9 -0
  35. package/src/orchestrator/project-initializer.ts +12 -410
  36. package/src/orchestrator/templates/ai-rules.md +189 -0
  37. package/src/orchestrator/templates/gitignore +16 -0
  38. package/src/orchestrator/templates/playwright.config.ts +80 -0
  39. package/src/orchestrator/templates/readme.md +197 -0
@@ -0,0 +1,80 @@
1
+ import { defineConfig, devices } from '@playwright/test';
2
+
3
+ /**
4
+ * Read environment variables from file.
5
+ * https://github.com/motdotla/dotenv
6
+ */
7
+ // import dotenv from 'dotenv';
8
+ // import path from 'path';
9
+ // dotenv.config({ path: path.resolve(__dirname, '.env') });
10
+
11
+ /**
12
+ * See https://playwright.dev/docs/test-configuration.
13
+ */
14
+ export default defineConfig({
15
+ testDir: './specs/generated',
16
+ /* Run tests in files in parallel */
17
+ fullyParallel: true,
18
+ /* Fail the build on CI if you accidentally left test.only in the source code. */
19
+ forbidOnly: !!process.env.CI,
20
+ /* Retry on CI only */
21
+ retries: process.env.CI ? 2 : 0,
22
+ /* Opt out of parallel tests on CI. */
23
+ workers: process.env.CI ? 1 : undefined,
24
+ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
25
+ reporter: 'html',
26
+ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
27
+ use: {
28
+ /* Base URL to use in actions like `await page.goto('')`. */
29
+ baseURL: 'https://example.com',
30
+
31
+ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
32
+ trace: 'on-first-retry',
33
+ },
34
+
35
+ /* Configure projects for major browsers */
36
+ projects: [
37
+ {
38
+ name: 'chromium',
39
+ use: { ...devices['Desktop Chrome'] },
40
+ },
41
+
42
+ /*
43
+ // {
44
+ // name: 'firefox',
45
+ // use: { ...devices['Desktop Firefox'] },
46
+ // },
47
+
48
+ // {
49
+ // name: 'webkit',
50
+ // use: { ...devices['Desktop Safari'] },
51
+ // },
52
+
53
+ /* Test against mobile viewports.
54
+ // {
55
+ // name: 'Mobile Chrome',
56
+ // use: { ...devices['Pixel 5'] },
57
+ // },
58
+ // {
59
+ // name: 'Mobile Safari',
60
+ // use: { ...devices['iPhone 12'] },
61
+ // },
62
+
63
+ /* Test against branded browsers. */
64
+ // {
65
+ // name: 'Microsoft Edge',
66
+ // use: { ...devices['Desktop Edge'], channel: 'msedge' },
67
+ // },
68
+ // {
69
+ // name: 'Google Chrome',
70
+ // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
71
+ // },
72
+ ],
73
+
74
+ /* Run your local dev server before starting the tests */
75
+ // webServer: {
76
+ // command: 'npm run start',
77
+ // url: 'http://localhost:3000',
78
+ // reuseExistingServer: !process.env.CI,
79
+ // },
80
+ });
@@ -0,0 +1,197 @@
1
+ # Sungen Test Automation
2
+
3
+ This project uses [Sungen v2](https://github.com/sun-asterisk/sungen) — a deterministic E2E test compiler.
4
+
5
+ ## How it works
6
+
7
+ ```
8
+ AI (Copilot/Claude + MCP Playwright) → visits URL → generates files
9
+ sungen generate → compiles Gherkin + selectors + data → Playwright .spec.ts
10
+ ```
11
+
12
+ ## Directory Structure
13
+
14
+ ```
15
+ ├── qa/screens/<name>/
16
+ │ ├── features/ # .feature files (Gherkin)
17
+ │ ├── selectors/ # Element locator YAML mappings
18
+ │ └── test-data/ # Test data YAML values
19
+ ├── specs/
20
+ │ ├── generated/ # Auto-generated Playwright tests
21
+ │ └── .auth/ # Auth storage states
22
+ ├── docs/
23
+ │ └── gherkin-dictionary.md # Full grammar & compiler rules
24
+ ├── .github/
25
+ │ └── copilot-instructions.md # AI rules for GitHub Copilot
26
+ └── CLAUDE.md # AI rules for Claude Code
27
+ ```
28
+
29
+ ## Workflow
30
+
31
+ ### 1. Add a screen
32
+
33
+ ```bash
34
+ sungen add --screen login --path /login
35
+ # Add more features to an existing screen:
36
+ sungen add --screen login --feature forgot-password
37
+ ```
38
+
39
+ ### 2. Set up auth (if needed)
40
+
41
+ ```bash
42
+ sungen makeauth admin
43
+ # Opens browser → login manually → saves specs/.auth/admin.json
44
+ ```
45
+
46
+ ### 3. Generate Gherkin + selectors with AI
47
+
48
+ Use your AI assistant (GitHub Copilot or Claude Code) to:
49
+ 1. Navigate to the page URL via MCP Playwright
50
+ 2. Take an accessibility snapshot
51
+ 3. Generate `.feature` + `selectors.yaml` + `test-data.yaml`
52
+
53
+ The AI rules in `.github/copilot-instructions.md` and `CLAUDE.md` teach the AI
54
+ how to write correct Gherkin syntax and selector YAML for sungen.
55
+
56
+ ### 4. Compile to Playwright tests
57
+
58
+ ```bash
59
+ sungen generate --screen login
60
+ # or for all screens:
61
+ sungen generate --all
62
+ ```
63
+
64
+ ### 5. Run tests
65
+
66
+ ```bash
67
+ npx playwright test
68
+ npx playwright test --ui # interactive mode
69
+ ```
70
+
71
+ ### 6. Fix failures (AI Verify loop)
72
+
73
+ When tests fail, use AI to read the error → fix `selectors.yaml` → recompile → re-run.
74
+
75
+ | Error | Fix in selectors.yaml |
76
+ |---|---|
77
+ | strict mode: resolved to N elements | Add `exact: true` or `scope` or `nth` |
78
+ | element(s) not found | Fix `name`, `type`, or `value` |
79
+ | getByText matched too many | Add `match: 'exact'` or `nth` |
80
+
81
+ ---
82
+
83
+ ## Gherkin Guide
84
+
85
+ ### Syntax
86
+
87
+ ```
88
+ User <action> [<Target>] <type> with {{<Value>}}
89
+ ```
90
+
91
+ - `[Target]` → selector reference → lookup in `selectors/*.yaml`
92
+ - `{{Value}}` → test data reference → lookup in `test-data/*.yaml`
93
+ - `<type>` → element type: button, link, field, heading, text, etc.
94
+
95
+ ### Pattern Shapes (17 total)
96
+
97
+ #### Actions
98
+
99
+ | Pattern | Example |
100
+ |---|---|
101
+ | Simple click | `User click [Submit] button` |
102
+ | Click with data | `User click [Teammate] button with {{name}}` |
103
+ | Fill field | `User fill [Email] field with {{email}}` |
104
+ | Check/Uncheck | `User check [Remember me] checkbox` |
105
+ | Select dropdown | `User select [Country] dropdown with {{country}}` |
106
+ | Upload file | `User upload [Avatar] file with {{path}}` |
107
+ | Double click | `User double click [Cell] element` |
108
+ | Hover | `User hover [Info] icon` |
109
+ | Clear | `User clear [Search] field` |
110
+
111
+ #### Keyboard
112
+
113
+ | Pattern | Example |
114
+ |---|---|
115
+ | Global key | `User press Escape key` |
116
+ | Key on element | `User press Enter on [Search] field` |
117
+
118
+ #### Navigation
119
+
120
+ | Pattern | Example |
121
+ |---|---|
122
+ | Open page | `User is on [login] page` |
123
+ | See page (URL) | `User see [dashboard] page` |
124
+
125
+ #### Wait
126
+
127
+ | Pattern | Example |
128
+ |---|---|
129
+ | Wait timeout | `User wait for 3 seconds` |
130
+ | Wait element | `User wait for [Modal] dialog` |
131
+ | Wait hidden | `User wait for [Loading] spinner is hidden` |
132
+ | Wait with data | `User wait for [Dialog] dialog with {{title}}` |
133
+
134
+ #### Assertions
135
+
136
+ | Pattern | Example |
137
+ |---|---|
138
+ | See element | `User see [Welcome] heading` |
139
+ | See with value | `User see [Title] heading with {{title}}` |
140
+ | State check | `User see [Submit] button is disabled` |
141
+ | State + data | `User see [Panel] dialog with {{title}} is hidden` |
142
+ | Text contains | `User see [Message] text contains {{partial}}` |
143
+
144
+ States: `hidden`, `visible`, `disabled`, `enabled`, `checked`, `unchecked`, `focused`, `empty`
145
+
146
+ #### Table
147
+
148
+ | Pattern | Example |
149
+ |---|---|
150
+ | Row exists | `User see [Users] table has row with {{name}}` |
151
+ | No row | `User see [Users] table has no row with {{name}}` |
152
+ | Row count | `User see [Users] table has {{count}} rows` |
153
+ | Column exists | `User see [Users] table has [Email] column` |
154
+ | Cell by filter | `User see [Users] table row with {{name}} has [Status] with {{status}}` |
155
+ | Cell by index | `User see [Users] table row 1 [Name] cell with {{name}}` |
156
+ | Action in row | `User click [Edit] in [Users] table row with {{name}}` |
157
+ | Empty table | `User see [Users] table is empty` |
158
+
159
+ #### Scope
160
+
161
+ | Pattern | Example |
162
+ |---|---|
163
+ | Scroll | `User scroll to [Footer] section` |
164
+ | Frame enter | `User switch to [Payment] frame` |
165
+ | Frame exit | `User switch to [main] frame` |
166
+
167
+ ### Tags
168
+
169
+ | Tag | Purpose |
170
+ |---|---|
171
+ | `@auth:role` | Use Playwright storage state for auth |
172
+ | `@steps:name` | Define reusable step group |
173
+ | `@extend:name` | Inherit steps from another scenario |
174
+ | `@manual` | Skip scenario in generation |
175
+
176
+ ### Selector YAML
177
+
178
+ ```yaml
179
+ submit.button:
180
+ type: 'role' # testid, role, text, label, placeholder, locator, page
181
+ value: 'button' # role name, testid value, CSS selector, etc.
182
+ name: 'Submit' # accessible name
183
+ nth: 0 # element index (0=first, 1=.nth(0), 2=.nth(1))
184
+ exact: true # exact name match (avoid "Submit" matching "Submit Form")
185
+ scope: 'desktop navigation' # scope to parent landmark
186
+ match: 'exact' # exact text match for getByText
187
+ ```
188
+
189
+ Locator priority: `data-testid` > `role+name` > `label` > `text` > `CSS`
190
+
191
+ ---
192
+
193
+ ## Documentation
194
+
195
+ - [Gherkin Dictionary](docs/gherkin-dictionary.md) — full grammar, all 17 patterns, compiler rules
196
+ - [Sungen GitHub](https://github.com/sun-asterisk/sungen)
197
+ - [Playwright Documentation](https://playwright.dev)