0
# jasmine-node
1
2
jasmine-node is a Node.js BDD testing framework that brings Pivotal Lab's Jasmine (version 1) to server-side JavaScript environments. It provides DOM-less testing capabilities with comprehensive reporting, asynchronous test support, and integration with build systems and continuous integration platforms.
3
4
## Package Information
5
6
- **Package Name**: jasmine-node
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install jasmine-node -g`
10
- **License**: MIT
11
12
## Core Imports
13
14
```javascript
15
const jasmine = require("jasmine-node");
16
```
17
18
For global usage (after global installation):
19
20
```bash
21
jasmine-node spec/
22
```
23
24
## Basic Usage
25
26
```javascript
27
// In your spec files (must match *spec.js pattern)
28
describe("Calculator", function() {
29
it("should add two numbers correctly", function() {
30
const result = 2 + 3;
31
expect(result).toEqual(5);
32
});
33
34
it("should handle async operations", function(done) {
35
setTimeout(function() {
36
expect(true).toBe(true);
37
done();
38
}, 100);
39
});
40
});
41
```
42
43
Run tests:
44
45
```bash
46
jasmine-node spec/
47
```
48
49
## Architecture
50
51
jasmine-node is built around several key components:
52
53
- **Core Jasmine Engine**: Modified Jasmine 1.3.1 with Node.js adaptations
54
- **CLI Interface**: Command-line tool with extensive configuration options
55
- **Reporter System**: Multiple output formats (terminal, verbose, TeamCity, JUnit XML, Growl)
56
- **Spec Discovery**: Automatic test file discovery and loading
57
- **Async Support**: Enhanced asynchronous testing with done() callbacks
58
- **Multi-Format Support**: JavaScript, CoffeeScript, and Literate CoffeeScript specs
59
- **RequireJS Integration**: Module loading support for AMD-style projects
60
61
## Capabilities
62
63
### Test Writing
64
65
Core BDD functions for writing test suites and specifications. Includes support for setup/teardown, test organization, and assertions.
66
67
```javascript { .api }
68
function describe(description, specDefinitions);
69
function it(description, specFunction, timeout);
70
function beforeEach(setupFunction, timeout);
71
function afterEach(teardownFunction, timeout);
72
function expect(actual);
73
```
74
75
[Test Writing](./test-writing.md)
76
77
### Command Line Interface
78
79
Comprehensive CLI with options for test execution, file watching, output formatting, and CI integration.
80
81
```javascript { .api }
82
// CLI execution options
83
interface CliOptions {
84
autotest?: boolean;
85
watch?: string[];
86
coffee?: boolean;
87
color?: boolean;
88
verbose?: boolean;
89
junitreport?: boolean;
90
teamcity?: boolean;
91
growl?: boolean;
92
match?: string;
93
timeout?: number;
94
}
95
```
96
97
[CLI Usage](./cli-usage.md)
98
99
### Reporters and Output
100
101
Multiple reporter formats for different environments including terminal output, CI integration, and notifications.
102
103
```javascript { .api }
104
class TerminalReporter {
105
constructor(config: ReporterConfig);
106
}
107
108
class TerminalVerboseReporter {
109
constructor(config: ReporterConfig);
110
}
111
112
class TeamcityReporter {
113
constructor(config: ReporterConfig);
114
}
115
116
interface ReporterConfig {
117
print?: Function;
118
color?: boolean;
119
onComplete?: Function;
120
includeStackTrace?: boolean;
121
}
122
```
123
124
[Reporters and Output](./reporters.md)
125
126
### Advanced Features
127
128
Advanced functionality including RequireJS support, CoffeeScript integration, file watching, and custom configuration.
129
130
```javascript { .api }
131
function executeSpecsInFolder(options: ExecutionOptions);
132
function loadHelpersInFolder(folder: string, matcher: RegExp);
133
134
interface ExecutionOptions {
135
specFolders: string[];
136
onComplete?: Function;
137
isVerbose?: boolean;
138
showColors?: boolean;
139
useRequireJs?: boolean | string;
140
regExpSpec?: RegExp;
141
}
142
```
143
144
[Advanced Features](./advanced-features.md)
145
146
## Core Types
147
148
```javascript { .api }
149
// Global BDD functions
150
declare function describe(description: string, specDefinitions: () => void): void;
151
declare function it(description: string, specFunction: (done?: () => void) => void, timeout?: number): void;
152
declare function beforeEach(setupFunction: (done?: () => void) => void, timeout?: number): void;
153
declare function afterEach(teardownFunction: (done?: () => void) => void, timeout?: number): void;
154
declare function xdescribe(description: string, specDefinitions: () => void): void;
155
declare function xit(description: string, specFunction: () => void): void;
156
157
// Expectations and spies
158
declare function expect(actual: any): jasmine.Matchers;
159
declare function spyOn(object: any, method: string): jasmine.Spy;
160
declare function waitsFor(latchFunction: () => boolean, timeoutMessage?: string, timeout?: number): void;
161
declare function waits(timeout: number): void;
162
declare function runs(asyncMethod: () => void): void;
163
164
// Main jasmine object
165
declare namespace jasmine {
166
interface Matchers {
167
toBe(expected: any): boolean;
168
toEqual(expected: any): boolean;
169
toMatch(expected: string | RegExp): boolean;
170
toBeNull(): boolean;
171
toBeUndefined(): boolean;
172
toBeTruthy(): boolean;
173
toBeFalsy(): boolean;
174
toContain(expected: any): boolean;
175
toBeGreaterThan(expected: number): boolean;
176
toBeLessThan(expected: number): boolean;
177
toThrow(expected?: any): boolean;
178
not: Matchers;
179
}
180
181
interface Spy {
182
andReturn(value: any): Spy;
183
andThrow(exception: any): Spy;
184
andCallThrough(): Spy;
185
andCallFake(fakeFunction: Function): Spy;
186
calls: any[];
187
mostRecentCall: { args: any[] };
188
argsForCall: any[][];
189
callCount: number;
190
}
191
192
interface Env {
193
defaultTimeoutInterval: number;
194
execute(): void;
195
addReporter(reporter: any): void;
196
}
197
198
function getEnv(): Env;
199
function getGlobal(): any;
200
}