@wdio/browserstack-service 9.30.2 → 9.31.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.
@@ -18,7 +18,10 @@ export default class AccessibilityModule extends BaseModule {
18
18
  [key: string]: unknown;
19
19
  }>;
20
20
  currentTestName: string | null;
21
+ currentHookRunUuid: string | null;
21
22
  constructor(accessibilityConfig: Accessibility, isNonBstackA11y: boolean);
23
+ onHookStart(args: Record<string, unknown>): Promise<void>;
24
+ onHookEnd(): Promise<void>;
22
25
  onBeforeExecute(): Promise<void>;
23
26
  private commandWrapper;
24
27
  onBeforeTest(args: Record<string, unknown>): Promise<void>;
@@ -18,9 +18,25 @@ export default class CustomTagsModule extends BaseModule {
18
18
  logger: typeof BStackLogger;
19
19
  name: string;
20
20
  static MODULE_NAME: string;
21
+ /**
22
+ * Tags set before a per-test context exists — e.g. from a `beforeEach` hook, which
23
+ * WDIO runs BEFORE `beforeTest` tracks the test instance. Buffered here and flushed
24
+ * into the test at test start (onBeforeTest), then reset per-test, so hook-set tags
25
+ * land on the test (parity with Java @Before). Process-local (one module per worker)
26
+ * and Mocha runs tests serially, so a plain object is safe.
27
+ */
28
+ private pendingTestLevelTags;
21
29
  constructor();
22
30
  getModuleName(): string;
23
31
  onBeforeExecute(): Promise<void>;
32
+ /**
33
+ * At each test start (TEST/PRE — after beforeTest tracks the instance), flush any
34
+ * tags buffered before the test had a context (e.g. set in a `beforeEach` hook — see
35
+ * the setCustomTags closure) into the tracked instance's custom_metadata via the SAME
36
+ * merge path as explicit setCustomTags, then reset the buffer for the next test — so
37
+ * hook-set tags union onto the test (parity with Java @Before).
38
+ */
39
+ onBeforeTest(args: Record<string, unknown>): Promise<void>;
24
40
  /**
25
41
  * If the test framework is currently inside a hook, merge custom_metadata onto
26
42
  * the last-started hook record so the binary receives hook.custom_metadata.
@@ -8,6 +8,19 @@ export default class TestHubModule extends BaseModule {
8
8
  testhubConfig: unknown;
9
9
  name: string;
10
10
  static MODULE_NAME: string;
11
+ /**
12
+ * Mocha-only: the TEST/POST (TestRunFinished) send deferred past the after-each hook
13
+ * window. WDIO fires `afterTest` (which triggers TEST/POST) BEFORE the user's
14
+ * `afterEach` hooks run, so custom tags set in `afterEach` would otherwise miss the
15
+ * event. The payload (`eventJson`) is serialized from the instance's live data map at
16
+ * SEND time, so deferring the send picks up those late merges; uuid / started_at /
17
+ * ended_at are already stamped in the data and do not drift. The stashed
18
+ * `args.instance` is the finished test's OWN object — INIT_TEST replaces the tracked
19
+ * slot with a fresh instance for the next test — so it stays valid across tests.
20
+ * Flushed at the next test's first event (INIT_TEST / TEST PRE) or, for the worker's
21
+ * last test, from service.after() via flushPendingTestFinishEvent().
22
+ */
23
+ private pendingTestFinish;
11
24
  /**
12
25
  * Create a new TestHubModule
13
26
  */
@@ -19,7 +32,18 @@ export default class TestHubModule extends BaseModule {
19
32
  getModuleName(): string;
20
33
  onBeforeTest(args: Record<string, unknown>): void;
21
34
  onAllTestEvents(args: Record<string, unknown>): void;
22
- sendTestFrameworkEvent(args: Record<string, unknown>): Promise<void>;
35
+ /**
36
+ * Send a deferred TEST/POST (TestRunFinished) event, if one is pending. The instance's
37
+ * CURRENT state may have moved on (e.g. LOG events during afterEach), so the send uses
38
+ * an explicit TEST/POST state override; the payload data itself is read fresh from the
39
+ * instance so late custom-tag merges are included. Called from onAllTestEvents at the
40
+ * next test's boundary and from service.after() at worker end.
41
+ */
42
+ flushPendingTestFinishEvent(): Promise<void> | undefined;
43
+ sendTestFrameworkEvent(args: Record<string, unknown>, stateOverride?: {
44
+ testFrameworkState: string;
45
+ testHookState: string;
46
+ }): Promise<void>;
23
47
  /**
24
48
  * Send test session event to the service
25
49
  * @param args containing test session data
@@ -56,3 +56,17 @@ export declare class CustomTagAccumulator {
56
56
  /** Drop the accumulated entry once flushed (avoid unbounded growth). */
57
57
  clear(testUuid: string | undefined): void;
58
58
  }
59
+ export type MochaHookWindow = 'before_each' | 'after_each' | 'before_all' | 'after_all' | null;
60
+ /**
61
+ * Classify a Mocha hook title (e.g. '"before each" hook: setup') into a window type.
62
+ * Derives from getHookType so this and the tracked hook-state — both computed from the
63
+ * same hook title in service.beforeHook — can never disagree. getHookType anchors on
64
+ * Mocha's generated '"before each"' prefix (startsWith), so a hook with a custom name
65
+ * that merely contains another window's phrase (e.g. afterEach('reset before each run'))
66
+ * is NOT misrouted, unlike a substring match.
67
+ */
68
+ export declare function classifyMochaHookTitle(title: string | undefined | null): MochaHookWindow;
69
+ /** Set by the service's beforeHook (mocha); cleared by afterHook. */
70
+ export declare function setCurrentMochaHookWindow(window: MochaHookWindow): void;
71
+ /** Read by the CLI CustomTagsModule to route setCustomTags calls made inside hooks. */
72
+ export declare function getCurrentMochaHookWindow(): MochaHookWindow;