0
# Adapter Implementation
1
2
Core adapter implementation that bridges WebdriverIO with the Jasmine testing framework, providing test execution, expectation handling, and reporting integration.
3
4
## Capabilities
5
6
### JasmineAdapter Class
7
8
The main adapter class that orchestrates Jasmine test execution within WebdriverIO environments.
9
10
```typescript { .api }
11
/**
12
* Core adapter class that bridges WebdriverIO with Jasmine testing framework
13
*/
14
class JasmineAdapter {
15
constructor(
16
cid: string,
17
config: WebdriverIOJasmineConfig,
18
specs: string[],
19
capabilities: Capabilities.ResolvedTestrunnerCapabilities,
20
reporter: EventEmitter
21
);
22
23
/** Initialize the adapter and set up Jasmine environment */
24
init(): Promise<JasmineAdapter>;
25
26
/** Set up WebdriverIO expect and matchers with Jasmine environment, integrating async matchers and global expect */
27
setupExpect(
28
wdioExpect: typeof expect,
29
wdioMatchers: typeof matchers,
30
getConfig: typeof getConfig
31
): Promise<void>;
32
33
/** Check if adapter has tests to run */
34
hasTests(): boolean;
35
36
/** Execute test suite and return failure count */
37
run(): Promise<number>;
38
39
/** Custom spec filtering based on grep options */
40
customSpecFilter(spec: jasmine.Spec): boolean;
41
42
/** Wrap hooks for async execution with WebdriverIO integration */
43
wrapHook(hookName: keyof Services.HookFunctions): () => Promise<void>;
44
45
/** Prepare hook messages for WebdriverIO reporters */
46
prepareMessage(hookName: keyof Services.HookFunctions): FormattedMessage;
47
48
/** Format framework messages for consumption by reporters */
49
formatMessage(params: FrameworkMessage): FormattedMessage;
50
51
/** Get custom expectation result handler for assertion interception */
52
getExpectationResultHandler(jasmine: jasmine.Jasmine): Function;
53
54
/** Create custom expectation result handler with user-defined logic */
55
expectationResultHandler(origHandler: Function): Function;
56
}
57
```
58
59
**Usage Examples:**
60
61
```typescript
62
import JasmineAdapterFactory from "@wdio/jasmine-framework";
63
import type { EventEmitter } from "node:events";
64
65
// Create adapter through factory
66
const adapter = await JasmineAdapterFactory.init(
67
'worker-1',
68
{
69
jasmineOpts: {
70
defaultTimeoutInterval: 30000,
71
expectationResultHandler: (passed, data) => {
72
if (!passed) {
73
console.log('Test failed:', data.message);
74
}
75
}
76
},
77
beforeHook: [],
78
afterHook: [],
79
beforeTest: [],
80
afterTest: []
81
},
82
['./test/**/*.spec.js'],
83
{ browserName: 'chrome' },
84
reporterEventEmitter
85
);
86
87
// Check if tests are available
88
if (adapter.hasTests()) {
89
const failures = await adapter.run();
90
console.log(`Tests completed with ${failures} failures`);
91
}
92
```
93
94
95
96
## Types
97
98
```typescript { .api }
99
interface ReporterOptions {
100
cid: string;
101
specs: string[];
102
cleanStack?: boolean;
103
jasmineOpts: JasmineOpts;
104
}
105
106
interface ParentSuite {
107
description: string;
108
id: string;
109
tests: number;
110
}
111
112
interface SuiteEvent extends jasmine.SuiteResult {
113
type: 'suite';
114
start: Date;
115
duration: number | null;
116
errors?: jasmine.FailedExpectation[];
117
error?: jasmine.FailedExpectation;
118
}
119
120
interface TestEvent extends jasmine.SpecResult {
121
type: 'test' | 'hook';
122
start: Date;
123
duration: number | null;
124
errors?: jasmine.FailedExpectation[];
125
error?: jasmine.FailedExpectation;
126
}
127
128
interface FrameworkMessage {
129
type: string;
130
payload?: any;
131
err?: jasmine.FailedExpectation;
132
}
133
134
interface FormattedMessage {
135
type: string;
136
cid?: string;
137
specs?: string[];
138
uid?: string;
139
title?: string;
140
parent?: string;
141
fullTitle?: string;
142
pending?: boolean;
143
passed?: boolean;
144
file?: string;
145
duration?: number;
146
currentTest?: string;
147
error?: jasmine.FailedExpectation;
148
context?: unknown;
149
fullName?: string;
150
errors?: jasmine.FailedExpectation[];
151
}
152
```
153
154
## Global Declarations
155
156
The adapter extends the global scope with Jasmine test functions that include WebdriverIO-specific parameters:
157
158
```typescript { .api }
159
/**
160
* Define a single spec with optional WebdriverIO-specific retry count
161
* @param expectation - Textual description of what this spec is checking
162
* @param assertion - Function containing test code
163
* @param timeout - Custom timeout for async spec
164
* @param retries - Custom retry count (WebdriverIO specific)
165
*/
166
declare function it(
167
expectation: string,
168
assertion?: jasmine.ImplementationCallback,
169
timeout?: number,
170
retries?: number
171
): void;
172
173
/**
174
* A focused spec - only focused specs will be executed
175
* @param expectation - Textual description of what this spec is checking
176
* @param assertion - Function containing test code
177
* @param timeout - Custom timeout for async spec
178
* @param retries - Custom retry count (WebdriverIO specific)
179
*/
180
declare function fit(
181
expectation: string,
182
assertion?: jasmine.ImplementationCallback,
183
timeout?: number,
184
retries?: number
185
): void;
186
187
/**
188
* A temporarily disabled spec - will be reported as pending
189
* @param expectation - Textual description of what this spec is checking
190
* @param assertion - Function containing test code
191
* @param timeout - Custom timeout for async spec
192
* @param retries - Custom retry count (WebdriverIO specific)
193
*/
194
declare function xit(
195
expectation: string,
196
assertion?: jasmine.ImplementationCallback,
197
timeout?: number,
198
retries?: number
199
): void;
200
201
/**
202
* Run shared setup before each spec in the describe block
203
* @param action - Function containing setup code
204
* @param timeout - Custom timeout for async beforeEach
205
* @param retries - Custom retry count (WebdriverIO specific)
206
*/
207
declare function beforeEach(
208
action: jasmine.ImplementationCallback,
209
timeout?: number,
210
retries?: number
211
): void;
212
213
/**
214
* Run shared teardown after each spec in the describe block
215
* @param action - Function containing teardown code
216
* @param timeout - Custom timeout for async afterEach
217
* @param retries - Custom retry count (WebdriverIO specific)
218
*/
219
declare function afterEach(
220
action: jasmine.ImplementationCallback,
221
timeout?: number,
222
retries?: number
223
): void;
224
225
/**
226
* Run shared setup once before all specs in the describe block
227
* @param action - Function containing setup code
228
* @param timeout - Custom timeout for async beforeAll
229
* @param retries - Custom retry count (WebdriverIO specific)
230
*/
231
declare function beforeAll(
232
action: jasmine.ImplementationCallback,
233
timeout?: number,
234
retries?: number
235
): void;
236
237
/**
238
* Run shared teardown once after all specs in the describe block
239
* @param action - Function containing teardown code
240
* @param timeout - Custom timeout for async afterAll
241
* @param retries - Custom retry count (WebdriverIO specific)
242
*/
243
declare function afterAll(
244
action: jasmine.ImplementationCallback,
245
timeout?: number,
246
retries?: number
247
): void;
248
```