0
# Sequential Test Execution
1
2
The `Jasmine` class provides single-process test execution with full jasmine-core integration, offering complete control over test execution, custom matchers, and flexible configuration.
3
4
## Capabilities
5
6
### Jasmine Class
7
8
Main test runner for sequential execution with comprehensive test suite management.
9
10
```javascript { .api }
11
/**
12
* Configures, builds, and executes a Jasmine test suite
13
* @param options - Configuration options for the runner
14
*/
15
class Jasmine {
16
constructor(options?: JasmineOptions);
17
18
/** The Jasmine environment from jasmine-core */
19
readonly env: Env;
20
21
/** Whether to cause the Node process to exit when the suite finishes executing */
22
exitOnCompletion: boolean;
23
24
/** Get the version of jasmine-core in use */
25
coreVersion(): string;
26
}
27
28
interface JasmineOptions {
29
/** The path to the project's base directory */
30
projectBaseDir?: string;
31
/** Whether to create the globals (describe, it, etc) that make up Jasmine's spec-writing interface */
32
globals?: boolean;
33
}
34
```
35
36
### Test Execution
37
38
Run the complete test suite with optional file filtering and spec filtering.
39
40
```javascript { .api }
41
/**
42
* Runs the test suite
43
* @param files - Spec files to run instead of the previously configured set
44
* @param filter - Optional specification of what specs to run (RegExp, string, or path object)
45
* @returns Promise that resolves when the suite completes
46
*/
47
execute(files?: string[], filter?: string | RegExp | FilterObject): Promise<JasmineDoneInfo>;
48
49
interface FilterObject {
50
/** Array of spec or suite descriptions for path-based filtering */
51
path: string[];
52
}
53
```
54
55
**Usage Examples:**
56
57
```javascript
58
const Jasmine = require('jasmine');
59
60
const jasmine = new Jasmine();
61
62
// Run all specs
63
await jasmine.execute();
64
65
// Run specific files
66
await jasmine.execute(['spec/unit/my-spec.js', 'spec/integration/api-spec.js']);
67
68
// Run specs matching regex filter
69
await jasmine.execute(null, 'integration');
70
await jasmine.execute(null, /authentication/);
71
72
// Run specs at specific path
73
await jasmine.execute(null, {
74
path: ['User management', 'Authentication', 'should validate credentials']
75
});
76
```
77
78
### Test Suite Enumeration
79
80
List all suites and specs without executing them, useful for test discovery and tooling integration.
81
82
```javascript { .api }
83
/**
84
* Returns a tree of suites and specs without actually running the specs
85
* @returns Promise resolving to enumerated test structure
86
*/
87
enumerate(): Promise<EnumeratedSuiteOrSpec[]>;
88
89
interface EnumeratedSuiteOrSpec {
90
/** Type of the item */
91
type: 'suite' | 'spec';
92
/** Description of the suite or spec */
93
description: string;
94
/** Child items (only present for suites) */
95
children?: EnumeratedSuiteOrSpec[];
96
}
97
```
98
99
**Usage Example:**
100
101
```javascript
102
const jasmine = new Jasmine();
103
await jasmine.loadConfigFile();
104
105
const structure = await jasmine.enumerate();
106
console.log(JSON.stringify(structure, null, 2));
107
```
108
109
### Test Randomization
110
111
Control test execution order with randomization and seeding capabilities.
112
113
```javascript { .api }
114
/**
115
* Sets whether to randomize the order of specs
116
* @param value - Whether to randomize
117
*/
118
randomizeTests(value: boolean): void;
119
120
/**
121
* Sets the random seed for reproducible test runs
122
* @param seed - The random seed value
123
*/
124
seed(seed: string): void;
125
```
126
127
**Usage Example:**
128
129
```javascript
130
const jasmine = new Jasmine();
131
132
// Enable randomization
133
jasmine.randomizeTests(true);
134
135
// Set specific seed for reproducible runs
136
jasmine.seed('12345');
137
138
await jasmine.execute();
139
```
140
141
### Reporter Management
142
143
Add and manage custom reporters for test output and result processing.
144
145
```javascript { .api }
146
/**
147
* Add a custom reporter to the Jasmine environment
148
* @param reporter - The reporter to add
149
*/
150
addReporter(reporter: Reporter): void;
151
152
/**
153
* Clears all registered reporters
154
*/
155
clearReporters(): void;
156
157
/**
158
* Provide a fallback reporter if no other reporters have been specified
159
* @param reporter - The fallback reporter
160
*/
161
provideFallbackReporter(reporter: Reporter): void;
162
```
163
164
**Usage Example:**
165
166
```javascript
167
const jasmine = new Jasmine();
168
169
// Add custom reporter
170
jasmine.addReporter({
171
jasmineStarted: () => console.log('Tests started'),
172
jasmineDone: (result) => console.log(`Tests completed: ${result.overallStatus}`),
173
specDone: (result) => console.log(`Spec: ${result.description} - ${result.status}`)
174
});
175
176
await jasmine.execute();
177
```
178
179
### Custom Matchers
180
181
Add custom matchers for enhanced test assertions within the current scope.
182
183
```javascript { .api }
184
/**
185
* Add custom matchers for the current scope of specs
186
* Note: Only callable from within beforeEach, it, or beforeAll
187
* @param matchers - Object where keys become new matcher names
188
*/
189
addMatchers(matchers: CustomMatchers): void;
190
191
interface CustomMatchers {
192
[matcherName: string]: (util?: MatchersUtil, customEqualityTesters?: CustomEqualityTester[]) => {
193
compare(actual: any, expected?: any): MatcherResult;
194
negativeCompare?(actual: any, expected?: any): MatcherResult;
195
};
196
}
197
198
interface MatcherResult {
199
pass: boolean;
200
message?: string | (() => string);
201
}
202
```
203
204
### Execution Control
205
206
Configure test execution behavior for failure handling and spec stopping.
207
208
```javascript { .api }
209
/**
210
* Sets whether to cause specs to only have one expectation failure
211
* @param value - Whether to cause specs to only have one expectation failure
212
*/
213
stopSpecOnExpectationFailure(value: boolean): void;
214
215
/**
216
* Sets whether to stop execution of the suite after the first spec failure
217
* @param value - Whether to stop execution after first spec failure
218
*/
219
stopOnSpecFailure(value: boolean): void;
220
```
221
222
**Usage Example:**
223
224
```javascript
225
const jasmine = new Jasmine();
226
227
// Stop suite on first failure for fast feedback
228
jasmine.stopOnSpecFailure(true);
229
230
// Continue specs after first expectation failure
231
jasmine.stopSpecOnExpectationFailure(false);
232
233
await jasmine.execute();
234
```
235
236
### Configuration and File Management
237
238
Load configuration and manage spec/helper files programmatically.
239
240
```javascript { .api }
241
/**
242
* Loads configuration from the specified file
243
* @param configFilePath - Path to config file, defaults to spec/support/jasmine.json
244
*/
245
loadConfigFile(configFilePath?: string): Promise<void>;
246
247
/**
248
* Loads configuration from the specified object
249
* @param config - Configuration object
250
*/
251
loadConfig(config: Configuration): void;
252
253
/**
254
* Configure the test environment
255
* @param envConfig - Environment configuration object
256
*/
257
configureEnv(envConfig: EnvConfig): void;
258
259
/**
260
* Load spec files into the test suite
261
*/
262
loadSpecs(): Promise<void>;
263
264
/**
265
* Load helper files into the test suite
266
*/
267
loadHelpers(): Promise<void>;
268
269
/**
270
* Load required modules
271
*/
272
loadRequires(): Promise<void>;
273
```
274
275
### Display and Output Control
276
277
Control test output formatting and verbosity.
278
279
```javascript { .api }
280
/**
281
* Sets whether to show colors in the console reporter
282
* @param value - Whether to show colors
283
*/
284
showColors(value: boolean): void;
285
286
/**
287
* Sets whether to run in verbose mode for debugging configuration problems
288
* @param value - Whether to run in verbose mode
289
*/
290
verbose(value: boolean): void;
291
292
/**
293
* Sets whether the console reporter should list pending specs even when there are failures
294
* @param value - Whether to always list pending specs
295
*/
296
alwaysListPendingSpecs(value: boolean): void;
297
```
298
299
**Usage Example:**
300
301
```javascript
302
const jasmine = new Jasmine();
303
304
// Load configuration
305
await jasmine.loadConfigFile('config/test.json');
306
307
// Configure environment
308
jasmine.configureEnv({
309
random: true,
310
stopOnSpecFailure: false
311
});
312
313
// Set display options
314
jasmine.showColors(true);
315
jasmine.verbose(true);
316
jasmine.alwaysListPendingSpecs(false);
317
318
await jasmine.execute();
319
```