@testspectra/skills 1.1.8-rc.2 → 1.1.8-rc.21

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.
@@ -1,193 +1,193 @@
1
- ---
2
- name: workspace-structure
3
- description: TestSpectra workspace layout, zero-import ambient type architecture, platform file suffixes (web/android/ios/mobile/common), spectra.config.ts, and the core spectra CLI commands. Use before scaffolding any new TestSpectra project or file so it lands in the right directory with the right suffix.
4
- ---
5
-
6
- # Skill: TestSpectra Workspace Structure & Zero-Import Architecture
7
-
8
- Use this skill whenever you scaffold a new TestSpectra workspace, add a new file to an existing
9
- one, or need to decide where a Page Object / Step / Action / Hook / Fixture belongs.
10
-
11
- ---
12
-
13
- ## 1. Core Philosophy: Git-First, Spec-as-Code
14
-
15
- Every test case, shared step, Page Object, fixture, and config file is a plain TypeScript or
16
- Markdown file tracked in git — there is no proprietary binary project format. TestSpectra supports
17
- two workspace paradigms:
18
-
19
- 1. **Default Project Mode** (`spectra init`, single-root repo) — one app, one `spectra.config.ts`.
20
- 2. **Monorepo / Nx Project Mode** (`spectra init --template nx`) — multiple `packages/*` test
21
- projects sharing a library under `shared/testing` (or a custom path), wired into
22
- `pnpm-workspace.yaml`.
23
-
24
- Never guess which mode a repo uses — check for `nx.json` / `pnpm-workspace.yaml` with a
25
- `packages:` list first.
26
-
27
- ---
28
-
29
- ## 2. Default Workspace Directory Layout
30
-
31
- ```
32
- my-test-project/
33
- ├── .testspectra/ # Auto-managed. NEVER hand-edit these files.
34
- │ ├── tsconfig/ # web.json, mobile.json, android.json, ios.json, common.json
35
- │ ├── types/ # web.d.ts, mobile.d.ts, android.d.ts, ios.d.ts, common.d.ts,
36
- │ │ # fixtures.d.ts — ambient globals (Spectra, Step, Fixture, POs)
37
- │ └── reports/ # report.json, network-resources.json, last-run.json
38
- │
39
- ├── specs/ # Test suites & test cases (Spec-as-Code)
40
- │ └── <SuiteName>/
41
- │ ├── suite.md # Suite metadata (id, name, executionOrder, parallel)
42
- │ ├── hooks/ # Suite-level lifecycle hooks (before/beforeEach/afterEach/after)
43
- │ └── TC-<NNNN>-<slug>/ # One directory per test case
44
- │ ├── spec.md # Frontmatter + "## Test Steps" with @step:<name> directives
45
- │ ├── web.test.ts # and/or android.test.ts / ios.test.ts / mobile.test.ts / common.test.ts
46
- │
47
- ├── page-objects/ # Page Object Model singletons
48
- │ └── <PageName>/
49
- │ ├── web.ts
50
- │ └── mobile.ts # (or android.ts / ios.ts)
51
- │
52
- ├── support/
53
- │ ├── steps/ # High-level reusable business workflows (Step.*)
54
- │ │ └── <stepName>/
55
- │ │ ├── step.md
56
- │ │ ├── web.step.ts
57
- │ │ └── mobile.step.ts
58
- │ └── actions/ # Low-level technical utilities (Spectra.<action>())
59
- │ └── <actionName>/
60
- │ ├── web.action.ts
61
- │ └── mobile.action.ts
62
- │
63
- ├── fixtures/ # JSON/CSV test data, auto-typed under Fixture.*
64
- │ └── users.json
65
- │
66
- ├── global-hooks/ # Workspace-wide hooks, run once per Global Batch Run only
67
- │ ├── before/
68
- │ └── after/
69
- │
70
- ├── spectra.config.ts # Single source of truth for execution settings
71
- ├── tsconfig.json # References ./.testspectra/tsconfig.json — do not add "include"
72
- └── package.json # Has "postinstall": "spectra sync-types"
73
- ```
74
-
75
- For the Nx/monorepo variant, each `packages/<project>/` is its own self-contained workspace
76
- (`specs/`, `page-objects/`, `spectra.config.ts`, `package.json`), and a shared library
77
- (default `shared/testing/`) holds cross-project Page Objects/Steps/Actions/Fixtures. **Never** put
78
- a `specs/` directory or a `spec.md`/`suite.md` file inside the shared library — the linter rejects
79
- it (`testspectra/no-specs-in-shared-lib`).
80
-
81
- ---
82
-
83
- ## 3. Zero-Import Rule (Non-Negotiable)
84
-
85
- TestSpectra scripts **never** contain a manual `import` statement for framework entities. Page
86
- Objects, `Step.*`, `Fixture.*`, and the global `Spectra` object are all injected as ambient
87
- globals via `.testspectra/types/*.d.ts`, which the CLI regenerates automatically (sub-60ms) when
88
- you add/rename files under `page-objects/`, `support/`, or `fixtures/`.
89
-
90
- - ❌ `import LoginPage from '../../page-objects/LoginPage';`
91
- - ✅ Just reference `LoginPage` directly — it resolves globally.
92
-
93
- Adding an `import` in a `*.test.ts`, `*.step.ts`, `*.action.ts`, `*.hook.ts`, or Page Object file
94
- triggers linter rule `testspectra/no-manual-import` (error). If a file's types look stale after you
95
- add a new Page Object/Step/Fixture, run `spectra sync-types` rather than importing manually.
96
-
97
- ---
98
-
99
- ## 4. Platform File Suffixes
100
-
101
- | Suffix | Target | Can access |
102
- | :------------ | :-------------------------- | :-------------------------------------------- |
103
- | `*.web.*` | Web (Chrome CDP) | web + common |
104
- | `*.android.*` | Android (native TCP driver) | android + mobile + common |
105
- | `*.ios.*` | iOS (XCUITest) | ios + mobile + common |
106
- | `*.mobile.*` | Shared Android & iOS | mobile + common only (no web, no android/ios) |
107
- | `*.common.*` | Universal (web + mobile) | common only (strictest isolation) |
108
-
109
- This applies to test scripts (`web.test.ts`), Page Objects (`web.ts`), steps (`web.step.ts`),
110
- actions (`web.action.ts`), and hooks (`web.hook.ts`). Pick the narrowest suffix that fits — don't
111
- write a `mobile.test.ts` for something that is actually web-only.
112
-
113
- ---
114
-
115
- ## 5. `spectra.config.ts`
116
-
117
- ```typescript
118
- import { defineConfig } from '@testspectra/cli';
119
-
120
- export default defineConfig({
121
- webConfig: {
122
- baseUrl: 'http://localhost:5173',
123
- maxConcurrentSessions: '1',
124
- headless: true,
125
- implicitWait: '5000',
126
- parallelizationMode: 'testcase', // "testcase" | "suite"
127
- },
128
- androidConfig: {
129
- driverServer: 'tcp://127.0.0.1:8200',
130
- appPackage: 'dev.example.app',
131
- appActivity: 'dev.example.app.MainActivity',
132
- noReset: false,
133
- implicitWait: '10000',
134
- parallelizationMode: 'suite',
135
- devices: [{ id: 'emulator-5554', name: 'Pixel 8a Emulator', version: '14.0', systemPort: 8200 }],
136
- },
137
- iosConfig: {
138
- appiumServer: 'http://127.0.0.1:4723',
139
- automationName: 'XCUITest',
140
- bundleId: '',
141
- autoAcceptAlerts: true,
142
- noReset: false,
143
- implicitWait: '10000',
144
- parallelizationMode: 'suite',
145
- devices: [
146
- { id: 'iphone-15-pro', name: 'iPhone 15 Pro Simulator', version: '17.0', udid: 'auto', wdaLocalPort: 8100 },
147
- ],
148
- },
149
- executionConfig: {
150
- networkMonitoringEnabled: true,
151
- fastResponseTime: '200',
152
- normalResponseTime: '1000',
153
- monitoredDomains: [{ domain: 'api.example.com', enabled: true }],
154
- environmentVariables: { API_MODE: 'sandbox' },
155
- },
156
- });
157
- ```
158
-
159
- Numeric-looking fields (timeouts, ports, session counts) accept either a `number` or a numeric
160
- `string` — stay consistent with whatever the rest of the file already uses.
161
-
162
- `executionConfig` notes:
163
-
164
- - **`monitoredDomains`**: empty/absent = record every domain; non-empty = only requests matching
165
- an `enabled: true` entry (exact hostname or leading-`*` wildcard) get recorded/streamed to the
166
- Network panel. `networkMonitoringEnabled: false` disables recording outright regardless of this
167
- list.
168
- - **`fastResponseTime`/`normalResponseTime`**: millisecond thresholds the VS Code Network panel
169
- uses to color each request's Duration cell (fast/normal/slow). No effect on test execution
170
- itself.
171
- - **`environmentVariables`**: a flat `Record<string, string>` (not an array, not nested
172
- key/value pairs) — every key becomes both a typed `Spectra.env.KEY` entry (generated into
173
- `.testspectra/types/env.d.ts`, autocompleted, zero-import — **prefer this over `process.env`**,
174
- which is untyped `string | undefined`) and a plain `process.env.KEY` string for code that must
175
- consume the untyped standard API.
176
-
177
- ---
178
-
179
- ## 6. Core `spectra` CLI Commands
180
-
181
- | Command | Purpose |
182
- | :--------------------------------------------------- | :------------------------------------------------------------------------------------------------------ |
183
- | `spectra init [--template nx]` | Scaffold a new workspace |
184
- | `spectra sync-types` | Regenerate `.testspectra/types` and `.testspectra/tsconfig` (also runs on `postinstall` and file-watch) |
185
- | `spectra run [path] -t <web\|mobile\|android\|ios>` | Execute tests |
186
- | `spectra lint [path] [--strict] [--json]` | Validate `spec.md`/`suite.md` schema + code parity (see the `spec-and-suite-authoring` skill) |
187
- | `spectra doctor` | Preflight dependency/environment health check |
188
- | `spectra refactor step\|action\|fixture <old> <new>` | Atomically rename across folder, metadata, and all call sites |
189
- | `spectra watch` | Background file watcher driving `sync-types` |
190
-
191
- After scaffolding or renaming any file under `page-objects/`, `support/`, or `fixtures/`, assume
192
- the ambient types are stale until `sync-types` (or the watcher) has run — don't hand-write
193
- `.testspectra/types/*.d.ts` yourself.
1
+ ---
2
+ name: workspace-structure
3
+ description: TestSpectra workspace layout, zero-import ambient type architecture, platform file suffixes (web/android/ios/mobile/common), spectra.config.ts, and the core spectra CLI commands. Use before scaffolding any new TestSpectra project or file so it lands in the right directory with the right suffix.
4
+ ---
5
+
6
+ # Skill: TestSpectra Workspace Structure & Zero-Import Architecture
7
+
8
+ Use this skill whenever you scaffold a new TestSpectra workspace, add a new file to an existing
9
+ one, or need to decide where a Page Object / Step / Action / Hook / Fixture belongs.
10
+
11
+ ---
12
+
13
+ ## 1. Core Philosophy: Git-First, Spec-as-Code
14
+
15
+ Every test case, shared step, Page Object, fixture, and config file is a plain TypeScript or
16
+ Markdown file tracked in git — there is no proprietary binary project format. TestSpectra supports
17
+ two workspace paradigms:
18
+
19
+ 1. **Default Project Mode** (`spectra init`, single-root repo) — one app, one `spectra.config.ts`.
20
+ 2. **Monorepo / Nx Project Mode** (`spectra init --template nx`) — multiple `packages/*` test
21
+ projects sharing a library under `shared/testing` (or a custom path), wired into
22
+ `pnpm-workspace.yaml`.
23
+
24
+ Never guess which mode a repo uses — check for `nx.json` / `pnpm-workspace.yaml` with a
25
+ `packages:` list first.
26
+
27
+ ---
28
+
29
+ ## 2. Default Workspace Directory Layout
30
+
31
+ ```
32
+ my-test-project/
33
+ ├── .testspectra/ # Auto-managed. NEVER hand-edit these files.
34
+ │ ├── tsconfig/ # web.json, mobile.json, android.json, ios.json, common.json
35
+ │ ├── types/ # web.d.ts, mobile.d.ts, android.d.ts, ios.d.ts, common.d.ts,
36
+ │ │ # fixtures.d.ts — ambient globals (Spectra, Step, Fixture, POs)
37
+ │ └── reports/ # report.json, network-resources.json, last-run.json
38
+ │
39
+ ├── specs/ # Test suites & test cases (Spec-as-Code)
40
+ │ └── <SuiteName>/
41
+ │ ├── suite.md # Suite metadata (id, name, executionOrder, parallel)
42
+ │ ├── hooks/ # Suite-level lifecycle hooks (before/beforeEach/afterEach/after)
43
+ │ └── TC-<NNNN>-<slug>/ # One directory per test case
44
+ │ ├── spec.md # Frontmatter + "## Test Steps" with @step:<name> directives
45
+ │ ├── web.test.ts # and/or android.test.ts / ios.test.ts / mobile.test.ts / common.test.ts
46
+ │
47
+ ├── page-objects/ # Page Object Model singletons
48
+ │ └── <PageName>/
49
+ │ ├── web.ts
50
+ │ └── mobile.ts # (or android.ts / ios.ts)
51
+ │
52
+ ├── support/
53
+ │ ├── steps/ # High-level reusable business workflows (Step.*)
54
+ │ │ └── <stepName>/
55
+ │ │ ├── step.md
56
+ │ │ ├── web.step.ts
57
+ │ │ └── mobile.step.ts
58
+ │ └── actions/ # Low-level technical utilities (Spectra.<action>())
59
+ │ └── <actionName>/
60
+ │ ├── web.action.ts
61
+ │ └── mobile.action.ts
62
+ │
63
+ ├── fixtures/ # JSON/CSV test data, auto-typed under Fixture.*
64
+ │ └── users.json
65
+ │
66
+ ├── global-hooks/ # Workspace-wide hooks, run once per Global Batch Run only
67
+ │ ├── before/
68
+ │ └── after/
69
+ │
70
+ ├── spectra.config.ts # Single source of truth for execution settings
71
+ ├── tsconfig.json # References ./.testspectra/tsconfig.json — do not add "include"
72
+ └── package.json # Has "postinstall": "spectra sync-types"
73
+ ```
74
+
75
+ For the Nx/monorepo variant, each `packages/<project>/` is its own self-contained workspace
76
+ (`specs/`, `page-objects/`, `spectra.config.ts`, `package.json`), and a shared library
77
+ (default `shared/testing/`) holds cross-project Page Objects/Steps/Actions/Fixtures. **Never** put
78
+ a `specs/` directory or a `spec.md`/`suite.md` file inside the shared library — the linter rejects
79
+ it (`testspectra/no-specs-in-shared-lib`).
80
+
81
+ ---
82
+
83
+ ## 3. Zero-Import Rule (Non-Negotiable)
84
+
85
+ TestSpectra scripts **never** contain a manual `import` statement for framework entities. Page
86
+ Objects, `Step.*`, `Fixture.*`, and the global `Spectra` object are all injected as ambient
87
+ globals via `.testspectra/types/*.d.ts`, which the CLI regenerates automatically (sub-60ms) when
88
+ you add/rename files under `page-objects/`, `support/`, or `fixtures/`.
89
+
90
+ - ❌ `import LoginPage from '../../page-objects/LoginPage';`
91
+ - ✅ Just reference `LoginPage` directly — it resolves globally.
92
+
93
+ Adding an `import` in a `*.test.ts`, `*.step.ts`, `*.action.ts`, `*.hook.ts`, or Page Object file
94
+ triggers linter rule `testspectra/no-manual-import` (error). If a file's types look stale after you
95
+ add a new Page Object/Step/Fixture, run `spectra sync-types` rather than importing manually.
96
+
97
+ ---
98
+
99
+ ## 4. Platform File Suffixes
100
+
101
+ | Suffix | Target | Can access |
102
+ | :------------ | :-------------------------- | :-------------------------------------------- |
103
+ | `*.web.*` | Web (Chrome CDP) | web + common |
104
+ | `*.android.*` | Android (native TCP driver) | android + mobile + common |
105
+ | `*.ios.*` | iOS (XCUITest) | ios + mobile + common |
106
+ | `*.mobile.*` | Shared Android & iOS | mobile + common only (no web, no android/ios) |
107
+ | `*.common.*` | Universal (web + mobile) | common only (strictest isolation) |
108
+
109
+ This applies to test scripts (`web.test.ts`), Page Objects (`web.ts`), steps (`web.step.ts`),
110
+ actions (`web.action.ts`), and hooks (`web.hook.ts`). Pick the narrowest suffix that fits — don't
111
+ write a `mobile.test.ts` for something that is actually web-only.
112
+
113
+ ---
114
+
115
+ ## 5. `spectra.config.ts`
116
+
117
+ ```typescript
118
+ import { defineConfig } from '@testspectra/cli';
119
+
120
+ export default defineConfig({
121
+ webConfig: {
122
+ baseUrl: 'http://localhost:5173',
123
+ maxConcurrentSessions: '1',
124
+ headless: true,
125
+ implicitWait: '5000',
126
+ parallelizationMode: 'testcase', // "testcase" | "suite"
127
+ },
128
+ androidConfig: {
129
+ driverServer: 'tcp://127.0.0.1:8200',
130
+ appPackage: 'dev.example.app',
131
+ appActivity: 'dev.example.app.MainActivity',
132
+ noReset: false,
133
+ implicitWait: '10000',
134
+ parallelizationMode: 'suite',
135
+ devices: [{ id: 'emulator-5554', name: 'Pixel 8a Emulator', version: '14.0', systemPort: 8200 }],
136
+ },
137
+ iosConfig: {
138
+ appiumServer: 'http://127.0.0.1:4723',
139
+ automationName: 'XCUITest',
140
+ bundleId: '',
141
+ autoAcceptAlerts: true,
142
+ noReset: false,
143
+ implicitWait: '10000',
144
+ parallelizationMode: 'suite',
145
+ devices: [
146
+ { id: 'iphone-15-pro', name: 'iPhone 15 Pro Simulator', version: '17.0', udid: 'auto', wdaLocalPort: 8100 },
147
+ ],
148
+ },
149
+ executionConfig: {
150
+ networkMonitoringEnabled: true,
151
+ fastResponseTime: '200',
152
+ normalResponseTime: '1000',
153
+ monitoredDomains: [{ domain: 'api.example.com', enabled: true }],
154
+ environmentVariables: { API_MODE: 'sandbox' },
155
+ },
156
+ });
157
+ ```
158
+
159
+ Numeric-looking fields (timeouts, ports, session counts) accept either a `number` or a numeric
160
+ `string` — stay consistent with whatever the rest of the file already uses.
161
+
162
+ `executionConfig` notes:
163
+
164
+ - **`monitoredDomains`**: empty/absent = record every domain; non-empty = only requests matching
165
+ an `enabled: true` entry (exact hostname or leading-`*` wildcard) get recorded/streamed to the
166
+ Network panel. `networkMonitoringEnabled: false` disables recording outright regardless of this
167
+ list.
168
+ - **`fastResponseTime`/`normalResponseTime`**: millisecond thresholds the VS Code Network panel
169
+ uses to color each request's Duration cell (fast/normal/slow). No effect on test execution
170
+ itself.
171
+ - **`environmentVariables`**: a flat `Record<string, string>` (not an array, not nested
172
+ key/value pairs) — every key becomes both a typed `Spectra.env.KEY` entry (generated into
173
+ `.testspectra/types/env.d.ts`, autocompleted, zero-import — **prefer this over `process.env`**,
174
+ which is untyped `string | undefined`) and a plain `process.env.KEY` string for code that must
175
+ consume the untyped standard API.
176
+
177
+ ---
178
+
179
+ ## 6. Core `spectra` CLI Commands
180
+
181
+ | Command | Purpose |
182
+ | :--------------------------------------------------- | :------------------------------------------------------------------------------------------------------ |
183
+ | `spectra init [--template nx]` | Scaffold a new workspace |
184
+ | `spectra sync-types` | Regenerate `.testspectra/types` and `.testspectra/tsconfig` (also runs on `postinstall` and file-watch) |
185
+ | `spectra run [path] -t <web\|mobile\|android\|ios>` | Execute tests |
186
+ | `spectra lint [path] [--strict] [--json]` | Validate `spec.md`/`suite.md` schema + code parity (see the `spec-and-suite-authoring` skill) |
187
+ | `spectra doctor` | Preflight dependency/environment health check |
188
+ | `spectra refactor step\|action\|fixture <old> <new>` | Atomically rename across folder, metadata, and all call sites |
189
+ | `spectra watch` | Background file watcher driving `sync-types` |
190
+
191
+ After scaffolding or renaming any file under `page-objects/`, `support/`, or `fixtures/`, assume
192
+ the ambient types are stale until `sync-types` (or the watcher) has run — don't hand-write
193
+ `.testspectra/types/*.d.ts` yourself.