@testspectra/skills 1.1.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.
Files changed (36) hide show
  1. package/LICENSE.md +48 -0
  2. package/README.md +78 -0
  3. package/bin/spectra-skills.js +7 -0
  4. package/dist/commands/add.d.ts +1 -0
  5. package/dist/commands/add.js +44 -0
  6. package/dist/commands/init.d.ts +1 -0
  7. package/dist/commands/init.js +54 -0
  8. package/dist/commands/list.d.ts +1 -0
  9. package/dist/commands/list.js +22 -0
  10. package/dist/commands/remove.d.ts +1 -0
  11. package/dist/commands/remove.js +26 -0
  12. package/dist/commands/update.d.ts +1 -0
  13. package/dist/commands/update.js +30 -0
  14. package/dist/detector.d.ts +35 -0
  15. package/dist/detector.js +129 -0
  16. package/dist/index.d.ts +8 -0
  17. package/dist/index.js +119 -0
  18. package/dist/registry.d.ts +8 -0
  19. package/dist/registry.js +48 -0
  20. package/dist/skills/fixtures-data/SKILL.md +109 -0
  21. package/dist/skills/lifecycle-hooks/SKILL.md +114 -0
  22. package/dist/skills/matchers-and-assertions/SKILL.md +123 -0
  23. package/dist/skills/network-interception/SKILL.md +115 -0
  24. package/dist/skills/page-objects-and-selectors/SKILL.md +107 -0
  25. package/dist/skills/shared-steps-and-actions/SKILL.md +184 -0
  26. package/dist/skills/spec-and-suite-authoring/SKILL.md +132 -0
  27. package/dist/skills/workspace-structure/SKILL.md +181 -0
  28. package/package.json +59 -0
  29. package/skills/fixtures-data/SKILL.md +109 -0
  30. package/skills/lifecycle-hooks/SKILL.md +114 -0
  31. package/skills/matchers-and-assertions/SKILL.md +123 -0
  32. package/skills/network-interception/SKILL.md +115 -0
  33. package/skills/page-objects-and-selectors/SKILL.md +107 -0
  34. package/skills/shared-steps-and-actions/SKILL.md +184 -0
  35. package/skills/spec-and-suite-authoring/SKILL.md +132 -0
  36. package/skills/workspace-structure/SKILL.md +181 -0
