Merging in sconover/jshint
This commit is contained in:
commit
0ef6582f73
27
Rakefile
27
Rakefile
@ -37,30 +37,13 @@ namespace :jasmine do
|
|||||||
|
|
||||||
desc 'Check jasmine sources for coding problems'
|
desc 'Check jasmine sources for coding problems'
|
||||||
task :lint do
|
task :lint do
|
||||||
passed = true
|
puts "Running JSHint via Node.js"
|
||||||
jasmine_sources.each do |src|
|
system("node jshint/run.js") || exit(1)
|
||||||
lines = File.read(src).split(/\n/)
|
|
||||||
lines.each_index do |i|
|
|
||||||
line = lines[i]
|
|
||||||
undefineds = line.scan(/.?undefined/)
|
|
||||||
if undefineds.include?(" undefined") || undefineds.include?("\tundefined")
|
|
||||||
puts "Dangerous undefined at #{src}:#{i}:\n > #{line}"
|
|
||||||
passed = false
|
|
||||||
end
|
|
||||||
|
|
||||||
if line.scan(/window/).length > 0
|
|
||||||
puts "Dangerous window at #{src}:#{i}:\n > #{line}"
|
|
||||||
passed = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
unless passed
|
|
||||||
puts "Lint failed!"
|
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Alias to JSHint"
|
||||||
|
task :hint => :lint
|
||||||
|
|
||||||
desc 'Builds lib/jasmine from source'
|
desc 'Builds lib/jasmine from source'
|
||||||
task :build => :lint do
|
task :build => :lint do
|
||||||
puts 'Building Jasmine from source'
|
puts 'Building Jasmine from source'
|
||||||
|
@ -2,8 +2,8 @@ beforeEach(function() {
|
|||||||
this.addMatchers({
|
this.addMatchers({
|
||||||
toBePlaying: function(expectedSong) {
|
toBePlaying: function(expectedSong) {
|
||||||
var player = this.actual;
|
var player = this.actual;
|
||||||
return player.currentlyPlayingSong === expectedSong
|
return player.currentlyPlayingSong === expectedSong &&
|
||||||
&& player.isPlaying;
|
player.isPlaying;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
5919
jshint/jshint.js
Executable file
5919
jshint/jshint.js
Executable file
File diff suppressed because it is too large
Load Diff
98
jshint/run.js
Normal file
98
jshint/run.js
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
var fs = require("fs");
|
||||||
|
var sys = require("sys");
|
||||||
|
var path = require("path");
|
||||||
|
var JSHINT = require("./jshint").JSHINT;
|
||||||
|
|
||||||
|
function isExcluded(fullPath) {
|
||||||
|
var fileName = path.basename(fullPath);
|
||||||
|
var excludeFiles = ["json2.js", "jshint.js", "publish.js", "node_suite.js", "jasmine.js", "jasmine-html.js"];
|
||||||
|
for (var i = 0; i < excludeFiles.length; i++) {
|
||||||
|
if (fileName == excludeFiles[i]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DWF TODO: This function could/should be re-written
|
||||||
|
function allJasmineJsFiles(rootDir) {
|
||||||
|
var files = [];
|
||||||
|
fs.readdirSync(rootDir).filter(function(filename) {
|
||||||
|
|
||||||
|
var fullPath = rootDir + "/" + filename;
|
||||||
|
if (fs.statSync(fullPath).isDirectory() && !fullPath.match(/pages/)) {
|
||||||
|
var subDirFiles = allJasmineJsFiles(fullPath);
|
||||||
|
if (subDirFiles.length > 0) {
|
||||||
|
files = files.concat();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (fullPath.match(/\.js$/) && !isExcluded(fullPath)) {
|
||||||
|
files.push(fullPath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
var jasmineJsFiles = allJasmineJsFiles(".");
|
||||||
|
jasmineJsFiles.reverse(); //cheap way to do the stuff in src stuff first
|
||||||
|
|
||||||
|
var jasmineJsHintConfig = {
|
||||||
|
|
||||||
|
forin:true, //while it's possible that we could be
|
||||||
|
//considering unwanted prototype methods, mostly
|
||||||
|
//we're doing this because the jsobjects are being
|
||||||
|
//used as maps.
|
||||||
|
|
||||||
|
loopfunc:true //we're fine with functions defined inside loops (setTimeout functions, etc)
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var jasmineGlobals = {};
|
||||||
|
|
||||||
|
|
||||||
|
//jasmine.undefined is a jasmine-ism, let's let it go...
|
||||||
|
function removeJasmineUndefinedErrors(errors) {
|
||||||
|
var keepErrors = [];
|
||||||
|
for (var i = 0; i < errors.length; i++) {
|
||||||
|
if (!(errors[i] &&
|
||||||
|
errors[i].raw &&
|
||||||
|
errors[i].evidence &&
|
||||||
|
( errors[i].evidence.match(/jasmine\.undefined/) ||
|
||||||
|
errors[i].evidence.match(/diz be undefined yo/) )
|
||||||
|
)) {
|
||||||
|
keepErrors.push(errors[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return keepErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var ansi = {
|
||||||
|
green: '\033[32m',
|
||||||
|
red: '\033[31m',
|
||||||
|
yellow: '\033[33m',
|
||||||
|
none: '\033[0m'
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i = 0; i < jasmineJsFiles.length; i++) {
|
||||||
|
var file = jasmineJsFiles[i];
|
||||||
|
JSHINT(fs.readFileSync(file, "utf8"), jasmineJsHintConfig);
|
||||||
|
var errors = JSHINT.data().errors || [];
|
||||||
|
errors = removeJasmineUndefinedErrors(errors);
|
||||||
|
|
||||||
|
if (errors.length >= 1) {
|
||||||
|
console.log(ansi.red + "Jasmine JSHint failure: " + ansi.none);
|
||||||
|
console.log(file);
|
||||||
|
console.log(errors);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(ansi.green + "Jasmine JSHint PASSED." + ansi.none);
|
||||||
|
})();
|
||||||
|
|
@ -110,7 +110,7 @@ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
|
|||||||
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
||||||
var results = suite.results();
|
var results = suite.results();
|
||||||
var status = results.passed() ? 'passed' : 'failed';
|
var status = results.passed() ? 'passed' : 'failed';
|
||||||
if (results.totalCount == 0) { // todo: change this to check results.skipped
|
if (results.totalCount === 0) { // todo: change this to check results.skipped
|
||||||
status = 'skipped';
|
status = 'skipped';
|
||||||
}
|
}
|
||||||
this.suiteDivs[suite.id].className += " " + status;
|
this.suiteDivs[suite.id].className += " " + status;
|
||||||
@ -183,6 +183,8 @@ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
|
|||||||
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!paramMap["spec"]) return true;
|
if (!paramMap.spec) {
|
||||||
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
|
return true;
|
||||||
|
}
|
||||||
|
return spec.getFullName().indexOf(paramMap.spec) === 0;
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
var isCommonJS = typeof window == "undefined";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
|
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var jasmine = {};
|
var jasmine = {};
|
||||||
|
if (isCommonJS) exports.jasmine = jasmine;
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
@ -106,7 +108,8 @@ jasmine.ExpectationResult.prototype.passed = function () {
|
|||||||
* Getter for the Jasmine environment. Ensures one gets created
|
* Getter for the Jasmine environment. Ensures one gets created
|
||||||
*/
|
*/
|
||||||
jasmine.getEnv = function() {
|
jasmine.getEnv = function() {
|
||||||
return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
|
var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
|
||||||
|
return env;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,7 +172,7 @@ jasmine.pp = function(value) {
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
jasmine.isDomNode = function(obj) {
|
jasmine.isDomNode = function(obj) {
|
||||||
return obj['nodeType'] > 0;
|
return obj.nodeType > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -405,7 +408,7 @@ jasmine.isSpy = function(putativeSpy) {
|
|||||||
* @param {Array} methodNames array of names of methods to make spies
|
* @param {Array} methodNames array of names of methods to make spies
|
||||||
*/
|
*/
|
||||||
jasmine.createSpyObj = function(baseName, methodNames) {
|
jasmine.createSpyObj = function(baseName, methodNames) {
|
||||||
if (!jasmine.isArray_(methodNames) || methodNames.length == 0) {
|
if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
|
||||||
throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
|
throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
|
||||||
}
|
}
|
||||||
var obj = {};
|
var obj = {};
|
||||||
@ -443,6 +446,7 @@ jasmine.log = function() {
|
|||||||
var spyOn = function(obj, methodName) {
|
var spyOn = function(obj, methodName) {
|
||||||
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
|
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.spyOn = spyOn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Jasmine spec that will be added to the current suite.
|
* Creates a Jasmine spec that will be added to the current suite.
|
||||||
@ -460,6 +464,7 @@ var spyOn = function(obj, methodName) {
|
|||||||
var it = function(desc, func) {
|
var it = function(desc, func) {
|
||||||
return jasmine.getEnv().it(desc, func);
|
return jasmine.getEnv().it(desc, func);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.it = it;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a <em>disabled</em> Jasmine spec.
|
* Creates a <em>disabled</em> Jasmine spec.
|
||||||
@ -472,6 +477,7 @@ var it = function(desc, func) {
|
|||||||
var xit = function(desc, func) {
|
var xit = function(desc, func) {
|
||||||
return jasmine.getEnv().xit(desc, func);
|
return jasmine.getEnv().xit(desc, func);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.xit = xit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a chain for a Jasmine expectation.
|
* Starts a chain for a Jasmine expectation.
|
||||||
@ -484,6 +490,7 @@ var xit = function(desc, func) {
|
|||||||
var expect = function(actual) {
|
var expect = function(actual) {
|
||||||
return jasmine.getEnv().currentSpec.expect(actual);
|
return jasmine.getEnv().currentSpec.expect(actual);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.expect = expect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
|
* Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
|
||||||
@ -493,6 +500,7 @@ var expect = function(actual) {
|
|||||||
var runs = function(func) {
|
var runs = function(func) {
|
||||||
jasmine.getEnv().currentSpec.runs(func);
|
jasmine.getEnv().currentSpec.runs(func);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.runs = runs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits a fixed time period before moving to the next block.
|
* Waits a fixed time period before moving to the next block.
|
||||||
@ -503,6 +511,7 @@ var runs = function(func) {
|
|||||||
var waits = function(timeout) {
|
var waits = function(timeout) {
|
||||||
jasmine.getEnv().currentSpec.waits(timeout);
|
jasmine.getEnv().currentSpec.waits(timeout);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.waits = waits;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for the latchFunction to return true before proceeding to the next block.
|
* Waits for the latchFunction to return true before proceeding to the next block.
|
||||||
@ -514,6 +523,7 @@ var waits = function(timeout) {
|
|||||||
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
|
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
|
||||||
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
|
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.waitsFor = waitsFor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that is called before each spec in a suite.
|
* A function that is called before each spec in a suite.
|
||||||
@ -525,6 +535,7 @@ var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout
|
|||||||
var beforeEach = function(beforeEachFunction) {
|
var beforeEach = function(beforeEachFunction) {
|
||||||
jasmine.getEnv().beforeEach(beforeEachFunction);
|
jasmine.getEnv().beforeEach(beforeEachFunction);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.beforeEach = beforeEach;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that is called after each spec in a suite.
|
* A function that is called after each spec in a suite.
|
||||||
@ -536,6 +547,7 @@ var beforeEach = function(beforeEachFunction) {
|
|||||||
var afterEach = function(afterEachFunction) {
|
var afterEach = function(afterEachFunction) {
|
||||||
jasmine.getEnv().afterEach(afterEachFunction);
|
jasmine.getEnv().afterEach(afterEachFunction);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.afterEach = afterEach;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a suite of specifications.
|
* Defines a suite of specifications.
|
||||||
@ -555,6 +567,7 @@ var afterEach = function(afterEachFunction) {
|
|||||||
var describe = function(description, specDefinitions) {
|
var describe = function(description, specDefinitions) {
|
||||||
return jasmine.getEnv().describe(description, specDefinitions);
|
return jasmine.getEnv().describe(description, specDefinitions);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.describe = describe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
|
* Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
|
||||||
@ -565,27 +578,27 @@ var describe = function(description, specDefinitions) {
|
|||||||
var xdescribe = function(description, specDefinitions) {
|
var xdescribe = function(description, specDefinitions) {
|
||||||
return jasmine.getEnv().xdescribe(description, specDefinitions);
|
return jasmine.getEnv().xdescribe(description, specDefinitions);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.xdescribe = xdescribe;
|
||||||
|
|
||||||
|
|
||||||
// Provide the XMLHttpRequest class for IE 5.x-6.x:
|
// Provide the XMLHttpRequest class for IE 5.x-6.x:
|
||||||
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
|
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
|
||||||
try {
|
function tryIt(f) {
|
||||||
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
|
try {
|
||||||
} catch(e) {
|
return f();
|
||||||
|
} catch(e) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
|
var xhr = tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.6.0");}) ||
|
||||||
} catch(e) {
|
tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0");}) ||
|
||||||
}
|
tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP");}) ||
|
||||||
try {
|
tryIt(function(){return new ActiveXObject("Microsoft.XMLHTTP");});
|
||||||
return new ActiveXObject("Msxml2.XMLHTTP");
|
|
||||||
} catch(e) {
|
if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
|
||||||
}
|
|
||||||
try {
|
return xhr;
|
||||||
return new ActiveXObject("Microsoft.XMLHTTP");
|
|
||||||
} catch(e) {
|
|
||||||
}
|
|
||||||
throw new Error("This browser does not support XMLHttpRequest.");
|
|
||||||
} : XMLHttpRequest;
|
} : XMLHttpRequest;
|
||||||
/**
|
/**
|
||||||
* @namespace
|
* @namespace
|
||||||
@ -606,7 +619,7 @@ jasmine.util.inherit = function(childClass, parentClass) {
|
|||||||
var subclass = function() {
|
var subclass = function() {
|
||||||
};
|
};
|
||||||
subclass.prototype = parentClass.prototype;
|
subclass.prototype = parentClass.prototype;
|
||||||
childClass.prototype = new subclass;
|
childClass.prototype = new subclass();
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.util.formatException = function(e) {
|
jasmine.util.formatException = function(e) {
|
||||||
@ -828,7 +841,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
|
|||||||
b.__Jasmine_been_here_before__ = a;
|
b.__Jasmine_been_here_before__ = a;
|
||||||
|
|
||||||
var hasKey = function(obj, keyName) {
|
var hasKey = function(obj, keyName) {
|
||||||
return obj != null && obj[keyName] !== jasmine.undefined;
|
return obj !== null && obj[keyName] !== jasmine.undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var property in b) {
|
for (var property in b) {
|
||||||
@ -854,7 +867,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
|
|||||||
|
|
||||||
delete a.__Jasmine_been_here_before__;
|
delete a.__Jasmine_been_here_before__;
|
||||||
delete b.__Jasmine_been_here_before__;
|
delete b.__Jasmine_been_here_before__;
|
||||||
return (mismatchKeys.length == 0 && mismatchValues.length == 0);
|
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
|
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
|
||||||
@ -1302,7 +1315,7 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
|
|||||||
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
|
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
|
||||||
}
|
}
|
||||||
this.message = function() {
|
this.message = function() {
|
||||||
if (this.actual.callCount == 0) {
|
if (this.actual.callCount === 0) {
|
||||||
// todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
|
// todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
|
||||||
return [
|
return [
|
||||||
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
|
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
|
||||||
@ -1333,7 +1346,7 @@ jasmine.Matchers.prototype.wasNotCalledWith = function() {
|
|||||||
return [
|
return [
|
||||||
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
|
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
|
||||||
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
|
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
|
||||||
]
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
return !this.env.contains_(this.actual.argsForCall, expectedArgs);
|
return !this.env.contains_(this.actual.argsForCall, expectedArgs);
|
||||||
@ -1390,7 +1403,7 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
|
|||||||
|
|
||||||
this.message = function() {
|
this.message = function() {
|
||||||
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
|
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
|
||||||
return ["Expected function " + not + "to throw", expected ? expected.message || expected : " an exception", ", but it threw", exception.message || exception].join(' ');
|
return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
|
||||||
} else {
|
} else {
|
||||||
return "Expected function to throw an exception.";
|
return "Expected function to throw an exception.";
|
||||||
}
|
}
|
||||||
@ -1602,7 +1615,8 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
|
|||||||
jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
|
jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
|
||||||
for (var property in obj) {
|
for (var property in obj) {
|
||||||
if (property == '__Jasmine_been_here_before__') continue;
|
if (property == '__Jasmine_been_here_before__') continue;
|
||||||
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false);
|
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
|
||||||
|
obj.__lookupGetter__(property) !== null) : false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2417,5 +2431,5 @@ jasmine.version_= {
|
|||||||
"major": 1,
|
"major": 1,
|
||||||
"minor": 0,
|
"minor": 0,
|
||||||
"build": 2,
|
"build": 2,
|
||||||
"revision": 1298837858
|
"revision": 1299565706
|
||||||
};
|
};
|
||||||
|
233
spec/node_suite.js
Normal file
233
spec/node_suite.js
Normal file
@ -0,0 +1,233 @@
|
|||||||
|
var fs = require('fs');
|
||||||
|
var sys = require('sys');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
|
// yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw]
|
||||||
|
// undefined = "diz be undefined yo";
|
||||||
|
|
||||||
|
var jasmineGlobals = require("../src/base");
|
||||||
|
for(var k in jasmineGlobals) {global[k] = jasmineGlobals[k];}
|
||||||
|
|
||||||
|
//load jasmine src files based on the order in runner.html
|
||||||
|
var srcFilesInProperRequireOrder = [];
|
||||||
|
var runnerHtmlLines = fs.readFileSync("spec/runner.html", "utf8").split("\n");
|
||||||
|
var srcFileLines = [];
|
||||||
|
for (var i=0; i<runnerHtmlLines.length; i++)
|
||||||
|
if (runnerHtmlLines[i].match(/script(.*?)\/src\//))
|
||||||
|
srcFileLines.push(runnerHtmlLines[i]);
|
||||||
|
for (i=0; i<srcFileLines.length; i++) srcFilesInProperRequireOrder.push(srcFileLines[i].match(/src=\"(.*?)\"/)[1]);
|
||||||
|
for (i=0; i<srcFilesInProperRequireOrder.length; i++) require(srcFilesInProperRequireOrder[i]);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Pulling in code from jasmine-node.
|
||||||
|
|
||||||
|
We can't just depend on jasmine-node because it has its own jasmine that it uses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
global.window = {
|
||||||
|
setTimeout: setTimeout,
|
||||||
|
clearTimeout: clearTimeout,
|
||||||
|
setInterval: setInterval,
|
||||||
|
clearInterval: clearInterval
|
||||||
|
};
|
||||||
|
|
||||||
|
delete global.window;
|
||||||
|
|
||||||
|
function noop(){}
|
||||||
|
|
||||||
|
jasmine.executeSpecs = function(specs, done, isVerbose, showColors){
|
||||||
|
var log = [];
|
||||||
|
var columnCounter = 0;
|
||||||
|
var start = 0;
|
||||||
|
var elapsed = 0;
|
||||||
|
var verbose = isVerbose || false;
|
||||||
|
var colors = showColors || false;
|
||||||
|
|
||||||
|
var ansi = {
|
||||||
|
green: '\033[32m',
|
||||||
|
red: '\033[31m',
|
||||||
|
yellow: '\033[33m',
|
||||||
|
none: '\033[0m'
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i = 0, len = specs.length; i < len; ++i){
|
||||||
|
var filename = specs[i];
|
||||||
|
require(filename.replace(/\.\w+$/, ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
var jasmineEnv = jasmine.getEnv();
|
||||||
|
jasmineEnv.reporter = {
|
||||||
|
log: function(str){
|
||||||
|
},
|
||||||
|
|
||||||
|
reportSpecStarting: function(runner) {
|
||||||
|
},
|
||||||
|
|
||||||
|
reportRunnerStarting: function(runner) {
|
||||||
|
sys.puts('Started');
|
||||||
|
start = new Date().getTime();
|
||||||
|
},
|
||||||
|
|
||||||
|
reportSuiteResults: function(suite) {
|
||||||
|
var specResults = suite.results();
|
||||||
|
var path = [];
|
||||||
|
while(suite) {
|
||||||
|
path.unshift(suite.description);
|
||||||
|
suite = suite.parentSuite;
|
||||||
|
}
|
||||||
|
var description = path.join(' ');
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
log.push('Spec ' + description);
|
||||||
|
|
||||||
|
specResults.items_.forEach(function(spec){
|
||||||
|
if (spec.failedCount > 0 && spec.description) {
|
||||||
|
if (!verbose)
|
||||||
|
log.push(description);
|
||||||
|
log.push(' it ' + spec.description);
|
||||||
|
spec.items_.forEach(function(result){
|
||||||
|
log.push(' ' + result.trace.stack + '\n');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
reportSpecResults: function(spec) {
|
||||||
|
var result = spec.results();
|
||||||
|
var msg = '';
|
||||||
|
if (result.passed())
|
||||||
|
{
|
||||||
|
msg = (colors) ? (ansi.green + '.' + ansi.none) : '.';
|
||||||
|
// } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec?
|
||||||
|
// msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*';
|
||||||
|
} else {
|
||||||
|
msg = (colors) ? (ansi.red + 'F' + ansi.none) : 'F';
|
||||||
|
}
|
||||||
|
sys.print(msg);
|
||||||
|
if (columnCounter++ < 50) return;
|
||||||
|
columnCounter = 0;
|
||||||
|
sys.print('\n');
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
reportRunnerResults: function(runner) {
|
||||||
|
elapsed = (new Date().getTime() - start) / 1000;
|
||||||
|
sys.puts('\n');
|
||||||
|
log.forEach(function(log){
|
||||||
|
sys.puts(log);
|
||||||
|
});
|
||||||
|
sys.puts('Finished in ' + elapsed + ' seconds');
|
||||||
|
|
||||||
|
var summary = jasmine.printRunnerResults(runner);
|
||||||
|
if(colors)
|
||||||
|
{
|
||||||
|
if(runner.results().failedCount === 0 )
|
||||||
|
sys.puts(ansi.green + summary + ansi.none);
|
||||||
|
else
|
||||||
|
sys.puts(ansi.red + summary + ansi.none);
|
||||||
|
} else {
|
||||||
|
sys.puts(summary);
|
||||||
|
}
|
||||||
|
(done||noop)(runner, log);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
jasmineEnv.execute();
|
||||||
|
};
|
||||||
|
|
||||||
|
jasmine.getAllSpecFiles = function(dir, matcher){
|
||||||
|
var specs = [];
|
||||||
|
|
||||||
|
if (fs.statSync(dir).isFile() && dir.match(matcher)) {
|
||||||
|
specs.push(dir);
|
||||||
|
} else {
|
||||||
|
var files = fs.readdirSync(dir);
|
||||||
|
for (var i = 0, len = files.length; i < len; ++i){
|
||||||
|
var filename = dir + '/' + files[i];
|
||||||
|
if (fs.statSync(filename).isFile() && filename.match(matcher)){
|
||||||
|
specs.push(filename);
|
||||||
|
}else if (fs.statSync(filename).isDirectory()){
|
||||||
|
var subfiles = this.getAllSpecFiles(filename, matcher);
|
||||||
|
subfiles.forEach(function(result){
|
||||||
|
specs.push(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return specs;
|
||||||
|
};
|
||||||
|
|
||||||
|
jasmine.printRunnerResults = function(runner){
|
||||||
|
var results = runner.results();
|
||||||
|
var suites = runner.suites();
|
||||||
|
var msg = '';
|
||||||
|
msg += suites.length + ' test' + ((suites.length === 1) ? '' : 's') + ', ';
|
||||||
|
msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', ';
|
||||||
|
msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n';
|
||||||
|
return msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
function now(){
|
||||||
|
return new Date().getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
jasmine.asyncSpecWait = function(){
|
||||||
|
var wait = jasmine.asyncSpecWait;
|
||||||
|
wait.start = now();
|
||||||
|
wait.done = false;
|
||||||
|
(function innerWait(){
|
||||||
|
waits(10);
|
||||||
|
runs(function() {
|
||||||
|
if (wait.start + wait.timeout < now()) {
|
||||||
|
expect('timeout waiting for spec').toBeNull();
|
||||||
|
} else if (wait.done) {
|
||||||
|
wait.done = false;
|
||||||
|
} else {
|
||||||
|
innerWait();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
jasmine.asyncSpecWait.timeout = 4 * 1000;
|
||||||
|
jasmine.asyncSpecDone = function(){
|
||||||
|
jasmine.asyncSpecWait.done = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
for ( var key in jasmine) {
|
||||||
|
exports[key] = jasmine[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
End jasmine-node runner
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var isVerbose = false;
|
||||||
|
var showColors = true;
|
||||||
|
process.argv.forEach(function(arg){
|
||||||
|
switch(arg) {
|
||||||
|
case '--color': showColors = true; break;
|
||||||
|
case '--noColor': showColors = false; break;
|
||||||
|
case '--verbose': isVerbose = true; break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var specs = jasmine.getAllSpecFiles(__dirname + '/suites', new RegExp(".js$"));
|
||||||
|
var domIndependentSpecs = [];
|
||||||
|
for(var i=0; i<specs.length; i++) {
|
||||||
|
if (fs.readFileSync(specs[i], "utf8").indexOf("document.createElement")<0) {
|
||||||
|
domIndependentSpecs.push(specs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jasmine.executeSpecs(domIndependentSpecs, function(runner, log){
|
||||||
|
if (runner.results().failedCount === 0) {
|
||||||
|
process.exit(0);
|
||||||
|
} else {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}, isVerbose, showColors);
|
@ -108,7 +108,7 @@ describe("jasmine.Env", function() {
|
|||||||
|
|
||||||
it("should give custom equality testers precedence", function() {
|
it("should give custom equality testers precedence", function() {
|
||||||
expect(env.equals_('abc', 'abc')).toBeFalsy();
|
expect(env.equals_('abc', 'abc')).toBeFalsy();
|
||||||
var o = new Object();
|
var o = {};
|
||||||
expect(env.equals_(o, o)).toBeFalsy();
|
expect(env.equals_(o, o)).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -89,9 +89,9 @@ describe('Exceptions:', function() {
|
|||||||
expect(blockResults[0].message).toMatch(/fake error 1/);
|
expect(blockResults[0].message).toMatch(/fake error 1/);
|
||||||
|
|
||||||
expect(specResults[1].passed()).toEqual(false);
|
expect(specResults[1].passed()).toEqual(false);
|
||||||
var blockResults = specResults[1].getItems();
|
blockResults = specResults[1].getItems();
|
||||||
expect(blockResults[0].passed()).toEqual(false);
|
expect(blockResults[0].passed()).toEqual(false);
|
||||||
expect(blockResults[0].message).toMatch(/fake error 2/),
|
expect(blockResults[0].message).toMatch(/fake error 2/);
|
||||||
expect(blockResults[1].passed()).toEqual(true);
|
expect(blockResults[1].passed()).toEqual(true);
|
||||||
|
|
||||||
expect(specResults[2].passed()).toEqual(true);
|
expect(specResults[2].passed()).toEqual(true);
|
||||||
|
@ -21,7 +21,7 @@ describe('jasmine.jsApiReporter', function() {
|
|||||||
nestedSuite = env.describe("nested suite", function() {
|
nestedSuite = env.describe("nested suite", function() {
|
||||||
nestedSpec = env.it("nested spec", function() {
|
nestedSpec = env.it("nested spec", function() {
|
||||||
expect(true).toEqual(true);
|
expect(true).toEqual(true);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
spec3 = env.it("spec 3", function() {
|
spec3 = env.it("spec 3", function() {
|
||||||
|
@ -18,7 +18,7 @@ describe("jasmine.Matchers", function() {
|
|||||||
toFail: function() {
|
toFail: function() {
|
||||||
return !lastResult().passed();
|
return !lastResult().passed();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function match(value) {
|
function match(value) {
|
||||||
@ -68,15 +68,15 @@ describe("jasmine.Matchers", function() {
|
|||||||
expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toFail();
|
expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toFail();
|
||||||
expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toFail();
|
expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toFail();
|
||||||
|
|
||||||
expect((match(new String("cat")).toEqual("cat"))).toPass();
|
expect((match("cat").toEqual("cat"))).toPass();
|
||||||
expect((match(new String("cat")).toNotEqual("cat"))).toFail();
|
expect((match("cat").toNotEqual("cat"))).toFail();
|
||||||
|
|
||||||
expect((match(new Number(5)).toEqual(5))).toPass();
|
expect((match(5).toEqual(5))).toPass();
|
||||||
expect((match(new Number('5')).toEqual(5))).toPass();
|
expect((match(parseInt('5', 10)).toEqual(5))).toPass();
|
||||||
expect((match(new Number(5)).toNotEqual(5))).toFail();
|
expect((match(5).toNotEqual(5))).toFail();
|
||||||
expect((match(new Number('5')).toNotEqual(5))).toFail();
|
expect((match(parseInt('5', 10)).toNotEqual(5))).toFail();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("toEqual with DOM nodes", function() {
|
it("toEqual with DOM nodes", function() {
|
||||||
var nodeA = document.createElement('div');
|
var nodeA = document.createElement('div');
|
||||||
var nodeB = document.createElement('div');
|
var nodeB = document.createElement('div');
|
||||||
@ -500,7 +500,7 @@ describe("jasmine.Matchers", function() {
|
|||||||
describe("and matcher is inverted with .not", function() {
|
describe("and matcher is inverted with .not", function() {
|
||||||
it("should match any exception", function() {
|
it("should match any exception", function() {
|
||||||
expect(match(throwingFn).not.toThrow()).toFail();
|
expect(match(throwingFn).not.toThrow()).toFail();
|
||||||
expect(lastResult().message).toMatch(/Expected function not to throw an exception/);
|
expect(lastResult().message).toMatch(/Expected function not to throw an exception/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should match exceptions specified by message", function() {
|
it("should match exceptions specified by message", function() {
|
||||||
|
@ -18,9 +18,9 @@ describe("jasmine.MultiReporter", function() {
|
|||||||
delegate[methodName] = jasmine.createSpy(methodName);
|
delegate[methodName] = jasmine.createSpy(methodName);
|
||||||
this.actual[methodName]("whatever argument");
|
this.actual[methodName]("whatever argument");
|
||||||
|
|
||||||
return delegate[methodName].wasCalled
|
return delegate[methodName].wasCalled &&
|
||||||
&& delegate[methodName].mostRecentCall.args.length == 1
|
delegate[methodName].mostRecentCall.args.length == 1 &&
|
||||||
&& delegate[methodName].mostRecentCall.args[0] == "whatever argument";
|
delegate[methodName].mostRecentCall.args[0] == "whatever argument";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ describe('Spec', function () {
|
|||||||
|
|
||||||
it('getFullName returns suite & spec description', function () {
|
it('getFullName returns suite & spec description', function () {
|
||||||
var spec = new jasmine.Spec(env, suite, 'spec 1');
|
var spec = new jasmine.Spec(env, suite, 'spec 1');
|
||||||
expect(spec.getFullName()).toEqual('suite 1 spec 1.')
|
expect(spec.getFullName()).toEqual('suite 1 spec 1.');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('results', function () {
|
describe('results', function () {
|
||||||
|
@ -25,7 +25,6 @@ describe("jasmine.util", function() {
|
|||||||
it("should return true if the argument is an array", function() {
|
it("should return true if the argument is an array", function() {
|
||||||
expect(jasmine.isArray_([])).toBe(true);
|
expect(jasmine.isArray_([])).toBe(true);
|
||||||
expect(jasmine.isArray_(['a'])).toBe(true);
|
expect(jasmine.isArray_(['a'])).toBe(true);
|
||||||
expect(jasmine.isArray_(new Array())).toBe(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false if the argument is not an array", function() {
|
it("should return false if the argument is not an array", function() {
|
||||||
|
@ -172,7 +172,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
|
|||||||
b.__Jasmine_been_here_before__ = a;
|
b.__Jasmine_been_here_before__ = a;
|
||||||
|
|
||||||
var hasKey = function(obj, keyName) {
|
var hasKey = function(obj, keyName) {
|
||||||
return obj != null && obj[keyName] !== jasmine.undefined;
|
return obj !== null && obj[keyName] !== jasmine.undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var property in b) {
|
for (var property in b) {
|
||||||
@ -198,7 +198,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
|
|||||||
|
|
||||||
delete a.__Jasmine_been_here_before__;
|
delete a.__Jasmine_been_here_before__;
|
||||||
delete b.__Jasmine_been_here_before__;
|
delete b.__Jasmine_been_here_before__;
|
||||||
return (mismatchKeys.length == 0 && mismatchValues.length == 0);
|
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
|
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
|
||||||
|
@ -227,7 +227,7 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
|
|||||||
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
|
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
|
||||||
}
|
}
|
||||||
this.message = function() {
|
this.message = function() {
|
||||||
if (this.actual.callCount == 0) {
|
if (this.actual.callCount === 0) {
|
||||||
// todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
|
// todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
|
||||||
return [
|
return [
|
||||||
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
|
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.",
|
||||||
@ -258,7 +258,7 @@ jasmine.Matchers.prototype.wasNotCalledWith = function() {
|
|||||||
return [
|
return [
|
||||||
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
|
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
|
||||||
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
|
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
|
||||||
]
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
return !this.env.contains_(this.actual.argsForCall, expectedArgs);
|
return !this.env.contains_(this.actual.argsForCall, expectedArgs);
|
||||||
@ -315,7 +315,7 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
|
|||||||
|
|
||||||
this.message = function() {
|
this.message = function() {
|
||||||
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
|
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
|
||||||
return ["Expected function " + not + "to throw", expected ? expected.message || expected : " an exception", ", but it threw", exception.message || exception].join(' ');
|
return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
|
||||||
} else {
|
} else {
|
||||||
return "Expected function to throw an exception.";
|
return "Expected function to throw an exception.";
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
|
|||||||
jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
|
jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
|
||||||
for (var property in obj) {
|
for (var property in obj) {
|
||||||
if (property == '__Jasmine_been_here_before__') continue;
|
if (property == '__Jasmine_been_here_before__') continue;
|
||||||
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false);
|
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
|
||||||
|
obj.__lookupGetter__(property) !== null) : false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
55
src/base.js
55
src/base.js
@ -1,10 +1,12 @@
|
|||||||
|
var isCommonJS = typeof window == "undefined";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
|
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var jasmine = {};
|
var jasmine = {};
|
||||||
|
if (isCommonJS) exports.jasmine = jasmine;
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
@ -106,7 +108,8 @@ jasmine.ExpectationResult.prototype.passed = function () {
|
|||||||
* Getter for the Jasmine environment. Ensures one gets created
|
* Getter for the Jasmine environment. Ensures one gets created
|
||||||
*/
|
*/
|
||||||
jasmine.getEnv = function() {
|
jasmine.getEnv = function() {
|
||||||
return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
|
var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
|
||||||
|
return env;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,7 +172,7 @@ jasmine.pp = function(value) {
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
jasmine.isDomNode = function(obj) {
|
jasmine.isDomNode = function(obj) {
|
||||||
return obj['nodeType'] > 0;
|
return obj.nodeType > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -405,7 +408,7 @@ jasmine.isSpy = function(putativeSpy) {
|
|||||||
* @param {Array} methodNames array of names of methods to make spies
|
* @param {Array} methodNames array of names of methods to make spies
|
||||||
*/
|
*/
|
||||||
jasmine.createSpyObj = function(baseName, methodNames) {
|
jasmine.createSpyObj = function(baseName, methodNames) {
|
||||||
if (!jasmine.isArray_(methodNames) || methodNames.length == 0) {
|
if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
|
||||||
throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
|
throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
|
||||||
}
|
}
|
||||||
var obj = {};
|
var obj = {};
|
||||||
@ -443,6 +446,7 @@ jasmine.log = function() {
|
|||||||
var spyOn = function(obj, methodName) {
|
var spyOn = function(obj, methodName) {
|
||||||
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
|
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.spyOn = spyOn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Jasmine spec that will be added to the current suite.
|
* Creates a Jasmine spec that will be added to the current suite.
|
||||||
@ -460,6 +464,7 @@ var spyOn = function(obj, methodName) {
|
|||||||
var it = function(desc, func) {
|
var it = function(desc, func) {
|
||||||
return jasmine.getEnv().it(desc, func);
|
return jasmine.getEnv().it(desc, func);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.it = it;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a <em>disabled</em> Jasmine spec.
|
* Creates a <em>disabled</em> Jasmine spec.
|
||||||
@ -472,6 +477,7 @@ var it = function(desc, func) {
|
|||||||
var xit = function(desc, func) {
|
var xit = function(desc, func) {
|
||||||
return jasmine.getEnv().xit(desc, func);
|
return jasmine.getEnv().xit(desc, func);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.xit = xit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a chain for a Jasmine expectation.
|
* Starts a chain for a Jasmine expectation.
|
||||||
@ -484,6 +490,7 @@ var xit = function(desc, func) {
|
|||||||
var expect = function(actual) {
|
var expect = function(actual) {
|
||||||
return jasmine.getEnv().currentSpec.expect(actual);
|
return jasmine.getEnv().currentSpec.expect(actual);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.expect = expect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
|
* Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
|
||||||
@ -493,6 +500,7 @@ var expect = function(actual) {
|
|||||||
var runs = function(func) {
|
var runs = function(func) {
|
||||||
jasmine.getEnv().currentSpec.runs(func);
|
jasmine.getEnv().currentSpec.runs(func);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.runs = runs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits a fixed time period before moving to the next block.
|
* Waits a fixed time period before moving to the next block.
|
||||||
@ -503,6 +511,7 @@ var runs = function(func) {
|
|||||||
var waits = function(timeout) {
|
var waits = function(timeout) {
|
||||||
jasmine.getEnv().currentSpec.waits(timeout);
|
jasmine.getEnv().currentSpec.waits(timeout);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.waits = waits;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for the latchFunction to return true before proceeding to the next block.
|
* Waits for the latchFunction to return true before proceeding to the next block.
|
||||||
@ -514,6 +523,7 @@ var waits = function(timeout) {
|
|||||||
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
|
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
|
||||||
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
|
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.waitsFor = waitsFor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that is called before each spec in a suite.
|
* A function that is called before each spec in a suite.
|
||||||
@ -525,6 +535,7 @@ var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout
|
|||||||
var beforeEach = function(beforeEachFunction) {
|
var beforeEach = function(beforeEachFunction) {
|
||||||
jasmine.getEnv().beforeEach(beforeEachFunction);
|
jasmine.getEnv().beforeEach(beforeEachFunction);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.beforeEach = beforeEach;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that is called after each spec in a suite.
|
* A function that is called after each spec in a suite.
|
||||||
@ -536,6 +547,7 @@ var beforeEach = function(beforeEachFunction) {
|
|||||||
var afterEach = function(afterEachFunction) {
|
var afterEach = function(afterEachFunction) {
|
||||||
jasmine.getEnv().afterEach(afterEachFunction);
|
jasmine.getEnv().afterEach(afterEachFunction);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.afterEach = afterEach;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a suite of specifications.
|
* Defines a suite of specifications.
|
||||||
@ -555,6 +567,7 @@ var afterEach = function(afterEachFunction) {
|
|||||||
var describe = function(description, specDefinitions) {
|
var describe = function(description, specDefinitions) {
|
||||||
return jasmine.getEnv().describe(description, specDefinitions);
|
return jasmine.getEnv().describe(description, specDefinitions);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.describe = describe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
|
* Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
|
||||||
@ -565,25 +578,25 @@ var describe = function(description, specDefinitions) {
|
|||||||
var xdescribe = function(description, specDefinitions) {
|
var xdescribe = function(description, specDefinitions) {
|
||||||
return jasmine.getEnv().xdescribe(description, specDefinitions);
|
return jasmine.getEnv().xdescribe(description, specDefinitions);
|
||||||
};
|
};
|
||||||
|
if (isCommonJS) exports.xdescribe = xdescribe;
|
||||||
|
|
||||||
|
|
||||||
// Provide the XMLHttpRequest class for IE 5.x-6.x:
|
// Provide the XMLHttpRequest class for IE 5.x-6.x:
|
||||||
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
|
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
|
||||||
try {
|
function tryIt(f) {
|
||||||
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
|
try {
|
||||||
} catch(e) {
|
return f();
|
||||||
|
} catch(e) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
|
var xhr = tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.6.0");}) ||
|
||||||
} catch(e) {
|
tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0");}) ||
|
||||||
}
|
tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP");}) ||
|
||||||
try {
|
tryIt(function(){return new ActiveXObject("Microsoft.XMLHTTP");});
|
||||||
return new ActiveXObject("Msxml2.XMLHTTP");
|
|
||||||
} catch(e) {
|
if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
|
||||||
}
|
|
||||||
try {
|
return xhr;
|
||||||
return new ActiveXObject("Microsoft.XMLHTTP");
|
} : XMLHttpRequest;
|
||||||
} catch(e) {
|
|
||||||
}
|
|
||||||
throw new Error("This browser does not support XMLHttpRequest.");
|
|
||||||
} : XMLHttpRequest;
|
|
@ -110,7 +110,7 @@ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
|
|||||||
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
||||||
var results = suite.results();
|
var results = suite.results();
|
||||||
var status = results.passed() ? 'passed' : 'failed';
|
var status = results.passed() ? 'passed' : 'failed';
|
||||||
if (results.totalCount == 0) { // todo: change this to check results.skipped
|
if (results.totalCount === 0) { // todo: change this to check results.skipped
|
||||||
status = 'skipped';
|
status = 'skipped';
|
||||||
}
|
}
|
||||||
this.suiteDivs[suite.id].className += " " + status;
|
this.suiteDivs[suite.id].className += " " + status;
|
||||||
@ -183,6 +183,8 @@ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
|
|||||||
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!paramMap["spec"]) return true;
|
if (!paramMap.spec) {
|
||||||
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
|
return true;
|
||||||
|
}
|
||||||
|
return spec.getFullName().indexOf(paramMap.spec) === 0;
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ jasmine.util.inherit = function(childClass, parentClass) {
|
|||||||
var subclass = function() {
|
var subclass = function() {
|
||||||
};
|
};
|
||||||
subclass.prototype = parentClass.prototype;
|
subclass.prototype = parentClass.prototype;
|
||||||
childClass.prototype = new subclass;
|
childClass.prototype = new subclass();
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.util.formatException = function(e) {
|
jasmine.util.formatException = function(e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user