1jasmine-node 2====== 3 4[![LICENSE](https://img.shields.io/github/license/mhevery/jasmine-node.svg?style=flat-square)](./LICENSE) 5[![npm](https://img.shields.io/npm/v/jasmine-node.svg?style=flat-square)](https://www.npmjs.com/package/jasmine-node) 6[![contributors](https://img.shields.io/badge/contributors-many-purple.svg?style=flat-square)](https://github.com/mhevery/jasmine-node/graphs/contributors) 7 8This node.js module makes the wonderful [Pivotal Lab's jasmine](http://github.com/pivotal/jasmine) 9spec framework (version 1) available in node.js. 10 11 12Project status 13-------------- 14 15This project is now in maintenance mode. It is recommended to use the `jasmine` or `jasmine-npm` 16package whenever possible. 17 18 19jasmine 20------- 21 22Version `1.3.1` of Jasmine is currently included with node-jasmine. This is a forked version from the 23[Karma project](https://github.com/karma-runner/karma-jasmine), which allows you to use the 24`ddescribe` and `iit` functions to run individual suites or specs. 25 26NOTICE: BETA `2.0.0` Support in the `Jasmine2.0` branch (with rewrite in CoffeeScript) is now abandoned and no longer supported. 27 28Supported Node.js versions 29-------------------------- 30 31* Current: 32 - 10 33 - 12 34* Deprecated: 35 - 8 (EOL in December 2019) 36 - 6 (already past EOL) 37 - 4 (already past EOL) 38 39Older versions of Node.js are no longer supported. It is *highly* recommended to upgrade to a supported version of Node.js. 40 41what's new 42---------- 43* Growl notifications with the `--growl` flag (requires Growl to be installed) 44* Ability to test specs written in Literate CoffeeScript 45* Teamcity Reporter reinstated. 46* Ability to specify multiple files to test via list in command line 47* Ability to suppress stack trace with `--noStack` 48* Async tests now run in the expected context instead of the global one 49* `--config` flag that allows you to assign variables to process.env 50* Terminal Reporters are now available in the Jasmine Object #184 51* Done is now available in all timeout specs #199 52* `afterEach` is available in requirejs #179 53* Editors that replace instead of changing files should work with autotest #198 54* Jasmine Mock Clock now works! 55* Autotest now works! 56* Using the latest Jasmine! 57* Verbose mode tabs `describe` blocks much more accurately! 58* `--coffee` now allows specs written in Literate CoffeeScript (`.litcoffee`) 59 60install 61------ 62 63To install the latest official version, use NPM: 64 65```sh 66npm install jasmine-node -g 67``` 68 69To install the latest _bleeding edge_ version, clone this repository and check 70out the `beta` branch. 71 72usage 73------ 74 75Write the specifications for your code in `*.js` and `*.coffee` files in the `spec/` directory. 76You can use sub-directories to better organise your specs. In the specs use `describe()`, `it()` etc. exactly 77as you would in client-side jasmine specs. 78 79**Note**: your specification files must be named as `*spec.js`, `*spec.coffee` or `*spec.litcoffee`, 80which matches the regular expression `/spec\.(js|coffee|litcoffee)$/i`; 81otherwise jasmine-node won't find them! 82For example, `sampleSpecs.js` is wrong, `sampleSpec.js` is right. 83 84If you have installed the npm package, you can run it with: 85 86```sh 87jasmine-node spec/ 88``` 89 90If you aren't using npm, you should add `pwd`/lib to the `$NODE_PATH` 91environment variable, then run: 92 93```sh 94node lib/jasmine-node/cli.js 95``` 96 97 98You can supply the following arguments: 99 100 * `--autotest`, provides automatic execution of specs after each change 101 * `--watch`, when used with `--autotest`, paths after `--watch` will be 102watched for changes, allowing to watch for changes outside of specs directory 103 * `--coffee`, allow execution of `.coffee` and `.litcoffee` specs 104 * `--color`, indicates spec output should uses color to 105indicates passing (green) or failing (red) specs 106 * `--noColor`, do not use color in the output 107 * `-m, --match REGEXP`, match only specs containing "REGEXPspec" 108 * `--matchall`, relax requirement of "spec" in spec file names 109 * `--verbose`, verbose output as the specs are run 110 * `--junitreport`, export tests results as junitreport xml format 111 * `--output FOLDER`, defines the output folder for junitreport files 112 * `--teamcity`, converts all console output to teamcity custom test runner commands. (Normally auto detected.) 113 * `--growl`, display test run summary in a growl notification (in addition to other outputs) 114 * `--runWithRequireJs`, loads all specs using requirejs instead of node's native require method 115 * `--requireJsSetup`, file run before specs to include and configure RequireJS 116 * `--test-dir`, the absolute root directory path where tests are located 117 * `--nohelpers`, does not load helpers 118 * `--forceexit`, force exit once tests complete 119 * `--captureExceptions`, listen to global exceptions, report them and exit (interferes with Domains in NodeJs, so do not use if using Domains as well 120 * `--config NAME VALUE`, set a global variable in `process.env` 121 * `--noStack`, suppress the stack trace generated from a test failure 122 123Individual files to test can be added as bare arguments to the end of the args. 124 125Example: 126 127```bash 128jasmine-node --coffee spec/AsyncSpec.coffee spec/CoffeeSpec.coffee spec/SampleSpec.js 129``` 130 131async tests 132----------- 133 134jasmine-node includes an alternate syntax for writing asynchronous tests. Accepting 135a done callback in the specification will trigger jasmine-node to run the test 136asynchronously waiting until the `done()` callback is called. 137 138```javascript 139var request = require('request'); 140 141it("should respond with hello world", function(done) { 142 request("http://localhost:3000/hello", function(error, response, body){ 143 expect(body).toEqual("hello world"); 144 done(); 145 }); 146}); 147``` 148 149An asynchronous test will fail after `5000` ms if `done()` is not called. This timeout 150can be changed by setting `jasmine.getEnv().defaultTimeoutInterval` or by passing a timeout 151interval in the specification. 152 153```javascript 154var request = require('request'); 155 156it("should respond with hello world", function(done) { 157 request("http://localhost:3000/hello", function(error, response, body){ 158 done(); 159 }); 160}, 250); // timeout after 250 ms 161``` 162 163or 164 165```javascript 166var request = require('request'); 167 168jasmine.getEnv().defaultTimeoutInterval = 500; 169 170it("should respond with hello world", function(done) { 171 request("http://localhost:3000/hello", function(error, response, body){ 172 done(); 173 }); // timeout after 500 ms 174}); 175``` 176 177Checkout [`spec/SampleSpecs.js`](https://github.com/mhevery/jasmine-node/blob/master/spec/SampleSpecs.js) to see how to use it. 178 179 180requirejs 181--------- 182 183There is a sample project in `/spec-requirejs`. It is comprised of: 184 1851. `requirejs-setup.js`, this pulls in our wrapper template (next) 1861. `requirejs-wrapper-template`, this builds up requirejs settings 1871. `requirejs.sut.js`, this is a __SU__bject To __T__est, something required by requirejs 1881. `requirejs.spec.js`, the actual jasmine spec for testing 189 190To run it: 191 192```sh 193node lib/jasmine-node/cli.js --runWithRequireJs --requireJsSetup ./spec-requirejs/requirejs-setup.js ./spec-requirejs/ 194``` 195 196exceptions 197---------- 198 199Often you'll want to capture an uncaught exception and log it to the console, 200this is accomplished by using the `--captureExceptions` flag. Exceptions will 201be reported to the console, but jasmine-node will attempt to recover and 202continue. It was decided to not change the current functionality until `2.0`. So, 203until then, jasmine-node will still return `0` and continue on without this flag. 204 205### Scenario ### 206 207You require a module, but it doesn't exist, ie `require('Q')` instead of 208`require('q')`. Jasmine-Node reports the error to the console, but carries on 209and returns `0`. This messes up Travis-CI because you need it to return a 210non-zero status while doing CI tests. 211 212### Mitigation ### 213 214Before `--captureExceptions` 215 216```sh 217> jasmine-node --coffee spec 218> echo $status 2190 220``` 221 222Run jasmine node with the `--captureExceptions` flag. 223 224```sh 225> jasmine-node --coffee --captureExceptions spec 226> echo $status 2271 228``` 229 230 231growl notifications 232------------------- 233 234Jasmine node can display [Growl](http://growl.info) notifications of test 235run summaries in addition to other reports. 236Growl must be installed separately, see [node-growl](https://github.com/visionmedia/node-growl) 237for platform-specific instructions. Pass the `--growl` flag to enable the notifications. 238 239 240development 241----------- 242 243Install the dependent packages by running: 244 245```sh 246npm install 247``` 248 249Run the specs before you send your pull request: 250 251```sh 252specs.sh 253``` 254 255__Note:__ Some tests are designed to fail in the specs.sh. After each of the 256individual runs completes, there is a line that lists what the expected 257Pass/Assert/Fail count should be. If you add/remove/edit tests, please be sure 258to update this with your PR. 259 260 261changelog 262--------- 263 264* `1.16.2` Back to `jasmine-growl-reporter@~0.2.0` (needed by Node.js pre-4.0) 265* `1.16.1` Use `~` instead of `^` in `dependencies` (may be needed by some really old npm versions) 266* `1.16.0` Fix `dependencies` to prevent major package updates 267* `1.15.0` Switch to coffeescript package 268* `1.14.6` Update dependencies to resolve `npm audit` issues 269* `1.14.5` Using `~` instead of `^` for reporter version (thanks to [Maxim-Filimonov](https://github.com/Maxim-Filimonov)) 270* `1.14.4` Rolled back jasmine reporter version (thanks to [tjmcduffie](https://github.com/tjmcduffie)) 271* `1.14.3` Added 'onComplete' callback to TeamCityReporter (thanks to [JoergFiedler](https://github.com/JoergFiedler)) 272* `1.14.2` Uhhh...not sure what happened here. 273* `1.14.1` Default to noColors if not in a TTY 274* `1.14.0` Add support for `iit`, `ddescribe` (thanks to [mgcrea](https://github.com/mgcrea)) 275* `1.13.1` Add coffee-script support for 1.7.x (thanks to [nathancarter](https://github.com/nathancarter)) 276* `1.13.0` Added timing to the verbose reporter (thanks to [rick-kilgore](https://github.com/rick-kilgore)) 277* `1.12.1` Fixed an issue where an undefined variable caused an unhelpful 278 exception in --watch Resolves #278 279* `1.12.0` 280 * Changed `util.print` to `stdout.write` (thanks to [nrstott](https://github.com/nrstott)) 281 * Don’t affect line numbers with --requireJsSetup (thanks to [daviddaurelio](https://github.com/davidaurelio)) 282 * Catch errors when loading helpers (thanks to [pimterry](https://github.com/pimterry)) 283 * Keep autotesting until all tests have passed (thanks to [notclive](https://github.com/notclive)) 284* `1.11.0` Added Growl notification option `--growl` (thanks to 285 [AlphaHydrae](https://github.com/AlphaHydrae)) 286* `1.10.2` Restored stack filter which was accidentally removed (thanks to 287 [kevinsawicki](https://github.com/kevinsawicki)) 288* `1.10.1` `beforeEach` and `afterEach` now properly handle the async-timeout function 289* `1.10.0` Skipped tests now show in the terminal reporter's output (thanks 290 to [kevinsawicki](https://github.com/kevinsawicki)) 291* `1.9.1` Timeout now consistent between Async and Non-Async Calls (thanks to 292 [codemnky](https://github.com/codemnky)) 293* `1.9.0` Now re-throwing the file-not-found error, added info to README.md, 294 printing version with `--version` 295* `1.8.1` Fixed silent failure due to invalid REGEX (thanks to 296 [pimterry](https://github.com/pimterry)) 297* `1.8.0` Fixed bug in autotest with multiple paths and added `--watch` feature 298 (thanks to [davegb3](https://github.com/davegb3)) 299* `1.7.1` Removed unneeded fs dependency (thanks to 300 [kevinsawicki](https://github.com/kevinsawicki)) Fixed broken fs call in 301 node `0.6` (thanks to [abe33](https://github.com/abe33)) 302* `1.7.0` Literate CoffeeScript now testable (thanks to [magicmoose](https://github.com/magicmoose)) 303* `1.6.0` Teamcity Reporter Reinstated (thanks to [bhcleek](https://github.com/bhcleek)) 304* `1.5.1` Missing files and require exceptions will now report instead of failing silently 305* `1.5.0` Now takes multiple files for execution. (thanks to [abe33](https://github.com/abe33)) 306* `1.4.0` Optional flag to suppress stack trace on test failure (thanks to [Lastalas](https://github.com/Lastalas)) 307* `1.3.1` Fixed context for async tests (thanks to [omryn](https://github.com/omryn)) 308* `1.3.0` Added `--config` flag for changeable testing environments 309* `1.2.3` Fixed #179, #184, #198, #199. Fixes autotest, afterEach in requirejs, terminal reporter is in jasmine object, done function missing in async tests 310* `1.2.2` Revert Exception Capturing to avoid Breaking Domain Tests 311* `1.2.1` Emergency fix for path reference missing 312* `1.2.0` Fixed #149, #152, #171, #181, #195. `--autotest` now works as expected, jasmine clock now responds to the fake ticking as requested, and removed the path.exists warning 313* `1.1.1` Fixed #173, #169 (Blocks were not indented in verbose properly, added more documentation to address #180 314* `1.1.0` Updated Jasmine to `1.3.1`, fixed fs missing, catching uncaught exceptions, other fixes 315