0
# Configuration Options
1
2
Comprehensive configuration options for customizing Jasmine behavior within WebdriverIO environments, including timeouts, test filtering, execution control, and custom handlers.
3
4
## Capabilities
5
6
### JasmineOpts Interface
7
8
Main configuration interface for customizing Jasmine framework adapter behavior.
9
10
```typescript { .api }
11
/**
12
* Configuration options for Jasmine framework adapter
13
*/
14
interface JasmineOpts {
15
/** Default timeout interval for Jasmine operations (default: 60000ms) */
16
defaultTimeoutInterval?: number;
17
18
/** Array of helper file paths relative to spec directory to include before specs (default: []) */
19
helpers?: string[];
20
21
/** Array of module paths to require before requiring any helper or spec files (default: []) */
22
requires?: string[];
23
24
/** Whether to randomize spec execution order (default: true) */
25
random?: boolean;
26
27
/** Seed function for randomization basis. Null causes random seed (default: undefined) */
28
seed?: Function;
29
30
/** Whether to stop execution after first spec failure (deprecated, use stopOnSpecFailure) */
31
failFast?: boolean;
32
33
/** Whether to fail specs that ran no expectations (default: false) */
34
failSpecWithNoExpectations?: boolean;
35
36
/** Whether specs should only have one expectation failure per spec (default: false) */
37
oneFailurePerSpec?: boolean;
38
39
/** Custom function to filter which specs to run */
40
specFilter?: () => boolean;
41
42
/** Pattern to selectively run specs matching string or regexp */
43
grep?: string | RegExp;
44
45
/** If true, inverts grep matches to run non-matching tests (default: false) */
46
invertGrep?: boolean;
47
48
/** Whether to clean up stack traces removing node module references (default: false) */
49
cleanStack?: boolean;
50
51
/** Whether to stop test suite execution on first spec failure (default: false) */
52
stopOnSpecFailure?: boolean;
53
54
/** Whether to stop spec execution on first expectation failure (default: false) */
55
stopSpecOnExpectationFailure?: boolean;
56
57
/** Custom handler for intercepting assertion results for logging or screenshots */
58
expectationResultHandler?: (passed: boolean, data: ResultHandlerPayload) => void;
59
}
60
```
61
62
**Usage Examples:**
63
64
```javascript
65
// Basic configuration
66
export const config = {
67
framework: 'jasmine',
68
jasmineOpts: {
69
defaultTimeoutInterval: 30000,
70
random: false,
71
stopOnSpecFailure: true
72
}
73
};
74
75
// Advanced configuration with custom handlers
76
export const config = {
77
framework: 'jasmine',
78
jasmineOpts: {
79
defaultTimeoutInterval: 60000,
80
helpers: ['./test/helpers/**/*.js'],
81
requires: ['ts-node/register'],
82
grep: /smoke/,
83
expectationResultHandler: (passed, data) => {
84
if (!passed) {
85
// Take screenshot on failure
86
browser.saveScreenshot(`./failures/${Date.now()}.png`);
87
console.log('Assertion failed:', data.message);
88
}
89
},
90
cleanStack: true,
91
failSpecWithNoExpectations: true
92
}
93
};
94
```
95
96
### Configuration Properties
97
98
#### Timeout Management
99
100
```typescript { .api }
101
/** Default timeout interval for all Jasmine operations */
102
defaultTimeoutInterval?: number; // Default: 60000ms
103
```
104
105
Controls the default timeout for all Jasmine specs and hooks. Individual tests can override this with their own timeout parameter.
106
107
#### File Loading
108
109
```typescript { .api }
110
/** Helper files to load before spec files */
111
helpers?: string[];
112
113
/** Modules to require before any helper or spec files */
114
requires?: string[];
115
```
116
117
Helper files are loaded after requires but before spec files. Both support glob patterns for file matching.
118
119
#### Execution Control
120
121
```typescript { .api }
122
/** Randomize spec execution order */
123
random?: boolean; // Default: true
124
125
/** Custom seed function for randomization */
126
seed?: Function;
127
128
/** Stop suite execution on first spec failure */
129
stopOnSpecFailure?: boolean; // Default: false
130
131
/** Stop spec execution on first expectation failure */
132
stopSpecOnExpectationFailure?: boolean; // Default: false
133
```
134
135
#### Test Filtering
136
137
```typescript { .api }
138
/** Custom spec filter function */
139
specFilter?: () => boolean;
140
141
/** Pattern to match spec names */
142
grep?: string | RegExp;
143
144
/** Invert grep pattern matching */
145
invertGrep?: boolean; // Default: false
146
```
147
148
Filtering allows selective test execution based on patterns or custom logic. When `specFilter` is provided, `grep` and `invertGrep` are ignored.
149
150
#### Validation and Error Handling
151
152
```typescript { .api }
153
/** Fail specs with no expectations */
154
failSpecWithNoExpectations?: boolean; // Default: false
155
156
/** Limit to one expectation failure per spec */
157
oneFailurePerSpec?: boolean; // Default: false
158
159
/** Clean up stack traces */
160
cleanStack?: boolean; // Default: false
161
162
/** Custom expectation result handler */
163
expectationResultHandler?: (passed: boolean, data: ResultHandlerPayload) => void;
164
```
165
166
### Result Handler Payload
167
168
Data structure passed to custom expectation result handlers.
169
170
```typescript { .api }
171
/**
172
* Payload structure for expectation result handlers
173
*/
174
interface ResultHandlerPayload {
175
/** Whether the expectation passed */
176
passed: boolean;
177
178
/** Optional message describing the expectation */
179
message?: string;
180
181
/** Error object if expectation failed */
182
error?: Error;
183
}
184
```
185
186
**Usage Example:**
187
188
```javascript
189
expectationResultHandler: (passed, data) => {
190
console.log(`Expectation ${passed ? 'passed' : 'failed'}`);
191
192
if (!passed) {
193
console.log('Failure message:', data.message);
194
195
if (data.error) {
196
console.log('Error details:', data.error.stack);
197
}
198
199
// Custom failure handling (screenshots, logging, etc.)
200
handleTestFailure(data);
201
}
202
}
203
```
204
205
### WebdriverIO Integration Types
206
207
Extended configuration interface that combines WebdriverIO config with Jasmine options.
208
209
```typescript { .api }
210
/**
211
* WebdriverIO configuration extended with Jasmine options
212
*/
213
interface WebdriverIOJasmineConfig extends Omit<WebdriverIO.Config, keyof HooksArray>, HooksArray {
214
/** Jasmine-specific configuration options */
215
jasmineOpts: Omit<JasmineOpts, 'cleanStack'>;
216
}
217
218
/**
219
* Hook arrays for WebdriverIO integration
220
*/
221
type HooksArray = {
222
[K in keyof Required<Services.HookFunctions>]: Required<Services.HookFunctions>[K][];
223
}
224
```
225
226
## Deprecated Options
227
228
### Legacy Properties
229
230
```typescript { .api }
231
/** @deprecated Use stopOnSpecFailure instead */
232
failFast?: boolean;
233
```
234
235
Note: `stopSpecOnExpectationFailure` is not deprecated but works alongside `oneFailurePerSpec`. When either is set to true, specs will only have one expectation failure. The implementation checks both properties for backwards compatibility.