@@ -0,0 +1,132 @@
1
+ ---
2
+ name: spec-and-suite-authoring
3
+ description: How to write suite.md, spec.md, and the paired *.test.ts execution script for a TestSpectra test case — frontmatter schema, the @step directive convention, and every spec-schema-linter rule that must pass (single it(), no describe/test, zero-import, title parity). Use whenever creating or editing a test case.
4
+ ---
5
+
6
+ # Skill: Spec & Suite Authoring (`spec.md`, `suite.md`, `*.test.ts`)
7
+
8
+ Use this skill whenever you create a new test case, add a new suite, or edit an existing
9
+ `spec.md` / `*.test.ts` pair. TestSpectra treats the Markdown spec as the human-readable source of
10
+ truth and the TypeScript file as its execution — the CLI linter (`spectra lint`) enforces that the
11
+ two never drift apart.
12
+
13
+ ---
14
+
15
+ ## 1. Directory Convention
16
+
17
+ ```
18
+ specs/<SuiteName>/suite.md
19
+ specs/<SuiteName>/hooks/{before,beforeEach,afterEach,after}/web.hook.ts
20
+ specs/<SuiteName>/TC-<NNNN>-<kebab-slug>/spec.md
21
+ specs/<SuiteName>/TC-<NNNN>-<kebab-slug>/web.test.ts # + android/ios/mobile/common variants
22
+ ```
23
+
24
+ `SuiteName` is a directory (no `describe()` block ever exists in code — the suite boundary is
25
+ purely the folder). The test case id (`TC-0001-valid-login`) is both the directory name and the
26
+ `id` in `spec.md`'s frontmatter, and must be unique across the entire workspace
27
+ (`testspectra/duplicate-spec-id`).
28
+
29
+ ---
30
+
31
+ ## 2. `suite.md` Frontmatter
32
+
33
+ ```markdown
34
+ ---
35
+ name: Untitled Suite
36
+ id: suite-element-matchers
37
+ description: Element visibility, existence, form states and attributes
38
+ executionOrder: 1.0
39
+ parallel: true
40
+ ---
41
+
42
+ # Suite: ElementMatchers
43
+ ```
44
+
45
+ ---
46
+
47
+ ## 3. `spec.md` Frontmatter & Body
48
+
49
+ ```markdown
50
+ ---
51
+ id: TC-0003-visibility-and-dom
52
+ title: Verify element visibility and existence matchers
53
+ priority: High
54
+ caseType: Positive
55
+ status: ready-for-automation
56
+ coverage:
57
+ web: automated
58
+ mobile: automated
59
+ ---
60
+
61
+ # Verify element visibility and existence matchers
62
+
63
+ ## Test Steps
64
+
65
+ 1. Open visibility section in matchers page
66
+ 2. Assert visible element has be.visible state
67
+ 3. Assert existing element exists in DOM
68
+ ```
69
+
70
+ Required frontmatter: `id`, `title`, `priority`, `caseType`, `status` — missing any of these, or
71
+ missing the `# <Title>` / `## Test Steps` headings, triggers `testspectra/missing-frontmatter`.
72
+ Invalid enum values (an unrecognized `priority`, `caseType`, or `status`) trigger
73
+ `testspectra/invalid-frontmatter-enum`.
74
+
75
+ If the test case invokes a shared step (see the `shared-steps-and-actions` skill), reference it in
76
+ the `## Test Steps` list as `@step:<stepName>` — the linter cross-checks this against
77
+ `Step.<stepName>()` calls in the paired `*.test.ts`.
78
+
79
+ ---
80
+
81
+ ## 4. The Paired Test Script (`web.test.ts`)
82
+
83
+ ```typescript
84
+ it('Verify element visibility and existence matchers', async () => {
85
+ await MatchersPage.open('visibility');
86
+
87
+ await MatchersPage.visibleElement.shouldBeVisible();
88
+ await MatchersPage.hiddenElement.shouldNotBeVisible();
89
+
90
+ await MatchersPage.existingElement.shouldExist();
91
+ await Spectra.get('#demo-non-existent-el').shouldNotExist();
92
+ });
93
+ ```
94
+
95
+ ### Hard rules (each is a `spectra lint` error unless noted):
96
+
97
+ 1. **Exactly one `it(...)` block, nothing else at the top level.** Zero or multiple `it()` blocks
98
+ → `testspectra/single-it-required`.
99
+ 2. **Never `test(...)`.** Only `it(...)` is allowed → `testspectra/no-test-block`.
100
+ 3. **Never `describe(...)`.** Suite grouping is the directory, not code →
101
+ `testspectra/no-describe-block`.
102
+ 4. **Zero manual `import`s.** See the `workspace-structure` skill →
103
+ `testspectra/no-manual-import`.
104
+ 5. **`it()`'s title should read the same as `spec.md`'s `title`** (case-insensitive semantic
105
+ match). A mismatch is a warning, not an error → `testspectra/title-mismatch`.
106
+ 6. **Every `@step:<name>` in `spec.md` must have a matching `Step.<name>()` call** in the test
107
+ script → `testspectra/missing-step-call` (error) if absent, and conversely a `Step.<name>()`
108
+ call not documented with `@step:<name>` in `spec.md` is
109
+ `testspectra/undocumented-step` (warning).
110
+
111
+ ### Platform variants
112
+
113
+ A test case directory may contain any combination of `web.test.ts`, `android.test.ts`,
114
+ `ios.test.ts`, `mobile.test.ts`, `common.test.ts` — each is linted and can be run independently.
115
+ Reuse a shared step for the parts of the flow that are identical across platforms rather than
116
+ duplicating the `it()` body per platform.
117
+
118
+ ---
119
+
120
+ ## 5. Running the Linter
121
+
122
+ - `spectra lint` — scan the whole workspace, human-readable output.
123
+ - `spectra lint --strict` — treat warnings as errors, exit code `1` on any diagnostic (use this in
124
+ CI).
125
+ - `spectra lint --json` — machine-readable diagnostics (what an AI agent should parse to
126
+ self-correct after generating a spec).
127
+ - `spectra lint <path>` — scan a single suite or test case folder.
128
+
129
+ Exit codes: `0` valid, `1` violations found, `2` fatal (malformed YAML/JSON).
130
+
131
+ After authoring or editing a `spec.md`/`*.test.ts` pair, run `spectra lint <path-to-that-case>`
132
+ before considering the task done.
@@ -0,0 +1,181 @@
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
+ pageLoadTimeout: '30000',
127
+ scriptTimeout: '30000',
128
+ parallelizationMode: 'testcase', // "testcase" | "suite"
129
+ },
130
+ browsers: [{ id: 'chrome-desktop', type: 'chrome', mobileEmulation: false }],
131
+ androidConfig: {
132
+ driverServer: 'tcp://127.0.0.1:8200',
133
+ appPackage: 'dev.example.app',
134
+ appActivity: 'dev.example.app.MainActivity',
135
+ noReset: false,
136
+ implicitWait: '10000',
137
+ parallelizationMode: 'suite',
138
+ devices: [{ id: 'emulator-5554', name: 'Pixel 8a Emulator', version: '14.0', systemPort: 8200 }],
139
+ },
140
+ iosConfig: {
141
+ appiumServer: 'http://127.0.0.1:4723',
142
+ automationName: 'XCUITest',
143
+ bundleId: '',
144
+ autoAcceptAlerts: true,
145
+ noReset: false,
146
+ implicitWait: '10000',
147
+ parallelizationMode: 'suite',
148
+ devices: [
149
+ { id: 'iphone-15-pro', name: 'iPhone 15 Pro Simulator', version: '17.0', udid: 'auto', wdaLocalPort: 8100 },
150
+ ],
151
+ },
152
+ executionConfig: {
153
+ networkMonitoringEnabled: true,
154
+ fastResponseTime: '200',
155
+ normalResponseTime: '1000',
156
+ monitoredDomains: [],
157
+ environmentVariables: [],
158
+ },
159
+ });
160
+ ```
161
+
162
+ Numeric-looking fields (timeouts, ports, session counts) accept either a `number` or a numeric
163
+ `string` — stay consistent with whatever the rest of the file already uses.
164
+
165
+ ---
166
+
167
+ ## 6. Core `spectra` CLI Commands
168
+
169
+ | Command | Purpose |
170
+ | :--------------------------------------------------- | :------------------------------------------------------------------------------------------------------ |
171
+ | `spectra init [--template nx]` | Scaffold a new workspace |
172
+ | `spectra sync-types` | Regenerate `.testspectra/types` and `.testspectra/tsconfig` (also runs on `postinstall` and file-watch) |
173
+ | `spectra run [path] -t <web\|mobile\|android\|ios>` | Execute tests |
174
+ | `spectra lint [path] [--strict] [--json]` | Validate `spec.md`/`suite.md` schema + code parity (see the `spec-and-suite-authoring` skill) |
175
+ | `spectra doctor` | Preflight dependency/environment health check |
176
+ | `spectra refactor step\|action\|fixture <old> <new>` | Atomically rename across folder, metadata, and all call sites |
177
+ | `spectra watch` | Background file watcher driving `sync-types` |
178
+
179
+ After scaffolding or renaming any file under `page-objects/`, `support/`, or `fixtures/`, assume
180
+ the ambient types are stale until `sync-types` (or the watcher) has run — don't hand-write
181
+ `.testspectra/types/*.d.ts` yourself.