Implementation:DevExpress Testcafe Task
| Knowledge Sources | |
|---|---|
| Domains | Test Execution, Orchestration |
| Last Updated | 2026-02-12 12:00 GMT |
Overview
Task represents an entire test execution session, coordinating multiple BrowserJob instances across browser connection groups and managing screenshots, video recording, and lifecycle events.
Description
Task extends AsyncEventEmitter and serves as the top-level orchestrator for a test run. Given a set of tests and browser connection groups, it creates one BrowserJob per group, initializes the Screenshots manager, sets up FixtureHookController, optionally creates a Videos recorder, and prepares a testStructure for reporters. It tracks phase transitions (initialized, started, done) and propagates events through a shared MessageBus. When stopOnFirstFail is enabled, the task aborts all remaining jobs on the first error.
Usage
Task is created by the runner after bootstrapping browser connections. It is the central coordination point for the entire test execution -- reporters, video recorders, and the runner itself all subscribe to task-level events via the MessageBus. Test authors do not interact with this class directly.
Code Reference
Source Location
- Repository: DevExpress_Testcafe
- File: src/runner/task/index.ts
- Lines: 1-172
Signature
export default class Task extends AsyncEventEmitter {
private readonly _timeStamp: moment.Moment;
private _phase: TaskPhase;
public browserConnectionGroups: BrowserConnection[][];
public readonly tests: Test[];
public readonly opts: Dictionary<OptionValue>;
private readonly _proxy: Proxy;
public readonly warningLog: WarningLog;
public readonly screenshots: Screenshots;
public readonly fixtureHookController: FixtureHookController;
private readonly _pendingBrowserJobs: BrowserJob[];
public readonly testStructure: ReportedTestStructureItem[];
public readonly videos?: Videos;
private readonly _messageBus: MessageBus;
public startTime?: Date;
public constructor({
tests,
browserConnectionGroups,
proxy,
opts,
runnerWarningLog,
messageBus,
}: TaskInit);
public abort(): void;
}
Import
import Task from '../runner/task/index';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| tests | Test[] |
Yes | Array of all test definitions to execute |
| browserConnectionGroups | BrowserConnection[][] |
Yes | Groups of browser connections (one group per browser, connections per concurrency slot) |
| proxy | Proxy |
Yes | Hammerhead proxy for request interception and URL rewriting |
| opts | Dictionary<OptionValue> |
Yes | Runner options including screenshots config, video path, concurrency, stopOnFirstFail, etc. |
| runnerWarningLog | WarningLog |
Yes | Pre-existing warning log from the runner to copy warnings from |
| messageBus | MessageBus |
Yes | Central event bus shared across all components |
Outputs
| Name | Type | Description |
|---|---|---|
| testStructure | ReportedTestStructureItem[] |
Grouped test/fixture structure for reporter consumption |
| screenshots | Screenshots |
Configured screenshot manager instance |
| videos | undefined | Video recording manager (present only if opts.videoPath is set)
|
| warningLog | WarningLog |
Aggregated warnings from all browser jobs |
| startTime | undefined | Timestamp when the first test began execution |
Events Emitted (via MessageBus)
| Event | Payload | Description |
|---|---|---|
start |
Task |
Fired once when the first browser job starts its first test |
test-run-done |
TestRun |
Fired for each completed test run |
test-action-done |
ActionEventArg |
Fired after each test action completes |
done |
none | Fired when all browser jobs have completed |
Usage Examples
// Creating a Task (internal runner usage)
const task = new Task({
tests,
browserConnectionGroups,
proxy,
opts,
runnerWarningLog: warningLog,
messageBus,
});
// Subscribe to task events via messageBus
messageBus.on('start', async (task) => {
reporter.reportTaskStart(task.startTime, task.testStructure);
});
messageBus.on('test-run-done', async (testRun) => {
reporter.reportTestDone(testRun);
});
messageBus.on('done', async () => {
reporter.reportTaskDone();
});
// Abort all in-progress tests
task.abort();
Internal Mechanics
Browser Job Creation
The constructor calls _createBrowserJobs which iterates over browserConnectionGroups, creating one BrowserJob per group. Each job receives the full test list, the group's connections, and shared infrastructure (screenshots, warning log, fixture hook controller). The job is registered with each connection via bc.addJob(job).
Test Structure Preparation
_prepareTestStructure groups tests by fixture ID using lodash groupBy, producing a reporter-friendly array of { fixture: { id, name, tests: [{ id, name, skip }] } }.
Video Recording Integration
If opts.videoPath is specified, the constructor creates a Videos instance that attaches to each BrowserJob and manages per-test-run VideoRecorder instances. The Videos class subscribes to browser job events to start/stop recording at test boundaries.
Phase Transitions
The task moves through three phases defined by TaskPhase:
- initialized -- constructor complete, waiting for first test to start
- started -- first browser job emitted its
startevent - done -- all browser jobs have completed