0
# Command Line Interface
1
2
Jasmine provides a full-featured command-line interface with sub-commands, extensive options, and environment variable support for integrating into development workflows and CI/CD pipelines.
3
4
## Capabilities
5
6
### Basic Usage
7
8
Execute the Jasmine CLI with various commands and options.
9
10
```bash { .api }
11
jasmine [command] [options] [files] [--]
12
13
# Run all tests
14
jasmine
15
16
# Run specific files
17
jasmine spec/unit/user-spec.js spec/integration/api-spec.js
18
19
# Run with options
20
jasmine --parallel=4 --filter="authentication" --verbose
21
```
22
23
### Sub-commands
24
25
Available commands for project initialization and management.
26
27
```bash { .api }
28
# Initialize jasmine project structure
29
jasmine init
30
31
# Install example specs and helpers
32
jasmine examples
33
34
# Show help information
35
jasmine help
36
jasmine -h
37
38
# Show version information
39
jasmine version
40
jasmine -v
41
42
# Enumerate suites and specs without running
43
jasmine enumerate
44
```
45
46
**Sub-command Examples:**
47
48
```bash
49
# Initialize new project
50
npx jasmine init
51
# Creates: spec/support/jasmine.mjs
52
53
# Add example files
54
npx jasmine examples
55
# Creates: spec/jasmine_examples/, lib/jasmine_examples/, spec/helpers/jasmine_examples/
56
57
# Check versions
58
npx jasmine version
59
# Output: jasmine v5.10.0, jasmine-core v5.10.0
60
61
# List all suites and specs
62
npx jasmine enumerate
63
# Output: JSON structure of all test suites and specs
64
```
65
66
### Parallel Execution Options
67
68
Control parallel test execution with worker process configuration.
69
70
```bash { .api }
71
# Run with specific number of workers
72
jasmine --parallel=4
73
74
# Auto-detect optimal worker count
75
jasmine --parallel=auto
76
77
# Combine with other options
78
jasmine --parallel=auto --verbose --no-color
79
```
80
81
**Parallel Examples:**
82
83
```bash
84
# Use 4 worker processes
85
npx jasmine --parallel=4
86
87
# Auto-detect workers (CPU count - 1)
88
npx jasmine --parallel=auto
89
90
# Parallel with filtering
91
npx jasmine --parallel=4 --filter="integration"
92
93
# Note: --filter-path not supported in parallel mode
94
```
95
96
### Filtering Options
97
98
Filter which specs to run using various criteria.
99
100
```bash { .api }
101
# Filter specs by regular expression
102
jasmine --filter=REGEX
103
104
# Filter specs by suite/spec path (not supported in parallel mode)
105
jasmine --filter-path='["suite name","spec name"]'
106
107
# Examples
108
jasmine --filter="authentication"
109
jasmine --filter="^User.*should"
110
jasmine --filter-path='["User management","Authentication","should validate credentials"]'
111
```
112
113
**Filtering Examples:**
114
115
```bash
116
# Run only integration tests
117
npx jasmine --filter="integration"
118
119
# Run specs matching specific pattern
120
npx jasmine --filter="^API.*should respond"
121
122
# Run specific spec by path (sequential mode only)
123
npx jasmine --filter-path='["UserService","authenticate","should reject invalid credentials"]'
124
125
# Combine filtering with specific files
126
npx jasmine spec/user-spec.js --filter="authentication"
127
```
128
129
### File Loading Options
130
131
Configure helper files and required modules.
132
133
```bash { .api }
134
# Load helper files matching pattern
135
jasmine --helper=PATTERN
136
137
# Require modules before execution
138
jasmine --require=MODULE
139
140
# Examples
141
jasmine --helper="helpers/**/*.js"
142
jasmine --require="@babel/register"
143
jasmine --require="tsconfig-paths/register"
144
```
145
146
**File Loading Examples:**
147
148
```bash
149
# Load specific helper files
150
npx jasmine --helper="spec/helpers/database-helper.js"
151
152
# Load helper files with glob pattern
153
npx jasmine --helper="spec/helpers/**/*.js"
154
155
# Require transpiler
156
npx jasmine --require="@babel/register"
157
158
# Multiple requires
159
npx jasmine --require="@babel/register" --require="tsconfig-paths/register"
160
161
# Combine options
162
npx jasmine --helper="spec/helpers/**/*.js" --require="@babel/register"
163
```
164
165
### Execution Control Options
166
167
Control test execution behavior and failure handling.
168
169
```bash { .api }
170
# Stop execution on first failure
171
jasmine --fail-fast
172
173
# Control randomization
174
jasmine --random=true
175
jasmine --random=false
176
177
# Set random seed for reproducible runs
178
jasmine --seed=12345
179
180
# Combine execution controls
181
jasmine --fail-fast --random=true --seed=54321
182
```
183
184
**Execution Control Examples:**
185
186
```bash
187
# Stop on first failure for fast feedback
188
npx jasmine --fail-fast
189
190
# Disable randomization for debugging
191
npx jasmine --random=false
192
193
# Use specific seed for reproducible test runs
194
npx jasmine --seed=12345
195
196
# Fast failure with specific seed
197
npx jasmine --fail-fast --seed=12345
198
```
199
200
### Output and Reporting Options
201
202
Control test output formatting and verbosity.
203
204
```bash { .api }
205
# Control color output
206
jasmine --color
207
jasmine --no-color
208
209
# Enable verbose output
210
jasmine --verbose
211
212
# Use custom reporter
213
jasmine --reporter=PATH_TO_REPORTER
214
215
# Examples
216
jasmine --no-color --verbose
217
jasmine --reporter="./custom-reporter.js"
218
```
219
220
**Output Examples:**
221
222
```bash
223
# Force color output (useful in CI)
224
npx jasmine --color
225
226
# Disable colors for log files
227
npx jasmine --no-color > test-results.log
228
229
# Verbose output for debugging
230
npx jasmine --verbose
231
232
# Custom reporter
233
npx jasmine --reporter="./reporters/junit-reporter.js"
234
235
# Combine output options
236
npx jasmine --no-color --verbose --reporter="./reporters/custom.js"
237
```
238
239
### Configuration Options
240
241
Specify configuration files and override defaults.
242
243
```bash { .api }
244
# Use custom configuration file
245
jasmine --config=PATH
246
247
# Examples
248
jasmine --config="config/test.json"
249
jasmine --config="spec/support/ci.mjs"
250
```
251
252
**Configuration Examples:**
253
254
```bash
255
# Use CI-specific configuration
256
npx jasmine --config="config/ci.json"
257
258
# Use development configuration
259
npx jasmine --config="spec/support/dev.mjs"
260
261
# Override config with CLI options
262
npx jasmine --config="config/base.json" --parallel=4 --verbose
263
```
264
265
### Environment Variables
266
267
Configure Jasmine using environment variables.
268
269
```bash { .api }
270
# Set configuration file path
271
JASMINE_CONFIG_PATH=path/to/config.json jasmine
272
273
# Set environment variables inline
274
NODE_ENV=test DATABASE_URL=test://localhost jasmine
275
276
# Examples
277
JASMINE_CONFIG_PATH=config/ci.json npx jasmine
278
NODE_ENV=test npx jasmine --parallel=auto
279
```
280
281
**Environment Variable Examples:**
282
283
```bash
284
# Use environment-specific config
285
JASMINE_CONFIG_PATH=config/production-test.json npx jasmine
286
287
# Set test environment
288
NODE_ENV=test DATABASE_URL=postgresql://localhost/test_db npx jasmine
289
290
# Multiple environment variables
291
export NODE_ENV=test
292
export DATABASE_URL=postgresql://localhost/test_db
293
export JASMINE_CONFIG_PATH=config/ci.json
294
npx jasmine --parallel=auto
295
```
296
297
### File Arguments and Separators
298
299
Specify files to run and separate options from file arguments.
300
301
```bash { .api }
302
# Run specific files
303
jasmine file1.js file2.js
304
305
# Use -- to separate options from files
306
jasmine --verbose -- spec/integration/*.js
307
308
# Mix files with glob patterns
309
jasmine spec/unit/user-spec.js spec/integration/**/*-spec.js
310
```
311
312
**File Argument Examples:**
313
314
```bash
315
# Run specific spec files
316
npx jasmine spec/unit/user-service-spec.js spec/unit/auth-spec.js
317
318
# Run files with glob patterns
319
npx jasmine "spec/integration/**/*-spec.js"
320
321
# Separate options from file patterns
322
npx jasmine --parallel=4 --verbose -- "spec/**/*-integration-spec.js"
323
324
# Override configured spec files
325
npx jasmine spec/unit/critical-spec.js --fail-fast
326
```
327
328
### Complete CLI Examples
329
330
Real-world usage patterns combining multiple options.
331
332
```bash
333
# CI/CD pipeline execution
334
npx jasmine --config=config/ci.json --parallel=auto --no-color --reporter=./reporters/junit.js
335
336
# Development with fast feedback
337
npx jasmine --fail-fast --verbose --filter="unit"
338
339
# Debug specific failing test
340
npx jasmine spec/problematic-spec.js --random=false --verbose
341
342
# Integration test suite
343
npx jasmine --filter="integration" --parallel=2 --require="./spec/helpers/database-setup.js"
344
345
# Load testing with specific configuration
346
JASMINE_CONFIG_PATH=config/load-test.json NODE_ENV=test npx jasmine --parallel=8 --verbose
347
```
348
349
### Exit Codes
350
351
Jasmine CLI returns different exit codes based on test results.
352
353
```bash { .api }
354
# Exit codes:
355
# 0 - All tests passed
356
# 2 - Incomplete (no specs found or suite incomplete)
357
# 3 - Tests failed
358
# 4 - Premature exit (process killed during execution)
359
# 1 - Other errors (configuration, setup, etc.)
360
```
361
362
**Exit Code Usage:**
363
364
```bash
365
# In CI/CD scripts
366
npx jasmine --parallel=auto
367
EXIT_CODE=$?
368
369
if [ $EXIT_CODE -eq 0 ]; then
370
echo "All tests passed!"
371
elif [ $EXIT_CODE -eq 3 ]; then
372
echo "Tests failed!"
373
exit 1
374
else
375
echo "Test execution error (code: $EXIT_CODE)"
376
exit 1
377
fi
378
379
# With conditional execution
380
npx jasmine --fail-fast && npm run build || exit 1
381
```