seedrandom
Advanced tools
Comparing version 2.3.3 to 2.3.4
{ | ||
"name": "seedrandom", | ||
"version": "2.3.1", | ||
"version": "2.3.4", | ||
"description": "Seeded random number generator for Javascript.", | ||
@@ -5,0 +5,0 @@ "devDependencies": { |
{ | ||
"name": "seedrandom", | ||
"version": "2.3.3", | ||
"version": "2.3.4", | ||
"description": "Seeded random number generator for Javascript.", | ||
"main": "seedrandom.js", | ||
"keywords": [ | ||
"random", "seed", "crypto" | ||
], | ||
"scripts": { | ||
@@ -20,10 +23,10 @@ "test": "grunt" | ||
"devDependencies": { | ||
"grunt": "0.4.2", | ||
"grunt-bowercopy": "0.4.1", | ||
"grunt-cli": "0.1.11", | ||
"grunt-contrib-uglify": "0.2.7", | ||
"grunt-contrib-qunit": "0.3.0", | ||
"grunt-release": "0.6.0", | ||
"phantomjs": "1.9.2-6" | ||
"grunt": "latest", | ||
"grunt-bowercopy": "latest", | ||
"grunt-cli": "latest", | ||
"grunt-contrib-uglify": "latest", | ||
"grunt-contrib-qunit": "latest", | ||
"grunt-release": "latest", | ||
"phantomjs": "latest" | ||
} | ||
} |
@@ -6,6 +6,6 @@ seedrandom.js | ||
version 2.3.3 | ||
version 2.3.4<br> | ||
Author: David Bau<br> | ||
Date: 2014 Mar 9 | ||
Date: 2014 Feb 4 | ||
Defines a method Math.seedrandom() that, when called, substitutes | ||
@@ -33,6 +33,10 @@ an explicitly seeded RC4-based algorithm for Math.random(). Also | ||
// together with accumulated entropy. | ||
</pre> | ||
<pre> | ||
<script src="https://jsonlib.appspot.com/urandom?callback=Math.seedrandom"> | ||
</script> <!-- Seeds using urandom bits from a server. --> | ||
</script> <!-- Seeds using urandom bits from a server. --> | ||
</pre> | ||
<pre> | ||
Math.seedrandom("hello."); // Behavior is the same everywhere: | ||
@@ -108,2 +112,4 @@ document.write(Math.random()); // Always 0.9282578795792454 | ||
* Version 2.3.1 adds a build environment, module packaging, and tests. | ||
* Version 2.3.3 fixes bugs on IE8, and switches to MIT license. | ||
* Version 2.3.4 fixes documentation to contain the MIT license. | ||
@@ -146,19 +152,20 @@ The standard ARC4 key scheduler cycles short keys, which means that | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
@@ -1,4 +0,4 @@ | ||
// seedrandom.js version 2.3.3 | ||
// seedrandom.js version 2.3.4 | ||
// Author: David Bau | ||
// Date: 2014 Feb 4 | ||
// Date: 2014 Mar 9 | ||
// | ||
@@ -92,2 +92,3 @@ // Defines a method Math.seedrandom() that, when called, substitutes | ||
// * Version 2.3.3 fixes bugs on IE8, and switches to MIT license. | ||
// * Version 2.3.4 fixes documentation to contain the MIT license. | ||
// | ||
@@ -126,32 +127,25 @@ // The standard ARC4 key scheduler cycles short keys, which means that | ||
// | ||
// LICENSE (BSD): | ||
// LICENSE (MIT): | ||
// | ||
// Copyright 2013 David Bau, all rights reserved. | ||
// Copyright (c)2014 David Bau. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are met: | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// 1. Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// 2. Redistributions in binary form must reproduce the above copyright | ||
// notice, this list of conditions and the following disclaimer in the | ||
// documentation and/or other materials provided with the distribution. | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// | ||
// 3. Neither the name of this module nor the names of its contributors may | ||
// be used to endorse or promote products derived from this software | ||
// without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
@@ -158,0 +152,0 @@ /** |
@@ -1,9 +0,10 @@ | ||
/** | ||
* QUnit v1.12.0 - A JavaScript Unit Testing Framework | ||
/*! | ||
* QUnit 1.14.0 | ||
* http://qunitjs.com/ | ||
* | ||
* http://qunitjs.com | ||
* Copyright 2013 jQuery Foundation and other contributors | ||
* Released under the MIT license | ||
* http://jquery.org/license | ||
* | ||
* Copyright 2013 jQuery Foundation and other contributors | ||
* Released under the MIT license. | ||
* https://jquery.org/license/ | ||
* Date: 2014-01-31T16:40Z | ||
*/ | ||
@@ -24,3 +25,5 @@ | ||
setTimeout = window.setTimeout, | ||
clearTimeout = window.clearTimeout, | ||
defined = { | ||
document: typeof window.document !== "undefined", | ||
setTimeout: typeof window.setTimeout !== "undefined", | ||
@@ -88,299 +91,3 @@ sessionStorage: (function() { | ||
function Test( settings ) { | ||
extend( this, settings ); | ||
this.assertions = []; | ||
this.testNumber = ++Test.count; | ||
} | ||
Test.count = 0; | ||
Test.prototype = { | ||
init: function() { | ||
var a, b, li, | ||
tests = id( "qunit-tests" ); | ||
if ( tests ) { | ||
b = document.createElement( "strong" ); | ||
b.innerHTML = this.nameHtml; | ||
// `a` initialized at top of scope | ||
a = document.createElement( "a" ); | ||
a.innerHTML = "Rerun"; | ||
a.href = QUnit.url({ testNumber: this.testNumber }); | ||
li = document.createElement( "li" ); | ||
li.appendChild( b ); | ||
li.appendChild( a ); | ||
li.className = "running"; | ||
li.id = this.id = "qunit-test-output" + testId++; | ||
tests.appendChild( li ); | ||
} | ||
}, | ||
setup: function() { | ||
if ( | ||
// Emit moduleStart when we're switching from one module to another | ||
this.module !== config.previousModule || | ||
// They could be equal (both undefined) but if the previousModule property doesn't | ||
// yet exist it means this is the first test in a suite that isn't wrapped in a | ||
// module, in which case we'll just emit a moduleStart event for 'undefined'. | ||
// Without this, reporters can get testStart before moduleStart which is a problem. | ||
!hasOwn.call( config, "previousModule" ) | ||
) { | ||
if ( hasOwn.call( config, "previousModule" ) ) { | ||
runLoggingCallbacks( "moduleDone", QUnit, { | ||
name: config.previousModule, | ||
failed: config.moduleStats.bad, | ||
passed: config.moduleStats.all - config.moduleStats.bad, | ||
total: config.moduleStats.all | ||
}); | ||
} | ||
config.previousModule = this.module; | ||
config.moduleStats = { all: 0, bad: 0 }; | ||
runLoggingCallbacks( "moduleStart", QUnit, { | ||
name: this.module | ||
}); | ||
} | ||
config.current = this; | ||
this.testEnvironment = extend({ | ||
setup: function() {}, | ||
teardown: function() {} | ||
}, this.moduleTestEnvironment ); | ||
this.started = +new Date(); | ||
runLoggingCallbacks( "testStart", QUnit, { | ||
name: this.testName, | ||
module: this.module | ||
}); | ||
/*jshint camelcase:false */ | ||
/** | ||
* Expose the current test environment. | ||
* | ||
* @deprecated since 1.12.0: Use QUnit.config.current.testEnvironment instead. | ||
*/ | ||
QUnit.current_testEnvironment = this.testEnvironment; | ||
/*jshint camelcase:true */ | ||
if ( !config.pollution ) { | ||
saveGlobal(); | ||
} | ||
if ( config.notrycatch ) { | ||
this.testEnvironment.setup.call( this.testEnvironment, QUnit.assert ); | ||
return; | ||
} | ||
try { | ||
this.testEnvironment.setup.call( this.testEnvironment, QUnit.assert ); | ||
} catch( e ) { | ||
QUnit.pushFailure( "Setup failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) ); | ||
} | ||
}, | ||
run: function() { | ||
config.current = this; | ||
var running = id( "qunit-testresult" ); | ||
if ( running ) { | ||
running.innerHTML = "Running: <br/>" + this.nameHtml; | ||
} | ||
if ( this.async ) { | ||
QUnit.stop(); | ||
} | ||
this.callbackStarted = +new Date(); | ||
if ( config.notrycatch ) { | ||
this.callback.call( this.testEnvironment, QUnit.assert ); | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
return; | ||
} | ||
try { | ||
this.callback.call( this.testEnvironment, QUnit.assert ); | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
} catch( e ) { | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + ( e.message || e ), extractStacktrace( e, 0 ) ); | ||
// else next test will carry the responsibility | ||
saveGlobal(); | ||
// Restart the tests if they're blocking | ||
if ( config.blocking ) { | ||
QUnit.start(); | ||
} | ||
} | ||
}, | ||
teardown: function() { | ||
config.current = this; | ||
if ( config.notrycatch ) { | ||
if ( typeof this.callbackRuntime === "undefined" ) { | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
} | ||
this.testEnvironment.teardown.call( this.testEnvironment, QUnit.assert ); | ||
return; | ||
} else { | ||
try { | ||
this.testEnvironment.teardown.call( this.testEnvironment, QUnit.assert ); | ||
} catch( e ) { | ||
QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) ); | ||
} | ||
} | ||
checkPollution(); | ||
}, | ||
finish: function() { | ||
config.current = this; | ||
if ( config.requireExpects && this.expected === null ) { | ||
QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack ); | ||
} else if ( this.expected !== null && this.expected !== this.assertions.length ) { | ||
QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack ); | ||
} else if ( this.expected === null && !this.assertions.length ) { | ||
QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack ); | ||
} | ||
var i, assertion, a, b, time, li, ol, | ||
test = this, | ||
good = 0, | ||
bad = 0, | ||
tests = id( "qunit-tests" ); | ||
this.runtime = +new Date() - this.started; | ||
config.stats.all += this.assertions.length; | ||
config.moduleStats.all += this.assertions.length; | ||
if ( tests ) { | ||
ol = document.createElement( "ol" ); | ||
ol.className = "qunit-assert-list"; | ||
for ( i = 0; i < this.assertions.length; i++ ) { | ||
assertion = this.assertions[i]; | ||
li = document.createElement( "li" ); | ||
li.className = assertion.result ? "pass" : "fail"; | ||
li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" ); | ||
ol.appendChild( li ); | ||
if ( assertion.result ) { | ||
good++; | ||
} else { | ||
bad++; | ||
config.stats.bad++; | ||
config.moduleStats.bad++; | ||
} | ||
} | ||
// store result when possible | ||
if ( QUnit.config.reorder && defined.sessionStorage ) { | ||
if ( bad ) { | ||
sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad ); | ||
} else { | ||
sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName ); | ||
} | ||
} | ||
if ( bad === 0 ) { | ||
addClass( ol, "qunit-collapsed" ); | ||
} | ||
// `b` initialized at top of scope | ||
b = document.createElement( "strong" ); | ||
b.innerHTML = this.nameHtml + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>"; | ||
addEvent(b, "click", function() { | ||
var next = b.parentNode.lastChild, | ||
collapsed = hasClass( next, "qunit-collapsed" ); | ||
( collapsed ? removeClass : addClass )( next, "qunit-collapsed" ); | ||
}); | ||
addEvent(b, "dblclick", function( e ) { | ||
var target = e && e.target ? e.target : window.event.srcElement; | ||
if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) { | ||
target = target.parentNode; | ||
} | ||
if ( window.location && target.nodeName.toLowerCase() === "strong" ) { | ||
window.location = QUnit.url({ testNumber: test.testNumber }); | ||
} | ||
}); | ||
// `time` initialized at top of scope | ||
time = document.createElement( "span" ); | ||
time.className = "runtime"; | ||
time.innerHTML = this.runtime + " ms"; | ||
// `li` initialized at top of scope | ||
li = id( this.id ); | ||
li.className = bad ? "fail" : "pass"; | ||
li.removeChild( li.firstChild ); | ||
a = li.firstChild; | ||
li.appendChild( b ); | ||
li.appendChild( a ); | ||
li.appendChild( time ); | ||
li.appendChild( ol ); | ||
} else { | ||
for ( i = 0; i < this.assertions.length; i++ ) { | ||
if ( !this.assertions[i].result ) { | ||
bad++; | ||
config.stats.bad++; | ||
config.moduleStats.bad++; | ||
} | ||
} | ||
} | ||
runLoggingCallbacks( "testDone", QUnit, { | ||
name: this.testName, | ||
module: this.module, | ||
failed: bad, | ||
passed: this.assertions.length - bad, | ||
total: this.assertions.length, | ||
duration: this.runtime | ||
}); | ||
QUnit.reset(); | ||
config.current = undefined; | ||
}, | ||
queue: function() { | ||
var bad, | ||
test = this; | ||
synchronize(function() { | ||
test.init(); | ||
}); | ||
function run() { | ||
// each of these can by async | ||
synchronize(function() { | ||
test.setup(); | ||
}); | ||
synchronize(function() { | ||
test.run(); | ||
}); | ||
synchronize(function() { | ||
test.teardown(); | ||
}); | ||
synchronize(function() { | ||
test.finish(); | ||
}); | ||
} | ||
// `bad` initialized at top of scope | ||
// defer when previous test run passed, if storage is available | ||
bad = QUnit.config.reorder && defined.sessionStorage && | ||
+sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName ); | ||
if ( bad ) { | ||
run(); | ||
} else { | ||
synchronize( run, true ); | ||
} | ||
} | ||
}; | ||
// Root QUnit object. | ||
@@ -504,188 +211,4 @@ // `QUnit` initialized at top of scope | ||
// `assert` initialized at top of scope | ||
// Assert helpers | ||
// All of these must either call QUnit.push() or manually do: | ||
// - runLoggingCallbacks( "log", .. ); | ||
// - config.current.assertions.push({ .. }); | ||
// We attach it to the QUnit object *after* we expose the public API, | ||
// otherwise `assert` will become a global variable in browsers (#341). | ||
assert = { | ||
/** | ||
* Asserts rough true-ish result. | ||
* @name ok | ||
* @function | ||
* @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); | ||
*/ | ||
ok: function( result, msg ) { | ||
if ( !config.current ) { | ||
throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) ); | ||
} | ||
result = !!result; | ||
msg = msg || (result ? "okay" : "failed" ); | ||
var source, | ||
details = { | ||
module: config.current.module, | ||
name: config.current.testName, | ||
result: result, | ||
message: msg | ||
}; | ||
msg = "<span class='test-message'>" + escapeText( msg ) + "</span>"; | ||
if ( !result ) { | ||
source = sourceFromStacktrace( 2 ); | ||
if ( source ) { | ||
details.source = source; | ||
msg += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr></table>"; | ||
} | ||
} | ||
runLoggingCallbacks( "log", QUnit, details ); | ||
config.current.assertions.push({ | ||
result: result, | ||
message: msg | ||
}); | ||
}, | ||
/** | ||
* Assert that the first two arguments are equal, with an optional message. | ||
* Prints out both actual and expected values. | ||
* @name equal | ||
* @function | ||
* @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" ); | ||
*/ | ||
equal: function( actual, expected, message ) { | ||
/*jshint eqeqeq:false */ | ||
QUnit.push( expected == actual, actual, expected, message ); | ||
}, | ||
/** | ||
* @name notEqual | ||
* @function | ||
*/ | ||
notEqual: function( actual, expected, message ) { | ||
/*jshint eqeqeq:false */ | ||
QUnit.push( expected != actual, actual, expected, message ); | ||
}, | ||
/** | ||
* @name propEqual | ||
* @function | ||
*/ | ||
propEqual: function( actual, expected, message ) { | ||
actual = objectValues(actual); | ||
expected = objectValues(expected); | ||
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
/** | ||
* @name notPropEqual | ||
* @function | ||
*/ | ||
notPropEqual: function( actual, expected, message ) { | ||
actual = objectValues(actual); | ||
expected = objectValues(expected); | ||
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
/** | ||
* @name deepEqual | ||
* @function | ||
*/ | ||
deepEqual: function( actual, expected, message ) { | ||
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
/** | ||
* @name notDeepEqual | ||
* @function | ||
*/ | ||
notDeepEqual: function( actual, expected, message ) { | ||
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
/** | ||
* @name strictEqual | ||
* @function | ||
*/ | ||
strictEqual: function( actual, expected, message ) { | ||
QUnit.push( expected === actual, actual, expected, message ); | ||
}, | ||
/** | ||
* @name notStrictEqual | ||
* @function | ||
*/ | ||
notStrictEqual: function( actual, expected, message ) { | ||
QUnit.push( expected !== actual, actual, expected, message ); | ||
}, | ||
"throws": function( block, expected, message ) { | ||
var actual, | ||
expectedOutput = expected, | ||
ok = false; | ||
// 'expected' is optional | ||
if ( typeof expected === "string" ) { | ||
message = expected; | ||
expected = null; | ||
} | ||
config.current.ignoreGlobalErrors = true; | ||
try { | ||
block.call( config.current.testEnvironment ); | ||
} catch (e) { | ||
actual = e; | ||
} | ||
config.current.ignoreGlobalErrors = false; | ||
if ( actual ) { | ||
// we don't want to validate thrown error | ||
if ( !expected ) { | ||
ok = true; | ||
expectedOutput = null; | ||
// expected is a regexp | ||
} else if ( QUnit.objectType( expected ) === "regexp" ) { | ||
ok = expected.test( errorString( actual ) ); | ||
// expected is a constructor | ||
} else if ( actual instanceof expected ) { | ||
ok = true; | ||
// expected is a validation function which returns true is validation passed | ||
} else if ( expected.call( {}, actual ) === true ) { | ||
expectedOutput = null; | ||
ok = true; | ||
} | ||
QUnit.push( ok, actual, expectedOutput, message ); | ||
} else { | ||
QUnit.pushFailure( message, null, "No exception was thrown." ); | ||
} | ||
} | ||
}; | ||
/** | ||
* @deprecated since 1.8.0 | ||
* Kept assertion helpers in root for backwards compatibility. | ||
*/ | ||
extend( QUnit, assert ); | ||
/** | ||
* @deprecated since 1.9.0 | ||
* Kept root "raises()" for backwards compatibility. | ||
* (Note that we don't introduce assert.raises). | ||
*/ | ||
QUnit.raises = assert[ "throws" ]; | ||
/** | ||
* @deprecated since 1.0.0, replaced with error pushes since 1.3.0 | ||
* Kept to avoid TypeErrors for undefined methods. | ||
*/ | ||
QUnit.equals = function() { | ||
QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" ); | ||
}; | ||
QUnit.same = function() { | ||
QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" ); | ||
}; | ||
// We want access to the constructor's prototype | ||
// We use the prototype to distinguish between properties that should | ||
// be exposed as globals (and in exports) and those that shouldn't | ||
(function() { | ||
@@ -722,2 +245,5 @@ function F() {} | ||
// by default, scroll to top of the page when suite is done | ||
scrolltop: true, | ||
// when enabled, all tests must call expect() | ||
@@ -754,19 +280,9 @@ requireExpects: false, | ||
// Export global variables, unless an 'exports' object exists, | ||
// in that case we assume we're in CommonJS (dealt with on the bottom of the script) | ||
if ( typeof exports === "undefined" ) { | ||
extend( window, QUnit.constructor.prototype ); | ||
// Expose QUnit object | ||
window.QUnit = QUnit; | ||
} | ||
// Initialize more QUnit.config and QUnit.urlParams | ||
(function() { | ||
var i, | ||
var i, current, | ||
location = window.location || { search: "", protocol: "file:" }, | ||
params = location.search.slice( 1 ).split( "&" ), | ||
length = params.length, | ||
urlParams = {}, | ||
current; | ||
urlParams = {}; | ||
@@ -777,5 +293,10 @@ if ( params[ 0 ] ) { | ||
current[ 0 ] = decodeURIComponent( current[ 0 ] ); | ||
// allow just a key to turn on a flag, e.g., test.html?noglobals | ||
current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true; | ||
urlParams[ current[ 0 ] ] = current[ 1 ]; | ||
if ( urlParams[ current[ 0 ] ] ) { | ||
urlParams[ current[ 0 ] ] = [].concat( urlParams[ current[ 0 ] ], current[ 1 ] ); | ||
} else { | ||
urlParams[ current[ 0 ] ] = current[ 1 ]; | ||
} | ||
} | ||
@@ -792,4 +313,13 @@ } | ||
config.testNumber = parseInt( urlParams.testNumber, 10 ) || null; | ||
config.testNumber = []; | ||
if ( urlParams.testNumber ) { | ||
// Ensure that urlParams.testNumber is an array | ||
urlParams.testNumber = [].concat( urlParams.testNumber ); | ||
for ( i = 0; i < urlParams.testNumber.length; i++ ) { | ||
current = urlParams.testNumber[ i ]; | ||
config.testNumber.push( parseInt( current, 10 ) ); | ||
} | ||
} | ||
// Figure out if we're running the tests from a server or not | ||
@@ -799,6 +329,3 @@ QUnit.isLocal = location.protocol === "file:"; | ||
// Extend QUnit object, | ||
// these after set here because they should not be exposed as global functions | ||
extend( QUnit, { | ||
assert: assert, | ||
@@ -872,16 +399,2 @@ config: config, | ||
// Trigger an event on an element. | ||
// @example triggerEvent( document.body, "click" ); | ||
triggerEvent: function( elem, type, event ) { | ||
if ( document.createEvent ) { | ||
event = document.createEvent( "MouseEvents" ); | ||
event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, | ||
0, 0, 0, 0, 0, false, false, false, false, 0, null); | ||
elem.dispatchEvent( event ); | ||
} else if ( elem.fireEvent ) { | ||
elem.fireEvent( "on" + type ); | ||
} | ||
}, | ||
// Safe object type checking | ||
@@ -894,7 +407,8 @@ is: function( type, obj ) { | ||
if ( typeof obj === "undefined" ) { | ||
return "undefined"; | ||
// consider: typeof null === object | ||
return "undefined"; | ||
} | ||
// Consider: typeof null === object | ||
if ( obj === null ) { | ||
return "null"; | ||
return "null"; | ||
} | ||
@@ -1056,3 +570,3 @@ | ||
// testDone: { name, failed, passed, total, duration } | ||
// testDone: { name, failed, passed, total, runtime } | ||
testDone: registerLoggingCallback( "testDone" ), | ||
@@ -1067,3 +581,3 @@ | ||
if ( typeof document === "undefined" || document.readyState === "complete" ) { | ||
if ( !defined.document || document.readyState === "complete" ) { | ||
config.autorun = true; | ||
@@ -1076,4 +590,4 @@ } | ||
// Initialize the config, saving the execution queue | ||
var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, | ||
urlConfigCheckboxesContainer, urlConfigCheckboxes, moduleFilter, | ||
var banner, filter, i, j, label, len, main, ol, toolbar, val, selection, | ||
urlConfigContainer, moduleFilter, userAgent, | ||
numModules = 0, | ||
@@ -1097,13 +611,51 @@ moduleNames = [], | ||
id: val, | ||
label: val, | ||
tooltip: "[no tooltip available]" | ||
label: val | ||
}; | ||
} | ||
config[ val.id ] = QUnit.urlParams[ val.id ]; | ||
urlConfigHtml += "<input id='qunit-urlconfig-" + escapeText( val.id ) + | ||
"' name='" + escapeText( val.id ) + | ||
"' type='checkbox'" + ( config[ val.id ] ? " checked='checked'" : "" ) + | ||
" title='" + escapeText( val.tooltip ) + | ||
"'><label for='qunit-urlconfig-" + escapeText( val.id ) + | ||
"' title='" + escapeText( val.tooltip ) + "'>" + val.label + "</label>"; | ||
if ( !val.value || typeof val.value === "string" ) { | ||
urlConfigHtml += "<input id='qunit-urlconfig-" + escapeText( val.id ) + | ||
"' name='" + escapeText( val.id ) + | ||
"' type='checkbox'" + | ||
( val.value ? " value='" + escapeText( val.value ) + "'" : "" ) + | ||
( config[ val.id ] ? " checked='checked'" : "" ) + | ||
" title='" + escapeText( val.tooltip ) + | ||
"'><label for='qunit-urlconfig-" + escapeText( val.id ) + | ||
"' title='" + escapeText( val.tooltip ) + "'>" + val.label + "</label>"; | ||
} else { | ||
urlConfigHtml += "<label for='qunit-urlconfig-" + escapeText( val.id ) + | ||
"' title='" + escapeText( val.tooltip ) + | ||
"'>" + val.label + | ||
": </label><select id='qunit-urlconfig-" + escapeText( val.id ) + | ||
"' name='" + escapeText( val.id ) + | ||
"' title='" + escapeText( val.tooltip ) + | ||
"'><option></option>"; | ||
selection = false; | ||
if ( QUnit.is( "array", val.value ) ) { | ||
for ( j = 0; j < val.value.length; j++ ) { | ||
urlConfigHtml += "<option value='" + escapeText( val.value[j] ) + "'" + | ||
( config[ val.id ] === val.value[j] ? | ||
(selection = true) && " selected='selected'" : | ||
"" ) + | ||
">" + escapeText( val.value[j] ) + "</option>"; | ||
} | ||
} else { | ||
for ( j in val.value ) { | ||
if ( hasOwn.call( val.value, j ) ) { | ||
urlConfigHtml += "<option value='" + escapeText( j ) + "'" + | ||
( config[ val.id ] === j ? | ||
(selection = true) && " selected='selected'" : | ||
"" ) + | ||
">" + escapeText( val.value[j] ) + "</option>"; | ||
} | ||
} | ||
} | ||
if ( config[ val.id ] && !selection ) { | ||
urlConfigHtml += "<option value='" + escapeText( config[ val.id ] ) + | ||
"' selected='selected' disabled='disabled'>" + | ||
escapeText( config[ val.id ] ) + | ||
"</option>"; | ||
} | ||
urlConfigHtml += "</select>"; | ||
} | ||
} | ||
@@ -1153,3 +705,3 @@ for ( i in config.modules ) { | ||
var tmp, | ||
ol = document.getElementById( "qunit-tests" ); | ||
ol = id( "qunit-tests" ); | ||
@@ -1174,3 +726,3 @@ if ( filter.checked ) { | ||
// `ol` initialized at top of scope | ||
ol = document.getElementById( "qunit-tests" ); | ||
ol = id( "qunit-tests" ); | ||
ol.className = ol.className + " hidepass"; | ||
@@ -1187,16 +739,23 @@ } | ||
urlConfigCheckboxesContainer = document.createElement("span"); | ||
urlConfigCheckboxesContainer.innerHTML = urlConfigHtml; | ||
urlConfigCheckboxes = urlConfigCheckboxesContainer.getElementsByTagName("input"); | ||
urlConfigContainer = document.createElement("span"); | ||
urlConfigContainer.innerHTML = urlConfigHtml; | ||
// For oldIE support: | ||
// * Add handlers to the individual elements instead of the container | ||
// * Use "click" instead of "change" | ||
// * Use "click" instead of "change" for checkboxes | ||
// * Fallback from event.target to event.srcElement | ||
addEvents( urlConfigCheckboxes, "click", function( event ) { | ||
addEvents( urlConfigContainer.getElementsByTagName("input"), "click", function( event ) { | ||
var params = {}, | ||
target = event.target || event.srcElement; | ||
params[ target.name ] = target.checked ? true : undefined; | ||
params[ target.name ] = target.checked ? | ||
target.defaultValue || true : | ||
undefined; | ||
window.location = QUnit.url( params ); | ||
}); | ||
toolbar.appendChild( urlConfigCheckboxesContainer ); | ||
addEvents( urlConfigContainer.getElementsByTagName("select"), "change", function( event ) { | ||
var params = {}, | ||
target = event.target || event.srcElement; | ||
params[ target.name ] = target.options[ target.selectedIndex ].value || undefined; | ||
window.location = QUnit.url( params ); | ||
}); | ||
toolbar.appendChild( urlConfigContainer ); | ||
@@ -1233,3 +792,5 @@ if (numModules > 1) { | ||
addEvent( window, "load", QUnit.load ); | ||
if ( defined.document ) { | ||
addEvent( window, "load", QUnit.load ); | ||
} | ||
@@ -1272,5 +833,5 @@ // `onErrorFnPrev` initialized at top of scope | ||
// Log the last module results | ||
if ( config.currentModule ) { | ||
if ( config.previousModule ) { | ||
runLoggingCallbacks( "moduleDone", QUnit, { | ||
name: config.currentModule, | ||
name: config.previousModule, | ||
failed: config.moduleStats.bad, | ||
@@ -1309,3 +870,3 @@ passed: config.moduleStats.all - config.moduleStats.bad, | ||
if ( config.altertitle && typeof document !== "undefined" && document.title ) { | ||
if ( config.altertitle && defined.document && document.title ) { | ||
// show ✖ for good, ✔ for bad suite result in title | ||
@@ -1331,3 +892,3 @@ // use escape sequences in case file gets loaded with non-utf-8-charset | ||
// scroll back to top to show results | ||
if ( window.scrollTo ) { | ||
if ( config.scrolltop && window.scrollTo ) { | ||
window.scrollTo(0, 0); | ||
@@ -1349,3 +910,3 @@ } | ||
module = config.module && config.module.toLowerCase(), | ||
fullName = (test.module + ": " + test.testName).toLowerCase(); | ||
fullName = ( test.module + ": " + test.testName ).toLowerCase(); | ||
@@ -1358,4 +919,6 @@ // Internally-generated tests are always valid | ||
if ( config.testNumber ) { | ||
return test.testNumber === config.testNumber; | ||
if ( config.testNumber.length > 0 ) { | ||
if ( inArray( test.testNumber, config.testNumber ) < 0 ) { | ||
return false; | ||
} | ||
} | ||
@@ -1562,8 +1125,14 @@ | ||
function addEvent( elem, type, fn ) { | ||
// Standards-based browsers | ||
if ( elem.addEventListener ) { | ||
// Standards-based browsers | ||
elem.addEventListener( type, fn, false ); | ||
// IE | ||
} else if ( elem.attachEvent ) { | ||
// support: IE <9 | ||
elem.attachEvent( "on" + type, fn ); | ||
} else { | ||
elem.attachEvent( "on" + type, fn ); | ||
// Caller must ensure support for event listeners is present | ||
throw new Error( "addEvent() was called in a context without event listener support" ); | ||
} | ||
@@ -1605,4 +1174,3 @@ } | ||
function id( name ) { | ||
return !!( typeof document !== "undefined" && document && document.getElementById ) && | ||
document.getElementById( name ); | ||
return defined.document && document.getElementById && document.getElementById( name ); | ||
} | ||
@@ -1629,2 +1197,516 @@ | ||
// from jquery.js | ||
function inArray( elem, array ) { | ||
if ( array.indexOf ) { | ||
return array.indexOf( elem ); | ||
} | ||
for ( var i = 0, length = array.length; i < length; i++ ) { | ||
if ( array[ i ] === elem ) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
function Test( settings ) { | ||
extend( this, settings ); | ||
this.assertions = []; | ||
this.testNumber = ++Test.count; | ||
} | ||
Test.count = 0; | ||
Test.prototype = { | ||
init: function() { | ||
var a, b, li, | ||
tests = id( "qunit-tests" ); | ||
if ( tests ) { | ||
b = document.createElement( "strong" ); | ||
b.innerHTML = this.nameHtml; | ||
// `a` initialized at top of scope | ||
a = document.createElement( "a" ); | ||
a.innerHTML = "Rerun"; | ||
a.href = QUnit.url({ testNumber: this.testNumber }); | ||
li = document.createElement( "li" ); | ||
li.appendChild( b ); | ||
li.appendChild( a ); | ||
li.className = "running"; | ||
li.id = this.id = "qunit-test-output" + testId++; | ||
tests.appendChild( li ); | ||
} | ||
}, | ||
setup: function() { | ||
if ( | ||
// Emit moduleStart when we're switching from one module to another | ||
this.module !== config.previousModule || | ||
// They could be equal (both undefined) but if the previousModule property doesn't | ||
// yet exist it means this is the first test in a suite that isn't wrapped in a | ||
// module, in which case we'll just emit a moduleStart event for 'undefined'. | ||
// Without this, reporters can get testStart before moduleStart which is a problem. | ||
!hasOwn.call( config, "previousModule" ) | ||
) { | ||
if ( hasOwn.call( config, "previousModule" ) ) { | ||
runLoggingCallbacks( "moduleDone", QUnit, { | ||
name: config.previousModule, | ||
failed: config.moduleStats.bad, | ||
passed: config.moduleStats.all - config.moduleStats.bad, | ||
total: config.moduleStats.all | ||
}); | ||
} | ||
config.previousModule = this.module; | ||
config.moduleStats = { all: 0, bad: 0 }; | ||
runLoggingCallbacks( "moduleStart", QUnit, { | ||
name: this.module | ||
}); | ||
} | ||
config.current = this; | ||
this.testEnvironment = extend({ | ||
setup: function() {}, | ||
teardown: function() {} | ||
}, this.moduleTestEnvironment ); | ||
this.started = +new Date(); | ||
runLoggingCallbacks( "testStart", QUnit, { | ||
name: this.testName, | ||
module: this.module | ||
}); | ||
/*jshint camelcase:false */ | ||
/** | ||
* Expose the current test environment. | ||
* | ||
* @deprecated since 1.12.0: Use QUnit.config.current.testEnvironment instead. | ||
*/ | ||
QUnit.current_testEnvironment = this.testEnvironment; | ||
/*jshint camelcase:true */ | ||
if ( !config.pollution ) { | ||
saveGlobal(); | ||
} | ||
if ( config.notrycatch ) { | ||
this.testEnvironment.setup.call( this.testEnvironment, QUnit.assert ); | ||
return; | ||
} | ||
try { | ||
this.testEnvironment.setup.call( this.testEnvironment, QUnit.assert ); | ||
} catch( e ) { | ||
QUnit.pushFailure( "Setup failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) ); | ||
} | ||
}, | ||
run: function() { | ||
config.current = this; | ||
var running = id( "qunit-testresult" ); | ||
if ( running ) { | ||
running.innerHTML = "Running: <br/>" + this.nameHtml; | ||
} | ||
if ( this.async ) { | ||
QUnit.stop(); | ||
} | ||
this.callbackStarted = +new Date(); | ||
if ( config.notrycatch ) { | ||
this.callback.call( this.testEnvironment, QUnit.assert ); | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
return; | ||
} | ||
try { | ||
this.callback.call( this.testEnvironment, QUnit.assert ); | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
} catch( e ) { | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + ( e.message || e ), extractStacktrace( e, 0 ) ); | ||
// else next test will carry the responsibility | ||
saveGlobal(); | ||
// Restart the tests if they're blocking | ||
if ( config.blocking ) { | ||
QUnit.start(); | ||
} | ||
} | ||
}, | ||
teardown: function() { | ||
config.current = this; | ||
if ( config.notrycatch ) { | ||
if ( typeof this.callbackRuntime === "undefined" ) { | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
} | ||
this.testEnvironment.teardown.call( this.testEnvironment, QUnit.assert ); | ||
return; | ||
} else { | ||
try { | ||
this.testEnvironment.teardown.call( this.testEnvironment, QUnit.assert ); | ||
} catch( e ) { | ||
QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) ); | ||
} | ||
} | ||
checkPollution(); | ||
}, | ||
finish: function() { | ||
config.current = this; | ||
if ( config.requireExpects && this.expected === null ) { | ||
QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack ); | ||
} else if ( this.expected !== null && this.expected !== this.assertions.length ) { | ||
QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack ); | ||
} else if ( this.expected === null && !this.assertions.length ) { | ||
QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack ); | ||
} | ||
var i, assertion, a, b, time, li, ol, | ||
test = this, | ||
good = 0, | ||
bad = 0, | ||
tests = id( "qunit-tests" ); | ||
this.runtime = +new Date() - this.started; | ||
config.stats.all += this.assertions.length; | ||
config.moduleStats.all += this.assertions.length; | ||
if ( tests ) { | ||
ol = document.createElement( "ol" ); | ||
ol.className = "qunit-assert-list"; | ||
for ( i = 0; i < this.assertions.length; i++ ) { | ||
assertion = this.assertions[i]; | ||
li = document.createElement( "li" ); | ||
li.className = assertion.result ? "pass" : "fail"; | ||
li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" ); | ||
ol.appendChild( li ); | ||
if ( assertion.result ) { | ||
good++; | ||
} else { | ||
bad++; | ||
config.stats.bad++; | ||
config.moduleStats.bad++; | ||
} | ||
} | ||
// store result when possible | ||
if ( QUnit.config.reorder && defined.sessionStorage ) { | ||
if ( bad ) { | ||
sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad ); | ||
} else { | ||
sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName ); | ||
} | ||
} | ||
if ( bad === 0 ) { | ||
addClass( ol, "qunit-collapsed" ); | ||
} | ||
// `b` initialized at top of scope | ||
b = document.createElement( "strong" ); | ||
b.innerHTML = this.nameHtml + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>"; | ||
addEvent(b, "click", function() { | ||
var next = b.parentNode.lastChild, | ||
collapsed = hasClass( next, "qunit-collapsed" ); | ||
( collapsed ? removeClass : addClass )( next, "qunit-collapsed" ); | ||
}); | ||
addEvent(b, "dblclick", function( e ) { | ||
var target = e && e.target ? e.target : window.event.srcElement; | ||
if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) { | ||
target = target.parentNode; | ||
} | ||
if ( window.location && target.nodeName.toLowerCase() === "strong" ) { | ||
window.location = QUnit.url({ testNumber: test.testNumber }); | ||
} | ||
}); | ||
// `time` initialized at top of scope | ||
time = document.createElement( "span" ); | ||
time.className = "runtime"; | ||
time.innerHTML = this.runtime + " ms"; | ||
// `li` initialized at top of scope | ||
li = id( this.id ); | ||
li.className = bad ? "fail" : "pass"; | ||
li.removeChild( li.firstChild ); | ||
a = li.firstChild; | ||
li.appendChild( b ); | ||
li.appendChild( a ); | ||
li.appendChild( time ); | ||
li.appendChild( ol ); | ||
} else { | ||
for ( i = 0; i < this.assertions.length; i++ ) { | ||
if ( !this.assertions[i].result ) { | ||
bad++; | ||
config.stats.bad++; | ||
config.moduleStats.bad++; | ||
} | ||
} | ||
} | ||
runLoggingCallbacks( "testDone", QUnit, { | ||
name: this.testName, | ||
module: this.module, | ||
failed: bad, | ||
passed: this.assertions.length - bad, | ||
total: this.assertions.length, | ||
runtime: this.runtime, | ||
// DEPRECATED: this property will be removed in 2.0.0, use runtime instead | ||
duration: this.runtime | ||
}); | ||
QUnit.reset(); | ||
config.current = undefined; | ||
}, | ||
queue: function() { | ||
var bad, | ||
test = this; | ||
synchronize(function() { | ||
test.init(); | ||
}); | ||
function run() { | ||
// each of these can by async | ||
synchronize(function() { | ||
test.setup(); | ||
}); | ||
synchronize(function() { | ||
test.run(); | ||
}); | ||
synchronize(function() { | ||
test.teardown(); | ||
}); | ||
synchronize(function() { | ||
test.finish(); | ||
}); | ||
} | ||
// `bad` initialized at top of scope | ||
// defer when previous test run passed, if storage is available | ||
bad = QUnit.config.reorder && defined.sessionStorage && | ||
+sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName ); | ||
if ( bad ) { | ||
run(); | ||
} else { | ||
synchronize( run, true ); | ||
} | ||
} | ||
}; | ||
// `assert` initialized at top of scope | ||
// Assert helpers | ||
// All of these must either call QUnit.push() or manually do: | ||
// - runLoggingCallbacks( "log", .. ); | ||
// - config.current.assertions.push({ .. }); | ||
assert = QUnit.assert = { | ||
/** | ||
* Asserts rough true-ish result. | ||
* @name ok | ||
* @function | ||
* @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); | ||
*/ | ||
ok: function( result, msg ) { | ||
if ( !config.current ) { | ||
throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) ); | ||
} | ||
result = !!result; | ||
msg = msg || ( result ? "okay" : "failed" ); | ||
var source, | ||
details = { | ||
module: config.current.module, | ||
name: config.current.testName, | ||
result: result, | ||
message: msg | ||
}; | ||
msg = "<span class='test-message'>" + escapeText( msg ) + "</span>"; | ||
if ( !result ) { | ||
source = sourceFromStacktrace( 2 ); | ||
if ( source ) { | ||
details.source = source; | ||
msg += "<table><tr class='test-source'><th>Source: </th><td><pre>" + | ||
escapeText( source ) + | ||
"</pre></td></tr></table>"; | ||
} | ||
} | ||
runLoggingCallbacks( "log", QUnit, details ); | ||
config.current.assertions.push({ | ||
result: result, | ||
message: msg | ||
}); | ||
}, | ||
/** | ||
* Assert that the first two arguments are equal, with an optional message. | ||
* Prints out both actual and expected values. | ||
* @name equal | ||
* @function | ||
* @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" ); | ||
*/ | ||
equal: function( actual, expected, message ) { | ||
/*jshint eqeqeq:false */ | ||
QUnit.push( expected == actual, actual, expected, message ); | ||
}, | ||
/** | ||
* @name notEqual | ||
* @function | ||
*/ | ||
notEqual: function( actual, expected, message ) { | ||
/*jshint eqeqeq:false */ | ||
QUnit.push( expected != actual, actual, expected, message ); | ||
}, | ||
/** | ||
* @name propEqual | ||
* @function | ||
*/ | ||
propEqual: function( actual, expected, message ) { | ||
actual = objectValues(actual); | ||
expected = objectValues(expected); | ||
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
/** | ||
* @name notPropEqual | ||
* @function | ||
*/ | ||
notPropEqual: function( actual, expected, message ) { | ||
actual = objectValues(actual); | ||
expected = objectValues(expected); | ||
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
/** | ||
* @name deepEqual | ||
* @function | ||
*/ | ||
deepEqual: function( actual, expected, message ) { | ||
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
/** | ||
* @name notDeepEqual | ||
* @function | ||
*/ | ||
notDeepEqual: function( actual, expected, message ) { | ||
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
/** | ||
* @name strictEqual | ||
* @function | ||
*/ | ||
strictEqual: function( actual, expected, message ) { | ||
QUnit.push( expected === actual, actual, expected, message ); | ||
}, | ||
/** | ||
* @name notStrictEqual | ||
* @function | ||
*/ | ||
notStrictEqual: function( actual, expected, message ) { | ||
QUnit.push( expected !== actual, actual, expected, message ); | ||
}, | ||
"throws": function( block, expected, message ) { | ||
var actual, | ||
expectedOutput = expected, | ||
ok = false; | ||
// 'expected' is optional | ||
if ( !message && typeof expected === "string" ) { | ||
message = expected; | ||
expected = null; | ||
} | ||
config.current.ignoreGlobalErrors = true; | ||
try { | ||
block.call( config.current.testEnvironment ); | ||
} catch (e) { | ||
actual = e; | ||
} | ||
config.current.ignoreGlobalErrors = false; | ||
if ( actual ) { | ||
// we don't want to validate thrown error | ||
if ( !expected ) { | ||
ok = true; | ||
expectedOutput = null; | ||
// expected is an Error object | ||
} else if ( expected instanceof Error ) { | ||
ok = actual instanceof Error && | ||
actual.name === expected.name && | ||
actual.message === expected.message; | ||
// expected is a regexp | ||
} else if ( QUnit.objectType( expected ) === "regexp" ) { | ||
ok = expected.test( errorString( actual ) ); | ||
// expected is a string | ||
} else if ( QUnit.objectType( expected ) === "string" ) { | ||
ok = expected === errorString( actual ); | ||
// expected is a constructor | ||
} else if ( actual instanceof expected ) { | ||
ok = true; | ||
// expected is a validation function which returns true is validation passed | ||
} else if ( expected.call( {}, actual ) === true ) { | ||
expectedOutput = null; | ||
ok = true; | ||
} | ||
QUnit.push( ok, actual, expectedOutput, message ); | ||
} else { | ||
QUnit.pushFailure( message, null, "No exception was thrown." ); | ||
} | ||
} | ||
}; | ||
/** | ||
* @deprecated since 1.8.0 | ||
* Kept assertion helpers in root for backwards compatibility. | ||
*/ | ||
extend( QUnit.constructor.prototype, assert ); | ||
/** | ||
* @deprecated since 1.9.0 | ||
* Kept to avoid TypeErrors for undefined methods. | ||
*/ | ||
QUnit.constructor.prototype.raises = function() { | ||
QUnit.push( false, false, false, "QUnit.raises has been deprecated since 2012 (fad3c1ea), use QUnit.throws instead" ); | ||
}; | ||
/** | ||
* @deprecated since 1.0.0, replaced with error pushes since 1.3.0 | ||
* Kept to avoid TypeErrors for undefined methods. | ||
*/ | ||
QUnit.constructor.prototype.equals = function() { | ||
QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" ); | ||
}; | ||
QUnit.constructor.prototype.same = function() { | ||
QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" ); | ||
}; | ||
// Test for equality any JavaScript type. | ||
@@ -2069,17 +2151,2 @@ // Author: Philippe Rathé <prathe@gmail.com> | ||
// from jquery.js | ||
function inArray( elem, array ) { | ||
if ( array.indexOf ) { | ||
return array.indexOf( elem ); | ||
} | ||
for ( var i = 0, length = array.length; i < length; i++ ) { | ||
if ( array[ i ] === elem ) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
/* | ||
@@ -2233,8 +2300,17 @@ * Javascript Diff Algorithm | ||
// for CommonJS environments, export everything | ||
if ( typeof exports !== "undefined" ) { | ||
extend( exports, QUnit.constructor.prototype ); | ||
// For browser, export only select globals | ||
if ( typeof window !== "undefined" ) { | ||
extend( window, QUnit.constructor.prototype ); | ||
window.QUnit = QUnit; | ||
} | ||
// get at whatever the global object is, like window in browsers | ||
}( (function() {return this;}.call()) )); | ||
// For CommonJS environments, export everything | ||
if ( typeof module !== "undefined" && module.exports ) { | ||
module.exports = QUnit; | ||
} | ||
// Get a reference to the global object, like window in browsers | ||
}( (function() { | ||
return this; | ||
})() )); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
184465
4399
168