@testspectra/matchers 1.1.14 → 1.2.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.
@@ -101,6 +101,7 @@ export interface PlatformDriverBridge extends SpectraBrowserBridge {
101
101
  select(selector: string | ScopedSelector, option: string, index?: number | null): Promise<void>;
102
102
  hover(selector: string | ScopedSelector, index?: number | null): Promise<void>;
103
103
  focus(selector: string | ScopedSelector, index?: number | null): Promise<void>;
104
+ blur(selector: string | ScopedSelector, index?: number | null): Promise<void>;
104
105
  dragDrop(sourceSelector: string | ScopedSelector, targetSelector: string, sourceIndex?: number | null): Promise<void>;
105
106
  longPress(selector: string | ScopedSelector, duration: number, index?: number | null): Promise<void>;
106
107
  scrollIntoView(selector: string | ScopedSelector, index?: number | null): Promise<void>;
package/dist/types.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Canonical action keys supported across TestSpectra runner and database models.
3
3
  * @see backend/src/models/test_step.rs
4
4
  */
5
- export type ActionKey = 'navigate' | 'click' | 'type' | 'clear' | 'select' | 'scroll' | 'swipe' | 'wait' | 'waitForElement' | 'pressKey' | 'longPress' | 'doubleClick' | 'hover' | 'dragDrop' | 'upload' | 'back' | 'refresh';
5
+ export type ActionKey = 'navigate' | 'click' | 'type' | 'clear' | 'select' | 'scroll' | 'swipe' | 'wait' | 'waitForElement' | 'pressKey' | 'longPress' | 'doubleClick' | 'hover' | 'focus' | 'blur' | 'dragDrop' | 'upload' | 'back' | 'refresh';
6
6
  /**
7
7
  * Canonical assertion keys supported across TestSpectra runner and database models.
8
8
  * @see backend/src/models/test_step.rs
@@ -741,6 +741,15 @@ export interface SingleElementProxy extends ElementReceiverAssertions<Promise<vo
741
741
  * ```
742
742
  */
743
743
  focus(): Promise<void>;
744
+ /**
745
+ * Removes focus from the target element (blurs it).
746
+ *
747
+ * @example
748
+ * ```ts
749
+ * await Spectra.get('#email-input').blur();
750
+ * ```
751
+ */
752
+ blur(): Promise<void>;
744
753
  /**
745
754
  * Moves the mouse cursor to the element (alias to `hover()`).
746
755
  */
@@ -1153,6 +1162,53 @@ export interface CDPNetworkEntry {
1153
1162
  /** Start timestamp epoch. */
1154
1163
  startTime: number;
1155
1164
  }
1165
+ /**
1166
+ * A user- or library-registered command callable on the global `Spectra` object.
1167
+ *
1168
+ * Commands are registered at runtime via `Spectra.registerCommand()` (typically from a plugin's
1169
+ * `setup()`), and their types are exposed to consumers through TypeScript module augmentation of
1170
+ * `SpectraStatic` — there is no type-generator integration for external plugins.
1171
+ */
1172
+ export type SpectraCommand = (...args: any[]) => any;
1173
+ /**
1174
+ * Context passed to a plugin's `setup()`. Plugins use `platform` to register only the commands
1175
+ * that are valid for the active target.
1176
+ */
1177
+ export interface SpectraPluginContext {
1178
+ /** Active execution platform: `'web'`, `'android'`, or `'ios'`. */
1179
+ platform: string;
1180
+ }
1181
+ /**
1182
+ * A TestSpectra plugin. A plugin is any external library that extends the `Spectra` DSL — its
1183
+ * `setup` receives the live `Spectra` object and registers commands (or performs other one-time
1184
+ * wiring) before test files are imported.
1185
+ *
1186
+ * Plugins are declared in `spectra.config.ts` under `executionConfig.plugins` as module specifiers
1187
+ * and loaded by both the native E2E worker and the component-testing runtime. Platform-specific
1188
+ * command **types** are shipped as per-stem subpath entries (`./web`, `./android`, `./ios`,
1189
+ * `./mobile`, `./common`) and wired into the generated ambient declarations by the type generator.
1190
+ *
1191
+ * @example
1192
+ * ```ts
1193
+ * import type { SpectraPlugin } from '@testspectra/matchers';
1194
+ *
1195
+ * const plugin: SpectraPlugin = {
1196
+ * name: 'my-plugin',
1197
+ * setup(spectra, { platform }) {
1198
+ * spectra.registerCommand('findButton', (selector: string) => spectra.get(selector));
1199
+ * if (platform === 'web') spectra.registerCommand('findByCss', (s: string) => spectra.get(s));
1200
+ * },
1201
+ * };
1202
+ *
1203
+ * export default plugin;
1204
+ * ```
1205
+ */
1206
+ export interface SpectraPlugin {
1207
+ /** Unique plugin identifier, used for diagnostics. */
1208
+ name: string;
1209
+ /** One-time wiring executed after `Spectra` is built and before test files are imported. */
1210
+ setup(spectra: SpectraStatic, context: SpectraPluginContext): void | Promise<void>;
1211
+ }
1156
1212
  /**
1157
1213
  * Main TestSpectra cross-platform automation and assertion interface contract.
1158
1214
  */
@@ -1316,6 +1372,16 @@ export interface SpectraStatic {
1316
1372
  * ```
1317
1373
  */
1318
1374
  focus(target: ElementTarget): Promise<void>;
1375
+ /**
1376
+ * Removes focus from the target element (blurs it).
1377
+ *
1378
+ * @param target Target element selector or proxy.
1379
+ * @example
1380
+ * ```ts
1381
+ * await Spectra.blur('#email-input');
1382
+ * ```
1383
+ */
1384
+ blur(target: ElementTarget): Promise<void>;
1319
1385
  /**
1320
1386
  * Drags a source element and drops it onto a destination element target.
1321
1387
  *
@@ -1459,4 +1525,32 @@ export interface SpectraStatic {
1459
1525
  * ```
1460
1526
  */
1461
1527
  clearMocks(): void;
1528
+ /**
1529
+ * Registers a custom command on the `Spectra` object, making it callable as
1530
+ * `Spectra.<name>(...)`. Intended for plugins to extend the DSL.
1531
+ *
1532
+ * Throws if `name` is not a valid identifier, collides with a built-in `Spectra` method, or is
1533
+ * already registered — built-ins can never be monkey-patched.
1534
+ *
1535
+ * @param name Command name (must be a valid JavaScript identifier).
1536
+ * @param command Implementation to attach.
1537
+ * @example
1538
+ * ```ts
1539
+ * Spectra.registerCommand('findButton', (selector: string) => Spectra.get(selector));
1540
+ * ```
1541
+ */
1542
+ registerCommand(name: string, command: SpectraCommand): void;
1543
+ /**
1544
+ * Registers multiple custom commands at once. Each entry is validated exactly like
1545
+ * `registerCommand`.
1546
+ *
1547
+ * @example
1548
+ * ```ts
1549
+ * Spectra.registerCommands({
1550
+ * findButton: (selector: string) => Spectra.get(selector),
1551
+ * findInput: (selector: string) => Spectra.get(selector),
1552
+ * });
1553
+ * ```
1554
+ */
1555
+ registerCommands(commands: Record<string, SpectraCommand>): void;
1462
1556
  }
@@ -94,4 +94,9 @@ export interface TestSpectraWorkerConfig {
94
94
  }[];
95
95
  /** Mirrors `spectra.config.ts`'s `executionConfig.environmentVariables`. */
96
96
  environmentVariables?: Record<string, string>;
97
+ /**
98
+ * Mirrors `spectra.config.ts`'s `executionConfig.plugins` — module specifiers (absolute paths,
99
+ * after CLI resolution) of TestSpectra plugins to install before test files are imported.
100
+ */
101
+ plugins?: string[];
97
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testspectra/matchers",
3
- "version": "1.1.14",
3
+ "version": "1.2.0",
4
4
  "description": "Canonical TypeScript contracts and ambient type definitions for TestSpectra",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/contract.ts CHANGED
@@ -151,6 +151,7 @@ export interface PlatformDriverBridge extends SpectraBrowserBridge {
151
151
  select(selector: string | ScopedSelector, option: string, index?: number | null): Promise<void>;
152
152
  hover(selector: string | ScopedSelector, index?: number | null): Promise<void>;
153
153
  focus(selector: string | ScopedSelector, index?: number | null): Promise<void>;
154
+ blur(selector: string | ScopedSelector, index?: number | null): Promise<void>;
154
155
  dragDrop(sourceSelector: string | ScopedSelector, targetSelector: string, sourceIndex?: number | null): Promise<void>;
155
156
  longPress(selector: string | ScopedSelector, duration: number, index?: number | null): Promise<void>;
156
157
  scrollIntoView(selector: string | ScopedSelector, index?: number | null): Promise<void>;
package/src/types.ts CHANGED
@@ -16,6 +16,8 @@ export type ActionKey =
16
16
  | 'longPress'
17
17
  | 'doubleClick'
18
18
  | 'hover'
19
+ | 'focus'
20
+ | 'blur'
19
21
  | 'dragDrop'
20
22
  | 'upload'
21
23
  | 'back'
@@ -918,6 +920,16 @@ export interface SingleElementProxy extends ElementReceiverAssertions<Promise<vo
918
920
  */
919
921
  focus(): Promise<void>;
920
922
 
923
+ /**
924
+ * Removes focus from the target element (blurs it).
925
+ *
926
+ * @example
927
+ * ```ts
928
+ * await Spectra.get('#email-input').blur();
929
+ * ```
930
+ */
931
+ blur(): Promise<void>;
932
+
921
933
  /**
922
934
  * Moves the mouse cursor to the element (alias to `hover()`).
923
935
  */
@@ -1352,6 +1364,56 @@ export interface CDPNetworkEntry {
1352
1364
  startTime: number;
1353
1365
  }
1354
1366
 
1367
+ /**
1368
+ * A user- or library-registered command callable on the global `Spectra` object.
1369
+ *
1370
+ * Commands are registered at runtime via `Spectra.registerCommand()` (typically from a plugin's
1371
+ * `setup()`), and their types are exposed to consumers through TypeScript module augmentation of
1372
+ * `SpectraStatic` — there is no type-generator integration for external plugins.
1373
+ */
1374
+ export type SpectraCommand = (...args: any[]) => any;
1375
+
1376
+ /**
1377
+ * Context passed to a plugin's `setup()`. Plugins use `platform` to register only the commands
1378
+ * that are valid for the active target.
1379
+ */
1380
+ export interface SpectraPluginContext {
1381
+ /** Active execution platform: `'web'`, `'android'`, or `'ios'`. */
1382
+ platform: string;
1383
+ }
1384
+
1385
+ /**
1386
+ * A TestSpectra plugin. A plugin is any external library that extends the `Spectra` DSL — its
1387
+ * `setup` receives the live `Spectra` object and registers commands (or performs other one-time
1388
+ * wiring) before test files are imported.
1389
+ *
1390
+ * Plugins are declared in `spectra.config.ts` under `executionConfig.plugins` as module specifiers
1391
+ * and loaded by both the native E2E worker and the component-testing runtime. Platform-specific
1392
+ * command **types** are shipped as per-stem subpath entries (`./web`, `./android`, `./ios`,
1393
+ * `./mobile`, `./common`) and wired into the generated ambient declarations by the type generator.
1394
+ *
1395
+ * @example
1396
+ * ```ts
1397
+ * import type { SpectraPlugin } from '@testspectra/matchers';
1398
+ *
1399
+ * const plugin: SpectraPlugin = {
1400
+ * name: 'my-plugin',
1401
+ * setup(spectra, { platform }) {
1402
+ * spectra.registerCommand('findButton', (selector: string) => spectra.get(selector));
1403
+ * if (platform === 'web') spectra.registerCommand('findByCss', (s: string) => spectra.get(s));
1404
+ * },
1405
+ * };
1406
+ *
1407
+ * export default plugin;
1408
+ * ```
1409
+ */
1410
+ export interface SpectraPlugin {
1411
+ /** Unique plugin identifier, used for diagnostics. */
1412
+ name: string;
1413
+ /** One-time wiring executed after `Spectra` is built and before test files are imported. */
1414
+ setup(spectra: SpectraStatic, context: SpectraPluginContext): void | Promise<void>;
1415
+ }
1416
+
1355
1417
  /**
1356
1418
  * Main TestSpectra cross-platform automation and assertion interface contract.
1357
1419
  */
@@ -1530,6 +1592,17 @@ export interface SpectraStatic {
1530
1592
  */
1531
1593
  focus(target: ElementTarget): Promise<void>;
1532
1594
 
1595
+ /**
1596
+ * Removes focus from the target element (blurs it).
1597
+ *
1598
+ * @param target Target element selector or proxy.
1599
+ * @example
1600
+ * ```ts
1601
+ * await Spectra.blur('#email-input');
1602
+ * ```
1603
+ */
1604
+ blur(target: ElementTarget): Promise<void>;
1605
+
1533
1606
  /**
1534
1607
  * Drags a source element and drops it onto a destination element target.
1535
1608
  *
@@ -1682,4 +1755,34 @@ export interface SpectraStatic {
1682
1755
  * ```
1683
1756
  */
1684
1757
  clearMocks(): void;
1758
+
1759
+ /**
1760
+ * Registers a custom command on the `Spectra` object, making it callable as
1761
+ * `Spectra.<name>(...)`. Intended for plugins to extend the DSL.
1762
+ *
1763
+ * Throws if `name` is not a valid identifier, collides with a built-in `Spectra` method, or is
1764
+ * already registered — built-ins can never be monkey-patched.
1765
+ *
1766
+ * @param name Command name (must be a valid JavaScript identifier).
1767
+ * @param command Implementation to attach.
1768
+ * @example
1769
+ * ```ts
1770
+ * Spectra.registerCommand('findButton', (selector: string) => Spectra.get(selector));
1771
+ * ```
1772
+ */
1773
+ registerCommand(name: string, command: SpectraCommand): void;
1774
+
1775
+ /**
1776
+ * Registers multiple custom commands at once. Each entry is validated exactly like
1777
+ * `registerCommand`.
1778
+ *
1779
+ * @example
1780
+ * ```ts
1781
+ * Spectra.registerCommands({
1782
+ * findButton: (selector: string) => Spectra.get(selector),
1783
+ * findInput: (selector: string) => Spectra.get(selector),
1784
+ * });
1785
+ * ```
1786
+ */
1787
+ registerCommands(commands: Record<string, SpectraCommand>): void;
1685
1788
  }
@@ -99,4 +99,9 @@ export interface TestSpectraWorkerConfig {
99
99
  monitoredDomains?: { domain: string; enabled: boolean }[];
100
100
  /** Mirrors `spectra.config.ts`'s `executionConfig.environmentVariables`. */
101
101
  environmentVariables?: Record<string, string>;
102
+ /**
103
+ * Mirrors `spectra.config.ts`'s `executionConfig.plugins` — module specifiers (absolute paths,
104
+ * after CLI resolution) of TestSpectra plugins to install before test files are imported.
105
+ */
106
+ plugins?: string[];
102
107
  }
Binary file
Binary file