UNPKG

@wdio/mocha-framework

Version:
65 lines • 3.1 kB
/** * Parallel test execution for the Mocha framework adapter. * * When `mochaOpts.parallelMode` is set (`'contexts'` or `'userContexts'`), this module * replaces the sequential `mocha.run()` with parallel execution: * 1. Walk the Mocha suite tree to collect all it() blocks * 2. Pre-create a browsing context (window) for each test * 3. Run all tests simultaneously via Promise.allSettled() * 4. Each test runs inside an AsyncLocalStorage scope that * overrides ContextManager.getCurrentContext() → every * command (url, $, click, setValue, getText, etc.) targets * the correct context with zero Proxy or special-casing. * * @module parallel */ import type { Suite } from 'mocha'; import { type ParallelMode } from '@wdio/utils'; import type { EventEmitter } from 'node:events'; export declare function parseTimeoutString(value: string): number | undefined; interface CollectedTest { title: string; /** space-joined like Mocha's fullTitle(); used for grep and hook context parity */ fullTitle: string; /** dot-joined like the sequential adapter reports it */ reportFullTitle: string; fn: Function; parentTitle: string; _beforeEach: Function[]; _afterEach: Function[]; /** ancestry-merged suite before() hooks, outermost-first */ _beforeAll: Function[]; /** ancestry-merged suite after() hooks, innermost-first */ _afterAll: Function[]; /** static skip (it.skip / it without fn) */ pending?: boolean; file: string | undefined; /** {@link CollectedSuite.depth} of the owning suite; undefined for root-level tests */ suiteIndex?: number; /** Mocha's resolved timeout for this test (`_timeout`) */ timeout?: number; /** Mocha's resolved retries for this test (`_retries`): `mochaOpts.retries`, `this.retries(n)` in a describe, `it().retries(n)` */ retries?: number; /** {@link CollectedSuite.depth} of each suite of the tree, for the declaring suite of a hook */ suiteIndexOf: Map<object, number>; } /** * Recursively walk the Mocha suite tree and collect all test * definitions with their associated hooks. Kept as a public * export for tests; delegates to the single-pass {@link collectAll}. */ export declare function collectTests(suite: Suite, _parentBeforeEach?: Function[], _parentAfterEach?: Function[]): CollectedTest[]; export declare function isSkipError(err?: unknown): boolean; export interface ParallelMochaOptions { grep?: RegExp; invert?: boolean; timeout?: number | string; mode?: ParallelMode; /** `false`: a test that a failed hook skips is not reported, as in a sequential run (default `true`) */ failHookAffectedTests?: boolean; /** `true`: an uncaught error is not caught, as with Mocha's `allowUncaught` */ allowUncaught?: boolean; } export declare function runParallelTests(mochaSuite: Suite, browser: WebdriverIO.Browser, reporter: EventEmitter, cid: string, specs: string[], maxParallelContexts?: number, mochaOptions?: ParallelMochaOptions): Promise<number>; export {}; //# sourceMappingURL=parallel.d.ts.map