Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jasmine-node

Package Overview
Dependencies
Maintainers
2
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jasmine-node - npm Package Compare versions

Comparing version 1.14.2 to 2.0.0-beta1

Gruntfile.coffee

2

bower.json
{
"name": "jasmine-node",
"version": "1.12.0",
"version": "2.0.0",
"homepage": "https://github.com/mhevery/jasmine-node",

@@ -5,0 +5,0 @@ "authors": [

(function() {
//
// Imports
//
var util;
try {
util = require('util')
} catch(e) {
util = require('sys')
}
var TerminalReporter, noOp, util, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
var jasmineNode = {};
//
// Helpers
//
function noop() {}
_ = require('underscore');
util = null;
jasmineNode.TerminalReporter = function(config) {
this.print_ = config.print || function (str) { process.stdout.write(util.format(str)); };
this.color_ = config.color ? this.ANSIColors : this.NoColors;
this.started_ = false;
this.finished_ = false;
this.callback_ = config.onComplete || false
this.suites_ = [];
this.specResults_ = {};
this.failures_ = [];
this.includeStackTrace_ = config.includeStackTrace === false ? false : true;
this.stackFilter_ = config.stackFilter || function(t) { return t; };
try {
util = require('util');
} catch (_error) {
util = require('sys');
}
noOp = function() {};
jasmineNode.TerminalReporter.prototype = {
reportRunnerStarting: function(runner) {
this.started_ = true;
this.startedAt = new Date();
var suites = runner.topLevelSuites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
this.suites_.push(this.summarize_(suite));
TerminalReporter = (function() {
TerminalReporter.prototype.ANSIColors = {
pass: function() {
return '\x1B[32m';
},
fail: function() {
return '\x1B[31m';
},
specTiming: function() {
return '\x1B[34m';
},
suiteTiming: function() {
return '\x1B[33m';
},
ignore: function() {
return '\x1B[37m';
},
neutral: function() {
return '\x1B[0m';
}
},
};
ANSIColors: {
pass: function() { return '\033[32m'; }, // Green
fail: function() { return '\033[31m'; }, // Red
specTiming: function() { return '\033[34m'; }, // Blue
suiteTiming: function() { return '\033[33m'; }, // Yelow
ignore: function() { return '\033[37m'; }, // Light Gray
neutral: function() { return '\033[0m'; } // Normal
},
TerminalReporter.prototype.NoColors = {
pass: function() {
return '';
},
fail: function() {
return '';
},
specTiming: function() {
return '';
},
suiteTiming: function() {
return '';
},
ignore: function() {
return '';
},
neutral: function() {
return '';
}
};
NoColors: {
pass: function() { return ''; },
fail: function() { return ''; },
specTiming: function() { return ''; },
suiteTiming: function() { return ''; },
ignore: function() { return ''; },
neutral: function() { return ''; }
},
function TerminalReporter(config) {
var defaults;
this.config = config != null ? config : {};
this.specDone = __bind(this.specDone, this);
this.specStarted = __bind(this.specStarted, this);
this.suiteDone = __bind(this.suiteDone, this);
this.suiteStarted = __bind(this.suiteStarted, this);
this.jasmineDone = __bind(this.jasmineDone, this);
this.jasmineStarted = __bind(this.jasmineStarted, this);
defaults = {
onComplete: noOp,
noStackTrace: true,
verbose: false,
print: function(str) {
process.stdout.write(util.format(str));
},
stackFilter: function(t) {
return t;
}
};
this.config = _.defaults(this.config, defaults);
this.config.color = this.config.noColor ? this.NoColors : this.ANSIColors;
this.counts = {
tests: 0,
failures: 0,
skipped: 0
};
this.allSpecs = {};
this.suiteNestLevel = 0;
this.done = false;
this.suiteTimes = {};
return;
}
summarize_: function(suiteOrSpec) {
var isSuite = suiteOrSpec instanceof jasmine.Suite;
TerminalReporter.prototype.jasmineStarted = function(runner) {
this.startedAt = +(new Date);
};
// We could use a separate object for suite and spec
var summary = {
id: suiteOrSpec.id,
name: suiteOrSpec.description,
type: isSuite? 'suite' : 'spec',
suiteNestingLevel: 0,
children: []
TerminalReporter.prototype.jasmineDone = function() {
var color, elapsed, now, results, _base;
if (this.done) {
return;
}
this.done = true;
now = +(new Date);
elapsed = now - this.startedAt;
this.printFailures();
this.config.print("\n\nFinished in " + (elapsed / 1000) + " seconds\n");
results = ["" + this.counts.tests + " Tests", "" + this.counts.failures + " Failures", "" + this.counts.skipped + " Skipped\n\n"];
if (this.counts.failures > 0) {
color = this.config.color.fail();
} else {
color = this.config.color.pass();
}
global.jasmineResult = {
fail: this.counts.failures > 0
};
this.config.print(this.stringWithColor(results.join(', '), color));
if (typeof (_base = this.config).onComplete === "function") {
_base.onComplete();
}
};
if (isSuite) {
var calculateNestingLevel = function(examinedSuite) {
var nestingLevel = 0;
while (examinedSuite.parentSuite !== null) {
nestingLevel += 1;
examinedSuite = examinedSuite.parentSuite;
}
return nestingLevel;
};
TerminalReporter.prototype.suiteStarted = function(suite) {
this.suiteTimes[suite.id] = +(new Date);
if (this.config.verbose) {
this.printVerboseSuiteStart(suite);
}
this.suiteNestLevel++;
suite.parent = this.currentSuite;
this.currentSuite = suite;
};
summary.suiteNestingLevel = calculateNestingLevel(suiteOrSpec);
var children = suiteOrSpec.children();
for (var i = 0; i < children.length; i++) {
summary.children.push(this.summarize_(children[i]));
}
TerminalReporter.prototype.printVerboseSuiteStart = function(suite) {
var i, msg, _i, _ref;
msg = '';
for (i = _i = 0, _ref = this.suiteNestLevel; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
msg += " ";
}
msg += this.stringWithColor("" + suite.description + " Start\n", this.config.color.ignore());
return this.config.print(msg);
};
return summary;
},
// This is heavily influenced by Jasmine's Html/Trivial Reporter
reportRunnerResults: function(runner) {
this.reportFailures_();
var results = runner.results();
var resultColor = (results.failedCount > 0) ? this.color_.fail() : this.color_.pass();
var specs = runner.specs();
var specCount = specs.length;
var message = "\n\nFinished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + " seconds";
this.printLine_(message);
// This is what jasmine-html.js has
//message = "" + specCount + " spec" + ( specCount === 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount === 1) ? "" : "s");
this.printLine_(this.stringWithColor_(this.printRunnerResults_(runner), resultColor));
this.finished_ = true;
if(this.callback_) { this.callback_(runner); }
},
reportFailures_: function() {
if (this.failures_.length === 0) {
TerminalReporter.prototype.suiteDone = function(suite) {
var _ref;
if (!this.suiteTimes[suite.id]) {
return;
}
this.suiteNestLevel--;
this.suiteTimes[suite.id] = (+(new Date)) - this.suiteTimes[suite.id];
if (this.config.verbose) {
this.printVerboseSuiteDone(suite);
}
delete this.suiteTimes[suite.id];
this.currentSuite = (_ref = this.currentSuite.parent) != null ? _ref : null;
};
var indent = ' ', failure;
this.printLine_('\n');
this.print_('Failures:');
for (var i = 0; i < this.failures_.length; i++) {
failure = this.failures_[i];
this.printLine_('\n');
this.printLine_(' ' + (i + 1) + ') ' + failure.spec);
this.printLine_(' Message:');
this.printLine_(' ' + this.stringWithColor_(failure.message, this.color_.fail()));
if (this.includeStackTrace_) {
this.printLine_(' Stacktrace:');
this.print_(' ' + this.stackFilter_(failure.stackTrace));
}
TerminalReporter.prototype.printVerboseSuiteDone = function(suite) {
var i, msg, _i, _ref;
msg = '';
for (i = _i = 0, _ref = this.suiteNestLevel; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
msg += " ";
}
},
msg += this.stringWithColor("" + suite.description + " Finish", this.config.color.ignore());
msg += this.stringWithColor(" - " + this.suiteTimes[suite.id] + " ms\n\n", this.config.color.suiteTiming());
return this.config.print(msg);
};
reportSuiteResults: function(suite) {
// Not used in this context
},
TerminalReporter.prototype.specStarted = function(spec) {
this.specStart = +(new Date);
this.counts.tests++;
};
reportSpecResults: function(spec) {
var result = spec.results();
var msg = '';
if (result.skipped) {
msg = this.stringWithColor_('-', this.color_.ignore());
} else if (result.passed()) {
msg = this.stringWithColor_('.', this.color_.pass());
TerminalReporter.prototype.specDone = function(spec) {
var msg, _base, _name;
((_base = this.allSpecs)[_name = this.currentSuite.id] != null ? _base[_name] : _base[_name] = []).push(spec);
if (this.config.verbose) {
msg = this.makeVerbose(spec);
} else {
msg = this.stringWithColor_('F', this.color_.fail());
this.addFailureToFailures_(spec);
msg = this.makeSimple(spec);
}
this.spec_results += msg;
this.print_(msg);
},
this.config.print(msg);
};
addFailureToFailures_: function(spec) {
var result = spec.results();
var failureItem = null;
TerminalReporter.prototype.makeSimple = function(spec) {
var msg;
msg = '';
switch (spec.status) {
case 'pending':
this.counts.skipped++;
msg = this.stringWithColor('-', this.config.color.ignore());
break;
case 'passed':
msg = this.stringWithColor('.', this.config.color.pass());
break;
case 'failed':
this.counts.failures++;
msg = this.stringWithColor('F', this.config.color.fail());
break;
default:
msg = this.stringWithColor('U', this.config.color.fail());
}
return msg;
};
var items_length = result.items_.length;
for (var i = 0; i < items_length; i++) {
if (result.items_[i].passed_ === false) {
failureItem = result.items_[i];
var failure = {
spec: spec.suite.getFullName() + " " + spec.description,
message: failureItem.message,
stackTrace: failureItem.trace.stack
}
this.failures_.push(failure);
}
TerminalReporter.prototype.makeVerbose = function(spec) {
var elapsed, i, msg, _i, _ref;
elapsed = (+(new Date)) - this.specStart;
msg = '';
for (i = _i = 0, _ref = this.suiteNestLevel; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
msg += " ";
}
},
printRunnerResults_: function(runner){
var results = runner.results();
var specs = runner.specs();
var msg = '';
var skippedCount = 0;
specs.forEach(function(spec) {
if (spec.results().skipped) {
skippedCount++;
}
});
var passedCount = specs.length - skippedCount;
msg += passedCount + ' test' + ((passedCount === 1) ? '' : 's') + ', ';
msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', ';
msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + ', ';
msg += skippedCount + ' skipped' + '\n';
switch (spec.status) {
case 'pending':
this.counts.skipped++;
msg += this.stringWithColor("" + spec.description, this.config.color.ignore());
break;
case 'passed':
msg += this.stringWithColor("" + spec.description, this.config.color.pass());
break;
case 'failed':
this.counts.failures++;
msg += this.stringWithColor("" + spec.description, this.config.color.fail());
break;
default:
msg += this.stringWithColor("" + spec.description, this.config.color.fail());
}
msg += this.stringWithColor(" - " + elapsed + " ms\n", this.config.color.specTiming());
return msg;
},
};
// Helper Methods //
stringWithColor_: function(stringValue, color) {
return (color || this.color_.neutral()) + stringValue + this.color_.neutral();
},
printLine_: function(stringValue) {
this.print_(stringValue);
this.print_('\n');
}
};
// ***************************************************************
// TerminalVerboseReporter uses the TerminalReporter's constructor
// ***************************************************************
jasmineNode.TerminalVerboseReporter = function(config) {
jasmineNode.TerminalReporter.call(this, config);
// The extra field in this object
this.indent_ = 0;
this.specTimes_ = {};
this.suiteTimes_ = {};
this.suiteResults_ = {};
}
jasmineNode.TerminalVerboseReporter.prototype = {
reportSpecStarting: function(spec) {
now = new Date().getTime();
this.specTimes_[spec.id] = now;
var suite = spec.suite;
while (suite) {
if (!this.suiteTimes_[suite.id]) {
this.suiteTimes_[suite.id] = now;
TerminalReporter.prototype.printFailures = function() {
var count, failure, indent, spec, specs, stack, suite, _i, _j, _len, _len1, _ref, _ref1;
if (!(this.counts.failures > 0)) {
return;
}
this.config.print("\n\nFailures:");
indent = " ";
count = 0;
_ref = this.allSpecs;
for (suite in _ref) {
specs = _ref[suite];
for (_i = 0, _len = specs.length; _i < _len; _i++) {
spec = specs[_i];
_ref1 = spec.failedExpectations;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
failure = _ref1[_j];
count++;
this.config.print("\n\n" + indent + count + ") " + spec.fullName + "\n" + indent + indent + "Message:\n" + indent + indent + indent + (this.stringWithColor(failure.message, this.config.color.fail())));
if (!this.config.noStackTrace) {
stack = this.config.stackFilter(failure.stack);
this.config.print("\n\n" + indent + indent + "Stacktrace:\n" + indent + indent + indent + stack);
}
suite = suite.parentSuite;
}
}
},
reportSpecResults: function(spec) {
var elapsed = new Date().getTime() - this.specTimes_[spec.id];
if (spec.results().failedCount > 0) {
this.addFailureToFailures_(spec);
}
};
this.specResults_[spec.id] = {
messages: spec.results().getItems(),
result: spec.results().failedCount > 0 ? 'failed' : 'passed',
runtime: elapsed
};
},
reportSuiteResults: function(suite) {
var startTime = this.suiteTimes_[suite.id];
if (startTime) {
var elapsed = new Date().getTime() - startTime;
this.suiteResults_[suite.id] = {
runtime: elapsed
};
}
},
reportRunnerResults: function(runner) {
var messages = new Array();
this.buildMessagesFromResults_(messages, this.suites_);
var messages_length = messages.length;
for (var i = 0; i < messages_length-1; i++) {
this.printLine_(messages[i]);
TerminalReporter.prototype.stringWithColor = function(string, color) {
if (color == null) {
color = this.config.color.neutral();
}
return "" + color + string + (this.config.color.neutral());
};
this.print_(messages[messages_length-1]);
return TerminalReporter;
// Call the parent object's method
jasmineNode.TerminalReporter.prototype.reportRunnerResults.call(this, runner);
},
})();
buildMessagesFromResults_: function(messages, results, depth) {
var element, specResult, specIndentSpaces, msg = '';
depth = (depth === undefined) ? 0 : depth;
var results_length = results.length;
for (var i = 0; i < results_length; i++) {
element = results[i];
if (element.type === 'spec') {
specResult = this.specResults_[element.id.toString()];
if (specResult.result === 'passed') {
msg = this.stringWithColor_(this.indentMessage_(element.name, depth), this.color_.pass());
} else {
msg = this.stringWithColor_(this.indentMessage_(element.name, depth), this.color_.fail());
}
msg += this.stringWithColor_(" - " + specResult.runtime + " ms",
this.color_.specTiming());
messages.push(msg);
} else {
messages.push('');
msg = this.indentMessage_(element.name, depth)
if (element.id != null) {
suiteResult = this.suiteResults_[element.id.toString()];
if (suiteResult) {
msg += this.stringWithColor_(" - " + suiteResult.runtime + " ms", this.color_.suiteTiming());
}
}
messages.push(msg);
}
this.buildMessagesFromResults_(messages, element.children, depth + 2);
}
},
indentMessage_: function(message, indentCount) {
var _indent = '';
for (var i = 0; i < indentCount; i++) {
_indent += ' ';
}
return (_indent + message);
}
module.exports = {
TerminalReporter: TerminalReporter
};
// Inherit from TerminalReporter
jasmineNode.TerminalVerboseReporter.prototype.__proto__ = jasmineNode.TerminalReporter.prototype;
//
// Exports
//
exports.jasmineNode = jasmineNode;
})();
}).call(this);
{
"name": "jasmine-node",
"version": "1.14.2",
"version": "2.0.0-beta1",
"description": "DOM-less simple JavaScript BDD testing framework for Node",

@@ -26,18 +26,30 @@ "contributors": [

"dependencies": {
"coffee-script": ">=1.0.1",
"jasmine-reporters": ">=0.2.0",
"jasmine-growl-reporter": "~0.0.2",
"requirejs": ">=0.27.1",
"walkdir": ">= 0.0.1",
"underscore": ">= 1.3.1",
"gaze": "~0.3.2",
"mkdirp": "~0.3.5"
"coffee-script": "~1.7.1",
"walkdir": "~0.0.7",
"underscore": "~1.6.0",
"gaze": "~0.5.1",
"mkdirp": "~0.3.5",
"minimist": "0.0.8",
"jasmine-growl-reporter": "~0.2.0"
},
"bin": "bin/jasmine-node",
"devDependencies": {
"grunt-contrib-coffee": "^0.10.1",
"grunt-contrib-watch": "^0.5.3",
"grunt": "^0.4.2"
},
"bin": {
"jasmine-node": "./bin/jasmine-node"
},
"preferGlobal": true,
"main": "lib/jasmine-node",
"main": "./lib/jasmine-node",
"scripts": {
"test": "node lib/jasmine-node/cli.js spec"
},
"devDependencies": {}
"bugs": {
"url": "https://github.com/mhevery/jasmine-node/issues"
},
"license": "ISC",
"engines": {
"node": ">=0.10.0"
}
}

@@ -0,1 +1,6 @@

NOTE
====
This branch is in-development. Not recommended for use
jasmine-node

@@ -12,26 +17,13 @@ ======

Version `1.3.1` of Jasmine is currently included with node-jasmine. This is a forked version from the
[Karma project](https://github.com/karma-runner/karma-jasmine), which allows you to use the
`ddescribe` and `iit` functions to run individual suites or specs.
Version `2.0.0` of Jasmine is currently included with node-jasmine.
BETA `2.0.0` Support is available in the `Jasmine2.0` branch.
what's new
----------
* Growl notifications with the `--growl` flag (requires Growl to be installed)
* Ability to test specs written in Literate Coffee-Script
* Teamcity Reporter reinstated.
* Ability to specify multiple files to test via list in command line
* Ability to suppress stack trace with `--noStack`
* Async tests now run in the expected context instead of the global one
* `--config` flag that allows you to assign variables to process.env
* Terminal Reporters are now available in the Jasmine Object #184
* Done is now available in all timeout specs #199
* `afterEach` is available in requirejs #179
* Editors that replace instead of changing files should work with autotest #198
* Jasmine Mock Clock now works!
* Autotest now works!
* Using the latest Jasmine!
* Verbose mode tabs `describe` blocks much more accurately!
* `--coffee` now allows specs written in Literate CoffeeScript (`.litcoffee`)
* Now using Jasmine 2.0.0
* Removed Support for RequireJS
* Removed Support for Custom Helpers (have to be inside a beforeEach)
* Removed Custom Timeout
* Rewrote Terminal Reporter
* Removed TeamCity Reporter (no support for Jasmine 2.0)
* Removed JUnit Reporter (no support for Jasmine 2.0)

@@ -77,26 +69,15 @@ install

You can supply the following arguments:
* `--autoTest` - rerun automatically the specs when a file changes
* `--watchFolders PATH`- when used with --autoTest, watches the given path(s) and runs all tests if a change is detected
* `--noColor` - do not use color coding for output
* `-m, --match REGEXP` - load only specs containing "REGEXPspec"
* `--matchAll` - relax requirement of "spec" in spec file names
* `--verbose` - print extra information per each test run
* `--coffee` - load coffee-script which allows execution .coffee files
* `--forceExit` - force exit once tests complete.
* `--captureExceptions`- listen to global exceptions, report them and exit (interferes with Domains)
* `--noStackTrace` - suppress the stack trace generated from a test failure
* `--version` - show the current version
* `-h, --help` - display this help and exit
* `--autotest`, provides automatic execution of specs after each change
* `--watch`, when used with `--autotest`, paths after `--watch` will be
watched for changes, allowing to watch for changes outside of specs directory
* `--coffee`, allow execution of `.coffee` and `.litcoffee` specs
* `--color`, indicates spec output should uses color to
indicates passing (green) or failing (red) specs
* `--noColor`, do not use color in the output
* `-m, --match REGEXP`, match only specs comtaining "REGEXPspec"
* `--matchall`, relax requirement of "spec" in spec file names
* `--verbose`, verbose output as the specs are run
* `--junitreport`, export tests results as junitreport xml format
* `--output FOLDER`, defines the output folder for junitreport files
* `--teamcity`, converts all console output to teamcity custom test runner commands. (Normally auto detected.)
* `--growl`, display test run summary in a growl notification (in addition to other outputs)
* `--runWithRequireJs`, loads all specs using requirejs instead of node's native require method
* `--requireJsSetup`, file run before specs to include and configure RequireJS
* `--test-dir`, the absolute root directory path where tests are located
* `--nohelpers`, does not load helpers
* `--forceexit`, force exit once tests complete
* `--captureExceptions`, listen to global exceptions, report them and exit (interferes with Domains in NodeJs, so do not use if using Domains as well
* `--config NAME VALUE`, set a global variable in `process.env`
* `--noStack`, suppress the stack trace generated from a test failure
Individual files to test can be added as bare arguments to the end of the args.

@@ -159,18 +140,2 @@

requirejs
---------
There is a sample project in `/spec-requirejs`. It is comprised of:
1. `requirejs-setup.js`, this pulls in our wrapper template (next)
1. `requirejs-wrapper-template`, this builds up requirejs settings
1. `requirejs.sut.js`, this is a __SU__bject To __T__est, something required by requirejs
1. `requirejs.spec.js`, the actual jasmine spec for testing
To run it:
```sh
node lib/jasmine-node/cli.js --runWithRequireJs --requireJsSetup ./spec-requirejs/requirejs-setup.js ./spec-requirejs/
```
exceptions

@@ -229,3 +194,3 @@ ----------

Run the specs before you send your pull request:
Run the specs before you send your pull request and ensure all pass:

@@ -236,11 +201,6 @@ ```sh

__Note:__ Some tests are designed to fail in the specs.sh. After each of the
individual runs completes, there is a line that lists what the expected
Pass/Assert/Fail count should be. If you add/remove/edit tests, please be sure
to update this with your PR.
changelog
---------
* _2.0.0_ Upgrade to Jasmine 2.0.0, remove support for legacy/unused items
* _1.14.1_ Default to noColors if not in a TTY

@@ -247,0 +207,0 @@ * _1.14.0_ Add support for `iit`, `ddescribe` (thanks to [mgcrea](https://github.com/mgcrea))

describe("helper", function() {
it("should load the helpers", function() {
var expectation= expect(true);
expect(typeof(expectation.toHaveProperty)).toBe('function');
});
});
beforeEach(function() {
jasmine.addMatchers(
{
toHaveProperty: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
var result = {};
try {
result.pass = expected in actual;
}
catch (e) {
result.pass = false;
}
if (result.pass) {
result.message = "Expected " + actual + " not to be a property.";
} else {
result.message = "Expected " + actual + " to be a property.";
}
return result
}
}
}
});
});
it("should load the helpers", function() {
expect(expect(true).toHaveProperty).toEqual(jasmine.any(Function));
});
});

@@ -7,6 +7,6 @@ describe('jasmine-node-uber-nested', function(){

describe('failure', function(){
it('should report failure (THIS IS EXPECTED)', function(){
expect(true).toBeFalsy();
it('should report passing', function(){
expect(false).toBeFalsy();
});
});
});

@@ -1,2 +0,2 @@

var jasmineNode = require(__dirname + "/../lib/jasmine-node/reporter").jasmineNode;
var jasmineNode = require(__dirname + "/../lib/jasmine-node/reporter")

@@ -10,61 +10,37 @@ describe('TerminalReporter', function() {

describe("initialize", function() {
it('initializes print_ from config', function() {
it('initializes print from config', function() {
var config = { print: true };
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.print_).toBeTruthy();
expect(this.reporter.config.print).toBeTruthy();
});
it('initializes color_ from config', function() {
var config = { color: true }
it('initializes color from config', function() {
var config = { noColor: false}
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.color_).toEqual(jasmineNode.TerminalReporter.prototype.ANSIColors);
expect(this.reporter.config.color).toEqual(jasmineNode.TerminalReporter.prototype.ANSIColors);
});
it('initializes includeStackTrace_ from config', function () {
it('initializes noStackTrace from config', function () {
var config = {}
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.includeStackTrace_).toBeTruthy();
expect(this.reporter.config.noStackTrace).toBeTruthy();
});
it('sets the started_ flag to false', function() {
it('initializes the specCounts to an Object', function() {
var config = {}
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.started_).toBeFalsy();
expect(this.reporter.counts).toBeDefined();
});
it('sets the finished_ flag to false', function() {
it('sets the callback property to false by default', function() {
var config = {}
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.finished_).toBeFalsy();
expect(this.reporter.config.onComplete).toEqual(jasmine.any(Function))
});
it('initializes the suites_ array', function() {
var config = {}
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.suites_.length).toEqual(0);
});
it('initializes the specResults_ to an Object', function() {
var config = {}
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.specResults_).toBeDefined();
});
it('initializes the failures_ array', function() {
var config = {}
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.failures_.length).toEqual(0);
});
it('sets the callback_ property to false by default', function() {
var config = {}
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.callback_).toEqual(false)
});
it('sets the callback_ property to onComplete if supplied', function() {
it('sets the callback property to callback if supplied', function() {
var foo = function() { }
var config = { onComplete: foo }
this.reporter = new jasmineNode.TerminalReporter(config);
expect(this.reporter.callback_).toBe(foo)
expect(this.reporter.config.onComplete).toBe(foo)
});

@@ -75,423 +51,27 @@ });

beforeEach(function() {
this.spy = spyOn(this.reporter, 'printLine_');
this.spy = spyOn(this.reporter.config, 'print');
var runner = {
topLevelSuites: function() {
var suites = [];
var suite = { id: 25 };
suites.push(suite);
return suites;
}
totalSpecsDefined: 3
};
this.reporter.reportRunnerStarting(runner);
this.reporter.jasmineStarted(runner);
});
it('sets the started_ field to true', function() {
expect(this.reporter.started_).toBeTruthy();
});
it('sets the startedAt field', function() {
// instanceof does not work cross-context (such as when run with requirejs)
var ts = Object.prototype.toString;
expect(ts.call(this.reporter.startedAt)).toBe(ts.call(new Date()));
expect(ts.call(this.reporter.startedAt)).toBe(ts.call(+new Date()));
});
it('buildes the suites_ collection', function() {
expect(this.reporter.suites_.length).toEqual(1);
expect(this.reporter.suites_[0].id).toEqual(25);
});
});
describe('the summarize_ creates suite and spec tree', function() {
beforeEach(function() {
this.spec = {
id: 1,
description: 'the spec',
isSuite: false
}
});
it('creates a summary object from spec', function() {
var result = this.reporter.summarize_(this.spec);
expect(result.id).toEqual(1);
expect(result.name).toEqual('the spec');
expect(result.type).toEqual('spec');
expect(result.children.length).toEqual(0);
});
it('creates a summary object from suite with 1 spec', function() {
var env = { nextSuiteId: false }
var suite = new jasmine.Suite(env, 'suite name', undefined, undefined);
suite.description = 'the suite';
suite.parentSuite = null;
suite.children_.push(this.spec);
var result = this.reporter.summarize_(suite);
expect(result.name).toEqual('the suite');
expect(result.type).toEqual('suite');
expect(result.children.length).toEqual(1);
var suiteChildSpec = result.children[0];
expect(suiteChildSpec.id).toEqual(1);
});
});
describe('reportRunnerResults', function() {
beforeEach(function() {
this.printLineSpy = spyOn(this.reporter, 'printLine_');
});
it('generates the report', function() {
var failuresSpy = spyOn(this.reporter, 'reportFailures_');
var printRunnerResultsSpy = spyOn(this.reporter, 'printRunnerResults_').
andReturn('this is the runner result');
var callbackSpy = spyOn(this.reporter, 'callback_');
var runner = {
results: function() {
var result = { failedCount: 0 };
return result;
},
specs: function() { return []; }
it('buildes the suites collection', function() {
suite = {
"description": "jasmine-node-flat",
"fullName": "jasmine-node-flat",
"id": "suite1",
"status": ""
};
this.reporter.startedAt = new Date();
this.reporter.reportRunnerResults(runner);
expect(failuresSpy).toHaveBeenCalled();
expect(this.printLineSpy).toHaveBeenCalled();
expect(callbackSpy).toHaveBeenCalled();
this.reporter.suiteStarted(suite);
expect(this.reporter.suiteTimes['suite1']).toEqual(jasmine.any(Number));
});
});
describe('reportSpecResults', function() {
beforeEach(function() {
this.printSpy = spyOn(this.reporter, 'print_');
this.spec = {
id: 1,
description: 'the spec',
isSuite: false,
results: function() {
var result = {
passed: function() { return true; }
}
return result;
}
}
});
it('prints a \'.\' for pass', function() {
this.reporter.reportSpecResults(this.spec);
expect(this.printSpy).toHaveBeenCalledWith('.');
});
it('prints an \'F\' for failure', function() {
var addFailureToFailuresSpy = spyOn(this.reporter, 'addFailureToFailures_');
var results = function() {
var result = {
passed: function() { return false; }
}
return result;
}
this.spec.results = results;
this.reporter.reportSpecResults(this.spec);
expect(this.printSpy).toHaveBeenCalledWith('F');
expect(addFailureToFailuresSpy).toHaveBeenCalled();
});
});
describe('addFailureToFailures', function() {
it('adds message and stackTrace to failures_', function() {
var spec = {
suite: {
getFullName: function() { return 'Suite name' }
},
description: 'the spec',
results: function() {
var result = {
items_: function() {
var theItems = new Array();
var item = {
passed_: false,
message: 'the message',
trace: {
stack: 'the stack'
}
}
theItems.push(item);
return theItems;
}.call()
};
return result;
}
};
this.reporter.addFailureToFailures_(spec);
var failures = this.reporter.failures_;
expect(failures.length).toEqual(1);
var failure = failures[0];
expect(failure.spec).toEqual('Suite name the spec');
expect(failure.message).toEqual('the message');
expect(failure.stackTrace).toEqual('the stack');
});
});
describe('prints the runner results', function() {
beforeEach(function() {
this.runner = {
results: function() {
var _results = {
totalCount: 23,
failedCount: 52
};
return _results;
},
specs: function() {
var _specs = new Array();
spec = {
results: function() {
var _results = {
skipped: false
}
return _results;
}
};
_specs.push(spec);
return _specs;
}
};
});
it('uses the specs\'s length, totalCount and failedCount', function() {
var message = this.reporter.printRunnerResults_(this.runner);
expect(message).toEqual('1 test, 23 assertions, 52 failures, 0 skipped\n');
});
});
describe('reports failures', function() {
beforeEach(function() {
this.printSpy = spyOn(this.reporter, 'print_');
this.printLineSpy = spyOn(this.reporter, 'printLine_');
});
it('does not report anything when there are no failures', function() {
this.reporter.failures_ = new Array();
this.reporter.reportFailures_();
expect(this.printLineSpy).not.toHaveBeenCalled();
});
it('prints the failures', function() {
var failure = {
spec: 'the spec',
message: 'the message',
stackTrace: 'the stackTrace'
}
this.reporter.failures_ = new Array();
this.reporter.failures_.push(failure);
this.reporter.reportFailures_();
var generatedOutput =
[ [ '\n' ],
[ '\n' ],
[ ' 1) the spec' ],
[ ' Message:' ],
[ ' the message' ],
[ ' Stacktrace:' ] ];
expect(this.printLineSpy).toHaveBeenCalled();
expect(this.printLineSpy.argsForCall).toEqual(generatedOutput);
expect(this.printSpy).toHaveBeenCalled();
expect(this.printSpy.argsForCall[0]).toEqual(['Failures:']);
expect(this.printSpy.argsForCall[1]).toEqual([' the stackTrace']);
});
it('prints the failures without a Stacktrace', function () {
var config = { includeStackTrace: false };
this.reporter = new jasmineNode.TerminalReporter(config);
this.printSpy = spyOn(this.reporter, 'print_');
this.printLineSpy = spyOn(this.reporter, 'printLine_');
var failure = {
spec: 'the spec',
message: 'the message',
stackTrace: 'the stackTrace'
}
this.reporter.failures_ = new Array();
this.reporter.failures_.push(failure);
this.reporter.reportFailures_();
var generatedOutput =
[ [ '\n' ],
[ '\n' ],
[ ' 1) the spec' ],
[ ' Message:' ],
[ ' the message' ] ];
expect(this.printLineSpy).toHaveBeenCalled();
expect(this.printLineSpy.argsForCall).toEqual(generatedOutput);
expect(this.printSpy).toHaveBeenCalled();
expect(this.printSpy.argsForCall[0]).toEqual(['Failures:']);
expect(this.printSpy.argsForCall[1]).toBeUndefined();
});
});
});
describe('TerminalVerboseReporter', function() {
beforeEach(function() {
var config = {}
this.verboseReporter = new jasmineNode.TerminalVerboseReporter(config);
this.addFailureToFailuresSpy = spyOn(this.verboseReporter, 'addFailureToFailures_');
this.spec = {
id: 23,
results: function() {
return {
failedCount: 1,
getItems: function() {
return ["this is the message"];
}
}
}
};
});
describe('#reportSpecResults', function() {
it('adds the spec to the failures_', function() {
this.verboseReporter.reportSpecResults(this.spec);
expect(this.addFailureToFailuresSpy).toHaveBeenCalledWith(this.spec);
});
it('adds a new object to the specResults_', function() {
this.verboseReporter.reportSpecResults(this.spec);
expect(this.verboseReporter.specResults_[23].messages).toEqual(['this is the message']);
expect(this.verboseReporter.specResults_[23].result).toEqual('failed');
});
});
describe('#buildMessagesFromResults_', function() {
beforeEach(function() {
this.suite = {
id: 17,
type: 'suite',
name: 'a describe block',
suiteNestingLevel: 0,
children: [],
getFullName: function() { return "A spec"; },
};
this.spec = {
id: 23,
type: 'spec',
name: 'a spec block',
children: []
};
this.verboseReporter.specResults_['23'] = {
result: 'passed',
runtime: 200
};
this.verboseReporter.suiteResults_['17'] = {
runtime: 500
};
});
it('does not build anything when the results collection is empty', function() {
var results = [],
messages = [];
this.verboseReporter.buildMessagesFromResults_(messages, results);
expect(messages.length).toEqual(0);
});
it('adds a single suite to the messages', function() {
var results = [],
messages = [];
results.push(this.suite);
this.verboseReporter.buildMessagesFromResults_(messages, results);
expect(messages.length).toEqual(2);
expect(messages[0]).toEqual('');
expect(messages[1]).toEqual('a describe block - 500 ms');
});
it('adds a single spec with success to the messages', function() {
var results = [],
messages = [];
this.passSpy = spyOn(this.verboseReporter.color_, 'pass');
results.push(this.spec);
this.verboseReporter.buildMessagesFromResults_(messages, results);
expect(this.passSpy).toHaveBeenCalled();
expect(messages.length).toEqual(1);
expect(messages[0]).toEqual('a spec block - 200 ms');
});
it('adds a single spec with failure to the messages', function() {
var results = [],
messages = [];
this.verboseReporter.specResults_['23'].result = 'failed';
this.passSpy = spyOn(this.verboseReporter.color_, 'pass');
this.failSpy = spyOn(this.verboseReporter.color_, 'fail');
results.push(this.spec);
this.verboseReporter.buildMessagesFromResults_(messages, results);
expect(this.failSpy).toHaveBeenCalled();
expect(this.passSpy).not.toHaveBeenCalled();
});
it('adds a suite, a suite and a single spec with success to the messages', function() {
var results = [],
messages = [];
var subSuite = new Object();
subSuite.id = '29';
subSuite.type = 'suite';
subSuite.name = 'a sub describe block';
subSuite.suiteNestingLevel = 1;
subSuite.children = [];
subSuite.children.push(this.spec);
this.suite.children.push(subSuite);
results.push(this.suite);
this.verboseReporter.suiteResults_['29'] = {
runtime: 350
};
this.verboseReporter.buildMessagesFromResults_(messages, results);
expect(messages.length).toEqual(5);
expect(messages[0]).toEqual('');
expect(messages[1]).toEqual('a describe block - 500 ms');
expect(messages[2]).toEqual('');
expect(messages[3]).toEqual(' a sub describe block - 350 ms');
expect(messages[4]).toEqual(' a spec block - 200 ms');
});
});
});

@@ -1,2 +0,1 @@

describe('jasmine-node-flat', function(){

@@ -6,2 +5,10 @@ it('should pass', function(){

});
xit('should skip this one', function(){
expect(1+2).toEqual(3);
});
describe('jasmine-node-flat-nested', function(){
it('should also pass', function(){
expect(3).toBe(3);
});
});
});

@@ -27,23 +34,7 @@

describe('Testing some characters', function() {
var chars = ['&', '\'', '"', '<', '>'];
for(var i = 0; i < chars.length; i+=1) {
currentChar = chars[i];
it('should reject ' + currentChar, (function(currentChar) {
expect(false).toEqual(false);
})(currentChar));
}
});
describe('Testing waitsfor functionality', function() {
it("Runs and then waitsFor", function() {
runs(function() {
1+1;
});
waitsFor(function() {
return true === false;
}, "the impossible", 1000);
runs(function() {
expect(true).toBeTruthy();
});
describe('Testing done functionality', function() {
it("calls done", function(done) {
1+1;
expect(true).toBeTruthy();
done();
});

@@ -50,0 +41,0 @@ });

@@ -6,4 +6,7 @@ describe("Manually ticking the Jasmine Mock Clock", function() {

timerCallback = jasmine.createSpy('timerCallback');
jasmine.Clock.useMock();
jasmine.clock().install();
});
afterEach(function() {
jasmine.clock().uninstall();
});

@@ -15,3 +18,3 @@ it("causes a timeout to be called synchronously", function() {

jasmine.Clock.tick(101);
jasmine.clock().tick(101);

@@ -26,12 +29,12 @@ expect(timerCallback).toHaveBeenCalled();

jasmine.Clock.tick(102);
jasmine.clock().tick(102);
expect(timerCallback).toHaveBeenCalled();
expect(timerCallback.callCount).toEqual(1);
expect(timerCallback.calls.count()).toEqual(1);
jasmine.Clock.tick(50);
expect(timerCallback.callCount).toEqual(1);
jasmine.clock().tick(50);
expect(timerCallback.calls.count()).toEqual(1);
jasmine.Clock.tick(50);
expect(timerCallback.callCount).toEqual(2);
jasmine.clock().tick(50);
expect(timerCallback.calls.count()).toEqual(2);
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc