pax_global_header00006660000000000000000000000064122620401360014506gustar00rootroot0000000000000052 comment=32f43e73938d4c787631a26898d41a131e3e0c90 qunit-1.13.0/000077500000000000000000000000001226204013600127305ustar00rootroot00000000000000qunit-1.13.0/.gitignore000066400000000000000000000000221226204013600147120ustar00rootroot00000000000000dist node_modules qunit-1.13.0/.jshintrc000066400000000000000000000007111226204013600145540ustar00rootroot00000000000000{ "globals": { "module": false }, "boss": true, "curly": true, "eqeqeq": true, "eqnull": true, "expr": true, "immed": true, "noarg": true, "onevar": true, "quotmark": "double", "smarttabs": true, "trailing": true, "undef": true, "unused": true, "bitwise": true, "browser": true, "camelcase": true, "forin": true, "latedef": false, "newcap": true, "noempty": true, "nonew": true, "plusplus": false, "proto": true, "sub": true } qunit-1.13.0/.mailmap000066400000000000000000000073171226204013600143610ustar00rootroot00000000000000Jörn Zaefferer Jörn Zaefferer Ariel Flesler Scott González Richard Worth Philippe Rathé John Resig Will Moffat Jan Kassens Ziling Zhao Ryan Szulczewski Chris Lloyd Louis-Rémi Babé Louis-Rémi Babé Louis-Rémi Babé Jake Archibald Jake Archibald Frances Berriman Rune Halvorsen Rune Halvorsen Chris Thatcher Chris Thatcher Fábio Rehm Leon Sorokin Douglas Neiner Paul Elliott Nikita Vasilyev Benjamin Lee Paul Irish Oleg Slobodskoi Anton Matzneller Aurélien Bombo Mathias Bynens Erik Vold Wesley Walser Wesley Walser Rob Kinninmont Marc Portier Michael Righi Timo Tijhof Jan Alonzo Daniel Trebbien Bob Fanger Markus Messner-Chaney Trevor Parscal Ashar Voultoiz Jimmy Mabey Domenic Denicola Mike Sherov Seong-A Kong Graham Conzett Niall Smart Johan Sörlin Gijs Kruitbosch Erkan Yilmaz Jonathan Sanchez Keith Cirkel Rick Waldron Herbert Vojčík Richard Gibson Alex J Burke Sergii Kliuchnyk Sergii Kliuchnyk Corey Frang John Reeves John Reeves Vivin Paliath Joshua Niehus Glen Huang Glen Huang Jonas Ulrich Jamie Hoover Jamie Hoover James M. Greene Rodney Rehm Peter Wagenet Clog Clog Antranig Basman Antranig Basman Matthew Mirande Jared Wyles Dmitry Gusev Ian Wallis Ian Wallis Dan Andreescu Dan Andreescu Matthew DuVall Matthew DuVall Dave K. Smith David Vollbracht qunit-1.13.0/.travis.yml000066400000000000000000000001231226204013600150350ustar00rootroot00000000000000language: node_js node_js: - "0.10" before_install: - npm install -g grunt-cli qunit-1.13.0/AUTHORS.txt000066400000000000000000000056061226204013600146250ustar00rootroot00000000000000Jörn Zaefferer Ariel Flesler Scott González Richard Worth Philippe Rathé John Resig Will Moffat Jan Kassens Ziling Zhao Ryan Szulczewski Chris Lloyd Louis-Rémi Babé Jake Archibald Frances Berriman Rune Halvorsen Chris Thatcher Fábio Rehm Leon Sorokin Douglas Neiner Paul Elliott Nikita Vasilyev Benjamin Lee Paul Irish Oleg Slobodskoi Anton Matzneller Aurélien Bombo Mathias Bynens Erik Vold Wesley Walser Rob Kinninmont Marc Portier Michael Righi Timo Tijhof Jan Alonzo Daniel Trebbien Bob Fanger Markus Messner-Chaney Trevor Parscal Ashar Voultoiz Jimmy Mabey Domenic Denicola Mike Sherov Seong-A Kong Graham Conzett Niall Smart Johan Sörlin Gijs Kruitbosch Erkan Yilmaz Jonathan Sanchez Keith Cirkel Rick Waldron Herbert Vojčík Richard Gibson Alex J Burke Sergii Kliuchnyk Corey Frang John Reeves Antranig Basman Vivin Paliath Joshua Niehus Glen Huang Jonas Ulrich Jamie Hoover James M. Greene Rodney Rehm Peter Wagenet Clog Matthew Mirande Jared Wyles Dmitry Gusev Ian Wallis Dan Andreescu Matthew DuVall Dave K. Smith David Vollbracht Katie Gengler Joshua Peek Leonardo Balter Jeff Cooper qunit-1.13.0/CONTRIBUTING.md000066400000000000000000000020261226204013600151610ustar00rootroot00000000000000Welcome! Thanks for your interest in contributing to QUnit. You're **almost** in the right place. More information on how to contribute to this and all other jQuery Foundation projects is over at [contribute.jquery.org](http://contribute.jquery.org). You'll definitely want to take a look at the articles on contributing [code](http://contribute.jquery.org/code). You may also want to take a look at our [commit & pull request guide](http://contribute.jquery.org/commits-and-pull-requests/) and [style guides](http://contribute.jquery.org/style-guide/) for instructions on how to maintain your fork and submit your code. Before we can merge any pull request, we'll also need you to sign our [contributor license agreement](http://contribute.jquery.org/cla). You can find us on [IRC](http://irc.jquery.org), specifically in #jquery-dev should you have any questions. If you've never contributed to open source before, we've put together [a short guide with tips, tricks, and ideas on getting started](http://contribute.jquery.org/open-source/). qunit-1.13.0/Gruntfile.js000066400000000000000000000075301226204013600152320ustar00rootroot00000000000000/*jshint node:true */ module.exports = function( grunt ) { grunt.loadNpmTasks( "grunt-git-authors" ); grunt.loadNpmTasks( "grunt-contrib-concat" ); grunt.loadNpmTasks( "grunt-contrib-jshint" ); grunt.loadNpmTasks( "grunt-contrib-qunit" ); grunt.loadNpmTasks( "grunt-contrib-watch" ); function process( code ) { return code // Embed version .replace( /@VERSION/g, grunt.config( "pkg" ).version ) // Embed date (yyyy-mm-ddThh:mmZ) .replace( /@DATE/g, ( new Date() ).toISOString().replace( /:\d+\.\d+Z$/, "Z" ) ); } grunt.initConfig({ pkg: grunt.file.readJSON( "package.json" ), concat: { "src-js": { options: { process: process }, src: [ "src/intro.js", "src/core.js", "src/test.js", "src/assert.js", "src/equiv.js", "src/dump.js", "src/diff.js", "src/export.js", "src/outro.js" ], dest: "dist/qunit.js" }, "src-css": { options: { process: process }, src: [ "src/qunit.css" ], dest: "dist/qunit.css" } }, jshint: { options: { jshintrc: ".jshintrc" }, gruntfile: [ "Gruntfile.js" ], dist: [ "dist/*.js" ], addons: { options: { jshintrc: "addons/.jshintrc" }, files: { src: [ "addons/**/*.js" ] } }, tests: { options: { jshintrc: "test/.jshintrc" }, files: { src: [ "test/**/*.js" ] } } }, qunit: { qunit: [ "test/index.html", "test/async.html", "test/logs.html", "test/setTimeout.html" ] }, watch: { files: [ "*", ".jshintrc", "{addons,src,test}/**/{*,.*}" ], tasks: "default" } }); grunt.registerTask( "testswarm", function( commit, configFile ) { var testswarm = require( "testswarm" ), config = grunt.file.readJSON( configFile ).qunit, runs = {}, done = this.async(); ["index", "async", "setTimeout"].forEach(function (suite) { runs[suite] = config.testUrl + commit + "/test/" + suite + ".html"; }); testswarm.createClient( { url: config.swarmUrl, pollInterval: 10000, timeout: 1000 * 60 * 30 } ) .addReporter( testswarm.reporters.cli ) .auth( { id: config.authUsername, token: config.authToken } ) .addjob( { name: "Commit " + commit.substr( 0, 10 ) + "", runs: runs, browserSets: config.browserSets }, function( err, passed ) { if ( err ) { grunt.log.error( err ); } done( passed ); } ); }); // TODO: Extract this task later, if feasible // Also spawn a separate process to keep tests atomic grunt.registerTask( "test-on-node", function() { var testActive = false, runDone = false, done = this.async(), QUnit = require( "./dist/qunit" ); // Make the current tests work in the Node.js environment by appending // a bunch of properties into the `global` object [ "test", "asyncTest", "start", "stop", "expect" ].forEach(function( method ) { global[ method ] = QUnit[ method ]; }); global.QUnit = QUnit; QUnit.testStart(function() { testActive = true; }); QUnit.log(function( details ) { if ( !testActive || details.result ) { return; } var message = "name: " + details.name + " module: " + details.module + " message: " + details.message; grunt.log.error( message ); }); QUnit.testDone(function() { testActive = false; }); QUnit.done(function( details ) { if ( runDone ) { return; } var succeeded = ( details.failed === 0 ), message = details.total + " assertions in (" + details.runtime + "ms), passed: " + details.passed + ", failed: " + details.failed; if ( succeeded ) { grunt.log.ok( message ); } else { grunt.log.error( message ); } done( succeeded ); runDone = true; }); QUnit.config.autorun = false; require( "./test/logs" ); require( "./test/test" ); require( "./test/deepEqual" ); QUnit.load(); }); grunt.registerTask( "build", [ "concat" ] ); grunt.registerTask( "default", [ "build", "jshint", "qunit", "test-on-node" ] ); }; qunit-1.13.0/History.md000066400000000000000000001202001226204013600147060ustar00rootroot000000000000001.13.0 / 2014-01-04 ================== * Tests: Stop using the expected argument in test() calls * Logging: Add runtime property to testDone, deprecate duration * Assert: Remove raises (deprecated 2012), replace with failed assertion * Grunt: Add non-browser test as grunt task. Runs existing tests in node. * Export: Only export to the variable that we check for. * Core: Properly check for existence of document * Core: Remove triggerEvent, which isn't used or documented anywhere. * Core: Silence addEvent in non-browser env * The Grand QUnit Split of 2013 * Use `id` function for selection elements in two places that were not using it. Closes gh-463 * Add bower.json. Fixes #461 1.12.0 / 2013-06-21 =================== * Add a deprecation comment to QUnit.reset. Partial fix for #354 * Fix mis-match between moduleStart and moduleDone events * Removed jQuery.trim optimization. Fixes #424. * Use a local setTimeout reference, add separate unit test suite for that. Fixes #432 - Using a setTimeout stub can stop test suite from continuing. Closes gh-433 * Added CONTRIBUTING.md. * Moved 'addons/themes/nv' to 'Krinkle/qunit-theme-nv.git' * Moved 'addons/themes/ninja' to 'Krinkle/qunit-theme-ninja.git' * Moved 'addons/themes/gabe' to 'Krinkle/qunit-theme-gabe.git' * Moved 'addons/canvas' to 'JamesMGreene/qunit-assert-canvas.git'. Tree: https://github.com/JamesMGreene/qunit-assert-canvas/tree/v1.0.0 * Moved 'addons/close-enough' to 'JamesMGreene/qunit-assert-close.git'. Tree: https://github.com/JamesMGreene/qunit-assert-close/tree/v1.0.0 * Moved 'addons/step' to 'JamesMGreene/qunit-assert-step.git'. Tree: https://github.com/JamesMGreene/qunit-assert-step/tree/v1.0.0 * Canvas plugin: Show how to test with images. Closes gh-438. * Clear filter and testNumber when choosing a module. Fixes #442. * Deprecate QUnit.current_testEnvironment in favour of config.current.testEnvironment. * assert.ok: Message shouldn't be undefined in 'log' event. * Emit moduleStart before testStart even if test isn't in a module. * PhantomJS plugin: Added optional timeout. Closes #415. * PhantomJS plugin: Include stack trace for all failed tests. Closes #416. * Moved 'addons/composite' to 'jquery/qunit-composite.git'. Tree: https://github.com/jquery/qunit-composite/tree/v1.0.0 Fixes #419. * Moved 'addons/junitlogger' to 'jquery/qunit-reporter-junit.git'. * Sort the module names so we no longer rely on implicit ordering. Fixes #391. Closes gh-392 * JUnitLogger: Add a `name` property to the test run. Closes gh-389 * Improve circular reference logic in equiv - Fixes #397 1.11.0 / 2013-01-20 ================== * Diff: Fix exception on property "constructor". Fixes #394. * Composite Add-on: Test suites can be named by including an obj with name & path props within array param for .testSuites() * Fix URL generator to take protocol and host into account to fix usage with file protocol in IE7/8 * Fix issue with Error.prototype.toString in IE 7 * Refactor jsDump for "node". Fixes #381. * Show contents of text nodes in jsDump.node. Fixes #380. * Escape text. Fixes #379. * Rewrote most of the JUnitLogger addon as it was in bad shape: unused variables, duplicate effort that QUnit handles internally (e.g. tallying number of total assertions, failed assertions, etc.), sub-optimal XmlWriter implementation, etc. * Phantomjs: Include source in assertion details * Phantomjs: Removed the polling mechanism in favor of PhantomJS 1.6+'s `WebPage#onCallback` * Delay start() until init() happened. Fixes #358. Closes #373. * urlConfig: Fix checkbox event for oldIE. Fixes #369. Closes #370. * Issue #365: Fix module picker for oldIE. Closes #366. * Fixes #344 - Capture and show test duration. * Rename tests to assertions in summary. Fixes #336 - Summary counts assertions but mentions 'tests'. * Assert: Implement propEqual and notPropEqual. Fixes #317. * Canvas addon: Use 0.6 as alpha value to avoid inconsistencies between browsers. Fixes #342 * Remove global variable "assert". Fixes #341. * Add a test for loading tests asynchronously * Improve start()-called-too-often fix, initialize semaphore at 1, fixes autostart=false case. Also provide stack for the offending start() call * There's type-free objects in Firefox, extend objectType() to allow null match. Fixes #315 * Push a failing assertion when calling start() while already running. Resets anyway to keep other tests going. Fixes #314 * Adds Ninja Theme * Extend jsdump to output Error objects as such, including the message property. Extend throws to provide 'expected' value when possible. Fixes #307 * Use classes to collapse assertion groups. Fixes #269 * Readme for junitlogger addon * Better readme for composite addon * Make `throws` ES3 compatible * Composite: Adds test whether iframe contains content. Fixes #318 - Composite: Raises "global failure" in Opera * Apply the same exception handling for test and teardown try/catch as for setup 1.10.0 / 2012-08-30 ================== * Simplify licensing: Only MIT, no more MIT/GPL dual licensing. * Scroll the window back to top after tests finished running. Fixes #304 * Simplify phantomjs runner to use module property in testDone callback * Adds module and test name to the information that is returned in the callback provided to QUnit.log(Function). Fixes #296 * Make QUnit.expect() (without arguments) a getter. Fixes #226 * Compare the ES6 sticky (y) property for RegExp. Can't add to tests yet. Fixes #284 - deepEqual for RegExp should compare * onerror: force display of global errors despite URL parameters. Fixes #288 - Global failures can be filtered out by test-limiting URL parameters * Remove conditional codepath based on jQuery presence from reset(). * Add module filter to UI * Keep a local reference to Date. Fixes #283. * Update copyright to jQuery Foundation. 1.9.0 / 2012-07-11 ================== * added jsdoc for QUnit.assert functions * Styling: radius to 5px and small pass/error border, remove inner shadow * Move checkboxes into toolbar and give them labels and descriptions (as tooltip). Fixes #274 - Improve urlFilter API and UI * Where we receive no exception in throws() use a relevant message. * Also make module filter case-insensitive. Follow-up to #252 * Banner: Link should ignore "testNumber" and "module". Fixes #270 * Rename assert.raises to assert.throws. Fixes #267 * Change package.json name property to 'qunitjs' to avoid conflict with node-qunit; will publish next release to npm 1.8.0 / 2012-06-14 ================== * Improve window.onerror handling * (issue #260) config.current should be reset at the right time. * Filter: Implement 'module' url parameter. Fixes #252 * raises: ignore global exceptions stemming from test. Fixes #257 - Globally-executed errors sneak past raises in IE 1.7.0 / 2012-06-07 ================== * Add config.requireExpects. Fixes #207 - Add option to require all tests to call expect(). * Improve extractStacktrace() implementation. Fixes #254 - Include all relevant stack lines * Make filters case-insensitive. Partial fix for #252 * is() expects lowercase types. Fixes #250 - Expected Date value is not displayed properly * Fix phantomjs addon header and add readme. Fixes #239 * Add some hints to composite addon readme. Fixes #251 * Track tests by the order in which they were run and create rerun links based on that number. Fixes #241 - Make Rerun link run only a single test. * Use QUnit.push for raises implementation. Fixes #243 * CLI runner for phantomjs * Fix jshint validation until they deal with /** */ comments properly * Update validTest() : Simplify logic, clarify vars and add comments * Refactor assertion helpers into QUnit.assert (backwards compatible) * Add Rerun link to placeholders. Fixes #240 1.6.0 / 2012-05-04 ================== * Save stack for each test, use that for failed expect() results, points at the line where test() was called. Fixes #209 * Prefix test-output id and ignore that in noglobals check. Fixes #212 * Only check for an exports object to detect a CommonJS environment. Fixes #237 - Incompatibility with require.js * Add testswarm integration as grunt task * Added padding on URL config checkboxes. * Cleanup composite addon: Use callback registration instead of overwriting them. Set the correct src on rerun link (and dblclick). Remove the composite test itself, as that was a crazy hack not worth maintaining * Cleanup reset() test and usage - run testDone callback first, to allow listeneres ignoring reset assertions * Double clicking on composite test rows opens individual test page * test-message for all message-bearing API reporting details 1.5.0 / 2012-04-04 ================== * Modify "Running..." to display test name. Fixes #220 * Fixed clearing of sessionStorage in Firefox 3.6. * Fixes #217 by calling "block" with config.current.testEnvironment * Add stats results to data. QUnit.jUnitReport function take one argument { xml:' QUnit.start() * Remove the 'let teardown clean up globals test' - IE<9 doesn't support (==buggy) deleting window properties, and that's not worth the trouble, as everything else passes just fine. Fixes #155 * Fix globals in test.js, part 2 * Fix globals in test.js. ?tell wwalser to use ?noglobals everyonce in a while * Extend readme regarding release process 1.1.0 / 2011-10-11 ================== * Fixes #134 - Add a window.onerror handler. Makes uncaught errors actually fail the testsuite, instead of going by unnoticed. * Whitespace cleanup * Merge remote branch 'trevorparscal/master' * Fixed IE compatibility issues with using toString on NodeList objects, which in some browsers results in [object Object] rather than [object NodeList]. Now using duck typing for NodeList objects based on the presence of length, length being a number, presence of item method (which will be typeof string in IE and function in others, so we just check that it's not undefined) and that item(0) returns the same value as [0], unless it's empty, in which case item(0) will return 0, while [0] would return undefined. Tested in IE6, IE8, Firefox 6, Safari 5 and Chrome 16. * Update readme with basic notes on releases * More whitespace/parens cleanup * Check if setTimeout is available before trying to delay running the next task. Fixes #160 * Whitespace/formatting fix, remove unnecessary parens * Use alias for Object.prototype.toString * Merge remote branch 'trevorparscal/master' * Merge remote branch 'wwalser/recursionBug' * Default 'expected' to null in asyncTest(), same as in test() itself. * Whitespace cleanup * Merge remote branch 'mmchaney/master' * Merge remote branch 'Krinkle/master' * Using === instead of == * Added more strict array type detection for dump output, and allowed NodeList objects to be output as arrays * Fixes a bug where after an async test, assertions could move between test cases because of internal state (config.current) being incorrectly set * Simplified check for assertion count and adjusted whitespace * Redo of fixing issue #156 (Support Object.prototype extending environment). * QUnit.diff: Throws exception without this if Object.prototype is set (Property 'length' of undefined. Since Object.prototype.foo doesn't have a property 'rows') * QUnit.url: Without this fix, if Object.prototype.foo is set, the url will be set to ?foo=...&the=rest. * saveGlobals: Without this fix, whenever a member is added to Object.prototype, saveGlobals will think it was a global variable in this loop. --- This time using the call method instead of obj.hasOwnProperty(key), which may fail if the object has that as it's own property (touché!). * Handle expect(0) as expected, i.e. expect(0); ok(true, foo); will cause a test to fail 1.0.0 / 2011-10-06 ================== * Make QUnit work with TestSwarm * Run other addons tests as composite addon demo. Need to move that to /test folder once this setup actually works * Add-on: New assertion-type: step() * added parameter to start and stop allowing a user to increment/decrement the semaphore more than once per call * Update readmes with .md extension for GitHub to render them as markdown * Update close-enough addon to include readme and match (new) naming conventions * Merge remote branch 'righi/close-enough-addon' * Canvas addon: Update file references * Update canvas addon: Rename files and add README * Merge remote branch 'wwalser/composite' * Fix #142 - Backslash characters in messages should not be escaped * Add module name to testStart and testDone callbacks * Removed extra columns in object literals. Closes #153 * Remove dead links in comments. * Merge remote branch 'wwalser/multipleCallbacks' * Fixed syntax error and CommonJS incompatibilities in package.json * Allow multiple callbacks to be registered. * Add placeholder for when Safari may end up providing useful error handling * changed file names to match addon naming convention * Whitespace * Created the composite addon. * Using array and object literals. * Issue #140: Make toggle system configurable. * Merge remote branch 'tweetdeck/master' * Adds the 'close enough' addon to determine if numbers are acceptably close enough in value. * Fix recursion support in jsDump, along with tests. Fixes #63 and #100 * Adding a QUnit.config.altertitle flag which will allow users to opt-out of the functionality introduced in 60147ca0164e3d810b8a9bf46981c3d9cc569efc * Refactor window.load handler into QUnit.load, makes it possible to call it manually. * More whitespace cleanup * Merge remote branch 'erikvold/one-chk-in-title' * Whitespace * Merge remote branch 'wwalser/syncStopCalls' * Introducing the first QUnit addon, based on https://github.com/jquery/qunit/pull/84 - adds QUnit.pixelEqual assertion method, along with example tests. * Remove config.hidepassed setting in test.js, wasn't intended to land in master. * Expose QUnit.config.hidepassed setting. Overrides sessionStorage and enables enabling the feature programmatically. Fixes #133 * Fix formatting (css whitespace) for tracebacks. * Expose extend, id, and addEvent methods. * minor comment typo correction * Ignore Eclipse WTP .settings * Set 'The jQuery Project' as author in package.json * Fixes a bug where synchronous calls to stop would cause tests to end before start was called again * Point to planning testing wiki in readme * only add one checkmark to the document.title * Escape the stacktrace output before setting it as innerHTML, since it tends to contain `<` and `>` characters. * Cleanup whitespace * Run module.teardown before checking for pollution. Fixes #109 - noglobals should run after module teardown * Fix accidental global variable "not" * Update document.title status to use more robust unicode escape sequences, works even when served with non-utf-8-charset. * Modify document.title when suite is done to show success/failure in tab, allows you to see the overall result without seeing the tab content. * Merge pull request #107 from sexyprout/master * Set a generic font * Add/update headers * Drop support for deprecated #main in favor of #qunit-fixture. If this breaks your testsuite, replace id="main" with id="qunit-fixture". Fixes #103 * Remove the same key as the one being set. Partial fix for #101 * Don't modify expected-count when checking pollution. The failing assertion isn't expected, so shouldn't be counted. And if expect wasn't used, the count is misleading. * Fix order of noglobals check to produce correct introduced/delete error messages * Prepend module name to sessionStorage keys to avoid conflicts * Store filter-tests only when checked * Write to sessionStorage only bad tests * Moved QUnit.url() definition after QUnit properties are merged into the global scope. Fixes #93 - QUnit url/extend function breaking urls in jQuery ajax test component * Add a "Rerun" link to each test to replace the dblclick (still supported, for now). * Fixed the regex for parsing the name of a test when double clicking to filter. * Merge remote branch 'scottgonzalez/url' * Added checkboxes to show which flags are currently on and allow toggling them. * Retain all querystring parameters when filtering a test via double click. * Added better querystring parsing. Now storing all querystring params in QUnit.urlParams so that we can carry the params forward when filtering to a specific test. This removes the ability to specify multiple filters. * Make reordering optional (QUnit.config.reorder = false) and optimize "Hide passed tests" mode by also hiding "Running [testname]" entries. * Added missing semicolons and wrapped undefined key in quotes. * Optimize test hiding, add class on page load if stored in sessionStorage * Optimize the hiding of passed tests. * Position test results above test list, making it visible without ever having to scroll. Create a placeholder to avoid pushing down results later. * Don't check for existing qunit-testresult element, it gets killed on init anyway. * Added URL flag ?notrycatch (ala ?noglobals) for debugging exceptions. Won't try/catch test code, giving better debugging changes on the original exceptions. Fixes #72 * Always show qunit-toolbar (if at all specified), persist checkbox via sessionStorage. Fixes #47 * Use non-html testname for calls to fail(). Fixes #77 * Overhaul of QUnit.callbacks. Consistent single argument with related properties, with additional runtime property for QUnit.done * Extended test/logs.html to capture more of the callbacks. * Fixed moduleStart/Done callbacks. Added test/logs.html to test these callbacks. To be extended. * Update copyright and license header. Fixes #61 * Formatting fix. * Use a semaphore to synchronize stop() and start() calls. Fixes #76 * Merge branch 'master' of https://github.com/paulirish/qunit into paulirish-master * Added two tests for previous QUnit.raises behaviour. For #69 * add optional 2. arg to QUnit.raises #69. * fix references inside Complex Instances Nesting to what was originally intended. * Qualify calls to ok() in raises() for compatibility with CLI environments. * Fix done() handling, check for blocking, not block property * Fix moduleStart/Done and done callbacks. * Replacing sessionStorage test with the one from Modernizr/master (instead of current release). Here's hoping it'll work for some time. * Updated test for availability of sessionStorage, based on test from Modernizr. Fixes #64 * Defer test execution when previous run passed, persisted via sessionStorage. Fixes #49 * Refactored module handling and queuing to enable selective defer of test runs. * Move assertions property from config to Test * Move expected-tests property from config to Test * Refactored test() method to delegate to a Test object to encapsulate all properties and methods of a single test, allowing further modifications. * Adding output of sourcefile and linenumber of failed assertions (except ok()). Only limited cross-browser support for now. Fixes #60 * Drop 'hide missing tests' feature. Fixes #48 * Adding readme. Fixes #58 * Merge branch 'prettydiff' * Improve jsDump output with formatted diffs. * Cleanup whitespace * Cleanup whitespace * Added additional guards around browser specific code and cleaned up jsDump code * Added guards around tests which are only for browsers * cleaned up setTimeout undefined checking and double done on test finish * fixing .gitignore * making window setTimeout query more consistent * Moved expect-code back to beginning of function, where it belongs. Fixes #52 * Bread crumb in header: Link to suite without filters, add link to current page based on the filter, if present. Fixes #50 * Make the toolbar element optional when checking for show/hide of test results. Fixes #46 * Adding headless.html to manually test logging and verify that QUnit works without output elements. Keeping #qunit-fixture as a few tests actually use that. * Fix for QUnit.moduleDone, get rid of initial bogus log. Fixes #33 * Pass raw data (result, message, actual, expected) as third argument to QUnit.log. Fixes #32 * Dump full exception. Not pretty, but functional (see issue Pretty diff for pretty output). Fixes #31 * Don't let QUnit.reset() cause assertions to run. Manually applied from Scott Gonzalez branch. Fixes #34 * Added missing semicolons. Fixes #37 * Show okay/failed instead of undefined. Fixes #38 * Expose push as QUnit.push to build custom assertions. Fixes #39 * Respect filter pass selection when writing new results. Fixes #43 * Cleanup tests, removing asyncTest-undefined check and formatting * Reset: Fall back to innerHTML when jQuery isn't available. Fixes #44 * Merge branch 'master' of github.com:jquery/qunit * reset doesn't exist here - fixes #28. * - less css cruft, better readability - replaced inline style for test counts with "counts" class - test counts now use a "failed"/"passed" vs "pass"/"fail", shorter/more distinct selectors - pulled all test counts styling together and up (they're always the same regardless of section pass/fail state) * Adding .gitignore file * Removing diff test - diffing works fine, as the browser collapses whitespace in its output, but the test can't do that and isn't worth fixing. * Always synchronize the done-step (it'll set the timeout when necessary), fixes timing race conditions. * Insert location.href as an anchor around the header. Fixes issue #29 * - kill double ;; in escapeHtml. oops * Removed html escaping from QUnit.diff, as input is already escaped, only leads to double escaping. Replaced newlines with single whitespace. * Optimized and cleaned up CSS file * Making the reset-method non-global (only module, test and assertions should be global), and fixing the fixture reset by using jQuery's html() method again, doesn't work with innerHTML, yet * Introducing #qunit-fixture element, deprecating the (never documented) #main element. Doesn't require inline styles and is now independent of jQuery. * Ammending previous commit: Remove jQuery-core specific resets (will be replaced within jQuery testsuite). Fixes issue #19 - QUnit.reset() removes global jQuery ajax event handlers * Remove jQuery-core specific resets (will be replaced within jQuery testsuite). Fixes issue #19 - QUnit.reset() removes global jQuery ajax event handlers * Cleaning up rubble from the previous commit. * Added raises assertion, reusing some of kensnyder's code. * Merged kensnyder's object detection code. Original message: Streamlined object detection and exposed QUnit.objectType as a function. * Fixed some bad formatting. * Move various QUnit properties below the globals-export to avoid init becoming a global method. Fixes issue #11 - Remove 'init' function from a global namespace * Improved output when expected != actual: Output both only then, and add a diff. Fixes issue #10 - Show diff if equal() or deepEqual() failed * Expand failed tests on load. Fixes issue #8 - Failed tests expanded on load * Set location.search for url-filtering instead of location.href. Fixes issue #7 - Modify location.search instead of location.href on test double-click * Add QUnit.begin() callback. Fixes issue #6 - Add 'start' callback. * add css style for result (".test-actual") in passed tests * Fixed output escaping by using leeoniya's custom escaping along with innerHTML. Also paves the way for outputting diffs. * Cleanup * Revert "Revert part of bad merge, back to using createTextNode" * Revert part of bad merge, back to using createTextNode * Fixed doubleclick-handler and filtering to rerun only a single test. * Add ability to css style a test's messages, expected and actual results. Merged from Leon Sorokin (leeoniya). * Remove space between module name and colon * - removed "module" wording from reports (unneeded and cluttery) - added and modified css to make module & test names styleable * Logging support for Each test can extend the module testEnvironment * Fixing whitespace * Update tests to use equal() and deepEqual() rather than the deprecated equals() and same() * Consistent argument names for deepEqual * Skip DOM part of jsDump test if using a SSJS environment without a DOM * Improve async testing by creating the result element before running the test, updating it later. If the test fails, its clear which test is the culprit. * Add autostart option to config. Set via QUnit.config.autostart = false; start later via QUnit.start() * Expose QUnit.config, but don't make config a global * Expose QUnit.config as global to make external workarounds easier * Merge branch 'asyncsetup' * Allowing async setup and teardown. Fixes http://github.com/jquery/qunit/issues#issue/20 * Always output expected and actual result (no reason not to). Fixes http://github.com/jquery/qunit/issues#issue/21 * More changes to the detection of types in jsDump's typeOf. * Change the typeOf checks in QUnit to be more accurate. * Added test for jsDump and modified its options to properly output results when document.createTextNode is used; currently tests for DOM elements cause a stackoverflow error in IEs, works fine, with the correct output, elsewhere * Always use jsDump to output result objects into messages, making the output for passing assertions more useful * Make it so that the display is updated, at least, once a second - also prevents scripts from executing for too long and causing problems. * added tests and patch for qunit.equiv to avoid circular references in objects and arrays * No reason to continue looping, we can stop at this point. Thanks to Chris Thatcher for the suggestion. * Use createTextNode instead of innerHTML for showing test result since expected and actual might be something that looks like a tag. * 'Test card' design added * switched green to blue for top-level pass + reduced padding * Bringing the QUnit API in line with the CommonJS API. * Explicitly set list-style-position: inside on result LIs. * Madness with border-radius. * Corrected banner styles for new class names * Added rounded corners and removed body rules for embedded tests * Resolving merge conflicts. * added colouring for value summary * adding some extra text colours * added styles for toolbar * added new styles * IE 6 and 7 weren't respecting the CSS rules for the banner, used a different technique instead. * Went a bit further and made extra-sure that the target was specified correctly. * Fixed problem where double-clicking an entry in IE caused an error to occur. * Path for http://dev.jquery.com/ticket/5426 - fix the microformat test result * Fixed test() to use 'expected' 2nd param * Remove the named function expressions, to stop Safari 2 from freaking out. Fixes #5. * Each test can extend the module testEnvironment * Extra test for current test environment * Make the current testEnvironment available to utility functions * typeOf in QUnit.jsDump now uses QUnit.is * hoozit in QUnit.equiv now uses QUnit.is * Properly set label attributes. * Some minor tweaks to RyanS' GETParams change. * left a console.log in :( * Took into account a fringe case when using qunit with testswarm. Trying to run all the tests with the extra url params from testswarm would make qunit look for a testsuite that did not exist * need to set config.currentModule to have correct names and working filters * Support logging of testEnvironment * async tests aren't possible on rhino * Fixed a missing QUnit.reset(). * The QUnit. prefix was missing from the uses of the start() method. * Merged lifecycle object into testEnvironment * "replacing totally wrong diff algorithm with a working one" Patch from kassens (manually applied). * fixing jslint errors in test.js * Fixed: testDone() was always called with 0 failures in CommonJS mode * Fixed: moduleDone() was invoked on first call to module() * Added a new asyncTest method - removes the need for having to call start() at the beginning of an asynchronous test. * Added support for expected numbers in the test method. * Fixed broken dynamic loading of tests (can now dynamically load tests and done still works properly). * Simplified the logic for calling 'done' and pushing off new tests - was causing too many inconsistencies otherwise. * Simplified the markup for the QUnit test test suite. * Realized that it's really easy to handle the case where stop() has been called and then an exception is thrown. * Added in better logging support. Now handle moduleStart/moduleDone and testStart/testDone. Also make sure that done only fires once at the end. * Made it so that you can reset the suite to an initial state (at which point tests can be dynamically loaded and run, for example). * Re-worked QUnit to handle dynamic loading of additional code (the 'done' code will be re-run after additional code is loaded). * Removed the old SVN version stuff. * Moved the QUnit source into a separate directory and updated the test suite/packages files. * Added in CommonJS support for exporting the QUnit functionality. * Missing quote from package.json. * Fixed trailing comma in package.json. * Added a CommonJS/Narwhal package.json file. * Accidentally reverted the jsDump/equiv changes that had been made. * Hide the filter toolbar if it's not needed. Also exposed the jsDump and equiv objects on QUnit. * Retooled the QUnit CSS to be more generic. * Renamed the QUnit files from testrunner/testsuite to QUnit. * Expose QUnit.equiv and QUnit.jsDump in QUnit. * Moved the QUnit test directory into the QUnit directory. * Reworked the QUnit CSS (moved jQuery-specific stuff out, made all the other selectors more specific). * Removed the #main reset for non-jQuery code (QUnit.reset can be overwritten with your own reset code). * Moved the QUnit toolbar inline. * Switched to using a qunit- prefix for special elements (banner, userAgent, and tests). * Missed a case in QUnit where an element was assumed to exist. * QUnit's isSet and isObj are no longer needed - you should use same instead. * Make sure that QUnit's equiv entity escaping is enabled by default (otherwise the output gets kind of crazy). * Refactored QUnit, completely reorganized the structure of the file. Additionally made it so that QUnit can run outside of a browser (inside Rhino, for example). * Removed some legacy and jQuery-specific test methods. * Added callbacks for tests and modules. It's now possible to reproduce the full display of the testrunner without using the regular rendering. * QUnit no longer depends upon rendering the results (it can work simply by using the logging callbacks). * Made QUnit no longer require jQuery (it is now a standalone, framework independent, test runner). * Reverted the noglobals changed from QUnit - causing chaos in the jQuery test suite. * qunit: removed noglobals flag, instead always check for globals after teardown; if a test has to introduce a global "myVar", use delete window.myVar in teardown or at the end of a test * qunit: don't child selectors when IE should behave nicely, too * qunit: improvement for the test-scope: create a new object and call setup, the test, and teardown in the scope of that object - allows you to provide test fixtures to each test without messing with global data; kudos to Martin Häcker for the contribution * qunit: added missing semicolons * qunit: fixed a semicolon, that should have been a comma * QUnit: implemented error handling for Opera as proposed by #3628 * qunit: fix for http://dev.jquery.com/ticket/3215 changing wording of testresults, to something more positive (x of y passed, z failed) * QUnit: testrunner.js: Ensures equality of types (String, Boolean, Number) declared with the 'new' prefix. See comments #3, #4 and #5 on http://philrathe.com/articles/equiv * qunit: wrap name of test in span when a module is used for better styling * qunit: auto-prepend default mark (#header, #banner, #userAgent, #tests) when not present * Landing some changes to add logging to QUnit (so that it's easier to hook in to when a test finishes). * Added checkbox for hiding missing tests (tests that fail with the text 'missing test - untested code is broken code') * qunit: eol-style:native and mime-type * HTML being injected for the test result wasn't valid HTML. * qunit: setting mimetype for testsuite.css * qunit: update to Ariel's noglobals patch to support async tests as well * Landing Ariel's change - checks for global variable leakage. * qunit: run module-teardown in its own synchronize block to synchronize with async tests (ugh) * qunit: same: equiv - completely refactored in the testrunner. * testrunner.js: - Update equiv to support Date and RegExp. - Change behavior when comparing function: - abort when in an instance of Object (when references comparison failed) - skip otherwise (like before) * qunit: code refactoring and cleanup * QUnit: update equiv to latest version, handling multiple arguments and NaN, see http://philrathe.com/articles/equiv * QUnit: cleanup, deprecating compare, compare2 and serialArray: usage now throws an error with a helpful message * QUnit: optional timeout argument for stop, while making tests undetermined, useful for debugging * QUnit: added toolbar with "hide passed tests" checkbox to help focus on failed tests * QUnit: minor output formatting * QUnit: adding same-assertion for a recursive comparison of primitive values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests * QUnit: adding same-assertion for a recursive comparison of primitive values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests * QUnit: adding same-assertion for a recursive comparison of primitive values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests * qunit: use window.load to initialize tests, allowing other code to run on document-ready before starting to run tests * qunit: allow either setup or teardown, instead of both or nothing * qunit: make everything private by default, expose only public API; removed old timeout-option (non-deterministic, disabled for a long time anyway); use local $ reference instead of global jQuery reference; minor code cleanup (var config instead of _config; queue.shift instead of slice) * qunit: added support for module level setup/teardown callbacks * qunit: modified example for equals to avoid confusion with parameter ordering * qunit: added id/classes to result element to enable integration with browser automation tools, see http://docs.jquery.com/QUnit#Integration_into_Browser_Automation_Tools * qunit: replaced $ alias with jQuery (merged from jquery/test/data/testrunner.js) * qunit: fixed inline documentation for equals * qunit testrunner - catch and log possible error during reset() * QUnit: Switched out Date and Rev for Id. * qunit: when errors are thrown in a test, the message is successfully show on all browsers. * qunit: added license header * qunit: moved jquery testrunner to top-level project, see http://docs.jquery.com/QUnit * Share project 'qunit' into 'https://jqueryjs.googlecode.com/svn' qunit-1.13.0/MIT-LICENSE.txt000066400000000000000000000021131226204013600151770ustar00rootroot00000000000000Copyright 2013 jQuery Foundation and other contributors http://jquery.com/ 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 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. qunit-1.13.0/README.md000066400000000000000000000061021226204013600142060ustar00rootroot00000000000000[![Build Status](http://jenkins.jquery.com/job/QUnit/badge/icon)](http://jenkins.jquery.com/job/QUnit/) # [QUnit](http://qunitjs.com) - A JavaScript Unit Testing Framework. QUnit is a powerful, easy-to-use, JavaScript unit testing framework. It's used by the jQuery project to test its code and plugins but is capable of testing any generic JavaScript code (and even capable of testing JavaScript code on the server-side). QUnit is especially useful for regression testing: Whenever a bug is reported, write a test that asserts the existence of that particular bug. Then fix it and commit both. Every time you work on the code again, run the tests. If the bug comes up again - a regression - you'll spot it immediately and know how to fix it, because you know what code you just changed. Having good unit test coverage makes safe refactoring easy and cheap. You can run the tests after each small refactoring step and always know what change broke something. QUnit is similar to other unit testing frameworks like JUnit, but makes use of the features JavaScript provides and helps with testing code in the browser, e.g. with its stop/start facilities for testing asynchronous code. If you are interested in helping developing QUnit, you are in the right place. For related discussions, visit the [QUnit and Testing forum](http://forum.jquery.com/qunit-and-testing). ## Development To submit patches, fork the repository, create a branch for the change. Then implement the change, run `grunt` to lint and test it, then commit, push and create a pull request. Include some background for the change in the commit message and `Fixes #nnn`, referring to the issue number you're addressing. To run `grunt`, you need `node` and `npm`, then `npm install grunt -g`. That gives you a global grunt binary. For additional grunt tasks, also run `npm install`. ## Releases Install [git-extras](https://github.com/visionmedia/git-extras) and run `git changelog` to update History.md. Clean up the changelog, removing merge commits or whitespace cleanups. Update qunit/qunit.js|css and package.json to the release version, commit ("Release $version") and tag (Put the 'v' in front of the tag, e.g. `v1.8.0`), update them again to the next version ("Bump post-release version"), commit and push commits and tags: git push --tags origin master To upload to code.jquery.com (replace $version accordingly), ssh to jq03 (swarm.jquery.org). Clone or fetch QUnit, checkout the tag you created, then: sudo cp qunit/qunit.js /var/www/html/code.jquery.com/qunit/qunit-$version.js sudo cp qunit/qunit.css /var/www/html/code.jquery.com/qunit/qunit-$version.css Then update /var/www/html/code.jquery.com/index.html and purge it with: curl -s http://code.origin.jquery.com/?reload Update web sites, replacing previous versions with new ones: * jquery/jquery-wp-content themes/jquery/footer-qunit.php * jquery/qunitjs.com pages/index.html Publish to npm via npm publish Finally announce on Twitter @qunitjs Released v1.12.0: https://github.com/jquery/qunit/tree/v1.12.0 Changelog: https://github.com/jquery/qunit/blob/v1.12.0/History.mdqunit-1.13.0/addons/000077500000000000000000000000001226204013600142005ustar00rootroot00000000000000qunit-1.13.0/addons/.jshintrc000066400000000000000000000005341226204013600160270ustar00rootroot00000000000000{ "predef": [ "QUnit" ], "bitwise": true, "camelcase": true, "curly": true, "eqeqeq": true, "forin": true, "immed": true, "latedef": true, "newcap": true, "noarg": true, "noempty": true, "nonew": true, "plusplus": false, "quotmark": false, "undef": true, "unused": true, "trailing": true, "browser": true, "onevar": true } qunit-1.13.0/addons/phantomjs/000077500000000000000000000000001226204013600162035ustar00rootroot00000000000000qunit-1.13.0/addons/phantomjs/README.md000066400000000000000000000007741226204013600174720ustar00rootroot00000000000000# PhantomJS Runner # A PhantomJS-powered headless test runner, providing basic console output for QUnit tests. ### Usage ### ```bash phantomjs runner.js [url-of-your-qunit-testsuite] [timeout-in-seconds] ``` ### Example ### ```bash phantomjs runner.js http://localhost/qunit/test/index.html ``` ### Notes ### - Requires [PhantomJS](http://phantomjs.org/) 1.6+ (1.7+ recommended). - If you're using Grunt, you should take a look at its [qunit task](https://github.com/gruntjs/grunt-contrib-qunit). qunit-1.13.0/addons/phantomjs/runner.js000066400000000000000000000071771226204013600200660ustar00rootroot00000000000000/* * QtWebKit-powered headless test runner using PhantomJS * * PhantomJS binaries: http://phantomjs.org/download.html * Requires PhantomJS 1.6+ (1.7+ recommended) * * Run with: * phantomjs runner.js [url-of-your-qunit-testsuite] * * e.g. * phantomjs runner.js http://localhost/qunit/test/index.html */ /*global phantom:false, require:false, console:false, window:false, QUnit:false */ (function() { 'use strict'; var url, page, timeout, args = require('system').args; // arg[0]: scriptName, args[1...]: arguments if (args.length < 2 || args.length > 3) { console.error('Usage:\n phantomjs runner.js [url-of-your-qunit-testsuite] [timeout-in-seconds]'); phantom.exit(1); } url = args[1]; page = require('webpage').create(); if (args[2] !== undefined) { timeout = parseInt(args[2], 10); } // Route `console.log()` calls from within the Page context to the main Phantom context (i.e. current `this`) page.onConsoleMessage = function(msg) { console.log(msg); }; page.onInitialized = function() { page.evaluate(addLogging); }; page.onCallback = function(message) { var result, failed; if (message) { if (message.name === 'QUnit.done') { result = message.data; failed = !result || !result.total || result.failed; if (!result.total) { console.error('No tests were executed. Are you loading tests asynchronously?'); } phantom.exit(failed ? 1 : 0); } } }; page.open(url, function(status) { if (status !== 'success') { console.error('Unable to access network: ' + status); phantom.exit(1); } else { // Cannot do this verification with the 'DOMContentLoaded' handler because it // will be too late to attach it if a page does not have any script tags. var qunitMissing = page.evaluate(function() { return (typeof QUnit === 'undefined' || !QUnit); }); if (qunitMissing) { console.error('The `QUnit` object is not present on this page.'); phantom.exit(1); } // Set a timeout on the test running, otherwise tests with async problems will hang forever if (typeof timeout === 'number') { setTimeout(function() { console.error('The specified timeout of ' + timeout + ' seconds has expired. Aborting...'); phantom.exit(1); }, timeout * 1000); } // Do nothing... the callback mechanism will handle everything! } }); function addLogging() { window.document.addEventListener('DOMContentLoaded', function() { var currentTestAssertions = []; QUnit.log(function(details) { var response; // Ignore passing assertions if (details.result) { return; } response = details.message || ''; if (typeof details.expected !== 'undefined') { if (response) { response += ', '; } response += 'expected: ' + details.expected + ', but was: ' + details.actual; } if (details.source) { response += "\n" + details.source; } currentTestAssertions.push('Failed assertion: ' + response); }); QUnit.testDone(function(result) { var i, len, name = result.module + ': ' + result.name; if (result.failed) { console.log('Test failed: ' + name); for (i = 0, len = currentTestAssertions.length; i < len; i++) { console.log(' ' + currentTestAssertions[i]); } } currentTestAssertions.length = 0; }); QUnit.done(function(result) { console.log('Took ' + result.runtime + 'ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.'); if (typeof window.callPhantom === 'function') { window.callPhantom({ 'name': 'QUnit.done', 'data': result }); } }); }, false); } })(); qunit-1.13.0/bower.json000066400000000000000000000003431226204013600147410ustar00rootroot00000000000000{ "name": "qunit", "version": "1.13.0", "main": [ "qunit/qunit.js", "qunit/qunit.css" ], "ignore": [ "**/.*", "package.json", "bower.json", "Gruntfile.js", "node_modules", "test" ] } qunit-1.13.0/build/000077500000000000000000000000001226204013600140275ustar00rootroot00000000000000qunit-1.13.0/build/release.js000066400000000000000000000013731226204013600160110ustar00rootroot00000000000000/*jshint node:true */ module.exports = function( Release ) { var shell = require( "shelljs" ), gruntCmd = process.platform === "win32" ? "grunt.cmd" : "grunt"; Release.define({ issueTracker: "github", changelogShell: function() { return "# Changelog for QUnit v" + Release.newVersion + "\n"; }, generateArtifacts: function( done ) { if ( Release.exec( gruntCmd ).code !== 0 ) { Release.abort("Grunt command failed"); } shell.mkdir( "-p", "qunit" ); shell.cp( "-r", "dist/*", "qunit/" ); shell.mkdir( "-p", "dist/cdn" ); shell.cp( "dist/qunit.js", "dist/cdn/qunit-" + Release.newVersion + ".js" ); shell.cp( "dist/qunit.css", "dist/cdn/qunit-" + Release.newVersion + ".css" ); done([ "qunit/qunit.js", "qunit/qunit.css" ]); }, }); };qunit-1.13.0/package.json000066400000000000000000000020221226204013600152120ustar00rootroot00000000000000{ "name": "qunitjs", "title": "QUnit", "description": "An easy-to-use JavaScript Unit Testing framework.", "version": "1.13.0", "homepage": "http://qunitjs.com", "author": { "name": "jQuery Foundation and other contributors", "url": "https://github.com/jquery/qunit/blob/1.13.0/AUTHORS.txt" }, "repository": { "type": "git", "url": "git://github.com/jquery/qunit.git" }, "keywords": [ "testing", "unit", "jquery" ], "bugs": { "url": "https://github.com/jquery/qunit/issues" }, "licenses": [ { "type": "MIT", "url": "https://github.com/jquery/qunit/blob/1.13.0/MIT-LICENSE.txt" } ], "dependencies": {}, "devDependencies": { "grunt": "0.4.2", "grunt-contrib-concat": "0.3.0", "grunt-contrib-jshint": "0.7.2", "grunt-contrib-qunit": "0.3.0", "grunt-contrib-watch": "0.5.3", "grunt-git-authors": "1.2.0", "testswarm": "1.1.0" }, "scripts": { "test": "grunt", "prepublish": "grunt build" }, "main": "dist/qunit.js" } qunit-1.13.0/qunit/000077500000000000000000000000001226204013600140705ustar00rootroot00000000000000qunit-1.13.0/qunit/qunit.css000066400000000000000000000110601226204013600157400ustar00rootroot00000000000000/*! * QUnit 1.13.0 * http://qunitjs.com/ * * Copyright 2013 jQuery Foundation and other contributors * Released under the MIT license * http://jquery.org/license * * Date: 2014-01-04T17:09Z */ /** Font Family and Sizes */ #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; } #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } #qunit-tests { font-size: smaller; } /** Resets */ #qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter { margin: 0; padding: 0; } /** Header */ #qunit-header { padding: 0.5em 0 0.5em 1em; color: #8699a4; background-color: #0d3349; font-size: 1.5em; line-height: 1em; font-weight: normal; border-radius: 5px 5px 0 0; -moz-border-radius: 5px 5px 0 0; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px; } #qunit-header a { text-decoration: none; color: #c2ccd1; } #qunit-header a:hover, #qunit-header a:focus { color: #fff; } #qunit-testrunner-toolbar label { display: inline-block; padding: 0 .5em 0 .1em; } #qunit-banner { height: 5px; } #qunit-testrunner-toolbar { padding: 0.5em 0 0.5em 2em; color: #5E740B; background-color: #eee; overflow: hidden; } #qunit-userAgent { padding: 0.5em 0 0.5em 2.5em; background-color: #2b81af; color: #fff; text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; } #qunit-modulefilter-container { float: right; } /** Tests: Pass/Fail */ #qunit-tests { list-style-position: inside; } #qunit-tests li { padding: 0.4em 0.5em 0.4em 2.5em; border-bottom: 1px solid #fff; list-style-position: inside; } #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { display: none; } #qunit-tests li strong { cursor: pointer; } #qunit-tests li a { padding: 0.5em; color: #c2ccd1; text-decoration: none; } #qunit-tests li a:hover, #qunit-tests li a:focus { color: #000; } #qunit-tests li .runtime { float: right; font-size: smaller; } .qunit-assert-list { margin-top: 0.5em; padding: 0.5em; background-color: #fff; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; } .qunit-collapsed { display: none; } #qunit-tests table { border-collapse: collapse; margin-top: .2em; } #qunit-tests th { text-align: right; vertical-align: top; padding: 0 .5em 0 0; } #qunit-tests td { vertical-align: top; } #qunit-tests pre { margin: 0; white-space: pre-wrap; word-wrap: break-word; } #qunit-tests del { background-color: #e0f2be; color: #374e0c; text-decoration: none; } #qunit-tests ins { background-color: #ffcaca; color: #500; text-decoration: none; } /*** Test Counts */ #qunit-tests b.counts { color: black; } #qunit-tests b.passed { color: #5E740B; } #qunit-tests b.failed { color: #710909; } #qunit-tests li li { padding: 5px; background-color: #fff; border-bottom: none; list-style-position: inside; } /*** Passing Styles */ #qunit-tests li li.pass { color: #3c510c; background-color: #fff; border-left: 10px solid #C6E746; } #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } #qunit-tests .pass .test-name { color: #366097; } #qunit-tests .pass .test-actual, #qunit-tests .pass .test-expected { color: #999999; } #qunit-banner.qunit-pass { background-color: #C6E746; } /*** Failing Styles */ #qunit-tests li li.fail { color: #710909; background-color: #fff; border-left: 10px solid #EE5757; white-space: pre; } #qunit-tests > li:last-child { border-radius: 0 0 5px 5px; -moz-border-radius: 0 0 5px 5px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px; } #qunit-tests .fail { color: #000000; background-color: #EE5757; } #qunit-tests .fail .test-name, #qunit-tests .fail .module-name { color: #000000; } #qunit-tests .fail .test-actual { color: #EE5757; } #qunit-tests .fail .test-expected { color: green; } #qunit-banner.qunit-fail { background-color: #EE5757; } /** Result */ #qunit-testresult { padding: 0.5em 0.5em 0.5em 2.5em; color: #2b81af; background-color: #D2E0E6; border-bottom: 1px solid white; } #qunit-testresult .module-name { font-weight: bold; } /** Fixture */ #qunit-fixture { position: absolute; top: -10000px; left: -10000px; width: 1000px; height: 1000px; } qunit-1.13.0/qunit/qunit.js000066400000000000000000001621531226204013600155760ustar00rootroot00000000000000/*! * QUnit 1.13.0 * http://qunitjs.com/ * * Copyright 2013 jQuery Foundation and other contributors * Released under the MIT license * http://jquery.org/license * * Date: 2014-01-04T17:09Z */ (function( window ) { var QUnit, assert, config, onErrorFnPrev, testId = 0, fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""), toString = Object.prototype.toString, hasOwn = Object.prototype.hasOwnProperty, // Keep a local reference to Date (GH-283) Date = window.Date, setTimeout = window.setTimeout, defined = { document: typeof window.document !== "undefined", setTimeout: typeof window.setTimeout !== "undefined", sessionStorage: (function() { var x = "qunit-test-string"; try { sessionStorage.setItem( x, x ); sessionStorage.removeItem( x ); return true; } catch( e ) { return false; } }()) }, /** * Provides a normalized error string, correcting an issue * with IE 7 (and prior) where Error.prototype.toString is * not properly implemented * * Based on http://es5.github.com/#x15.11.4.4 * * @param {String|Error} error * @return {String} error message */ errorString = function( error ) { var name, message, errorString = error.toString(); if ( errorString.substring( 0, 7 ) === "[object" ) { name = error.name ? error.name.toString() : "Error"; message = error.message ? error.message.toString() : ""; if ( name && message ) { return name + ": " + message; } else if ( name ) { return name; } else if ( message ) { return message; } else { return "Error"; } } else { return errorString; } }, /** * Makes a clone of an object using only Array or Object as base, * and copies over the own enumerable properties. * * @param {Object} obj * @return {Object} New object with only the own properties (recursively). */ objectValues = function( obj ) { // Grunt 0.3.x uses an older version of jshint that still has jshint/jshint#392. /*jshint newcap: false */ var key, val, vals = QUnit.is( "array", obj ) ? [] : {}; for ( key in obj ) { if ( hasOwn.call( obj, key ) ) { val = obj[key]; vals[key] = val === Object(val) ? objectValues(val) : val; } } return vals; }; // Root QUnit object. // `QUnit` initialized at top of scope QUnit = { // call on start of module test to prepend name to all tests module: function( name, testEnvironment ) { config.currentModule = name; config.currentModuleTestEnvironment = testEnvironment; config.modules[name] = true; }, asyncTest: function( testName, expected, callback ) { if ( arguments.length === 2 ) { callback = expected; expected = null; } QUnit.test( testName, expected, callback, true ); }, test: function( testName, expected, callback, async ) { var test, nameHtml = "" + escapeText( testName ) + ""; if ( arguments.length === 2 ) { callback = expected; expected = null; } if ( config.currentModule ) { nameHtml = "" + escapeText( config.currentModule ) + ": " + nameHtml; } test = new Test({ nameHtml: nameHtml, testName: testName, expected: expected, async: async, callback: callback, module: config.currentModule, moduleTestEnvironment: config.currentModuleTestEnvironment, stack: sourceFromStacktrace( 2 ) }); if ( !validTest( test ) ) { return; } test.queue(); }, // Specify the number of expected assertions to guarantee that failed test (no assertions are run at all) don't slip through. expect: function( asserts ) { if (arguments.length === 1) { config.current.expected = asserts; } else { return config.current.expected; } }, start: function( count ) { // QUnit hasn't been initialized yet. // Note: RequireJS (et al) may delay onLoad if ( config.semaphore === undefined ) { QUnit.begin(function() { // This is triggered at the top of QUnit.load, push start() to the event loop, to allow QUnit.load to finish first setTimeout(function() { QUnit.start( count ); }); }); return; } config.semaphore -= count || 1; // don't start until equal number of stop-calls if ( config.semaphore > 0 ) { return; } // ignore if start is called more often then stop if ( config.semaphore < 0 ) { config.semaphore = 0; QUnit.pushFailure( "Called start() while already started (QUnit.config.semaphore was 0 already)", null, sourceFromStacktrace(2) ); return; } // A slight delay, to avoid any current callbacks if ( defined.setTimeout ) { setTimeout(function() { if ( config.semaphore > 0 ) { return; } if ( config.timeout ) { clearTimeout( config.timeout ); } config.blocking = false; process( true ); }, 13); } else { config.blocking = false; process( true ); } }, stop: function( count ) { config.semaphore += count || 1; config.blocking = true; if ( config.testTimeout && defined.setTimeout ) { clearTimeout( config.timeout ); config.timeout = setTimeout(function() { QUnit.ok( false, "Test timed out" ); config.semaphore = 1; QUnit.start(); }, config.testTimeout ); } } }; // We use the prototype to distinguish between properties that should // be exposed as globals (and in exports) and those that shouldn't (function() { function F() {} F.prototype = QUnit; QUnit = new F(); // Make F QUnit's constructor so that we can add to the prototype later QUnit.constructor = F; }()); /** * Config object: Maintain internal state * Later exposed as QUnit.config * `config` initialized at top of scope */ config = { // The queue of tests to run queue: [], // block until document ready blocking: true, // when enabled, show only failing tests // gets persisted through sessionStorage and can be changed in UI via checkbox hidepassed: false, // by default, run previously failed tests first // very useful in combination with "Hide passed tests" checked reorder: true, // by default, modify document.title when suite is done altertitle: true, // when enabled, all tests must call expect() requireExpects: false, // add checkboxes that are persisted in the query-string // when enabled, the id is set to `true` as a `QUnit.config` property urlConfig: [ { id: "noglobals", label: "Check for Globals", tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings." }, { id: "notrycatch", label: "No try-catch", tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings." } ], // Set of all modules. modules: {}, // logging callback queues begin: [], done: [], log: [], testStart: [], testDone: [], moduleStart: [], moduleDone: [] }; // Initialize more QUnit.config and QUnit.urlParams (function() { var i, location = window.location || { search: "", protocol: "file:" }, params = location.search.slice( 1 ).split( "&" ), length = params.length, urlParams = {}, current; if ( params[ 0 ] ) { for ( i = 0; i < length; i++ ) { current = params[ i ].split( "=" ); 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 ]; } } QUnit.urlParams = urlParams; // String search anywhere in moduleName+testName config.filter = urlParams.filter; // Exact match of the module name config.module = urlParams.module; config.testNumber = parseInt( urlParams.testNumber, 10 ) || null; // Figure out if we're running the tests from a server or not QUnit.isLocal = location.protocol === "file:"; }()); extend( QUnit, { config: config, // Initialize the configuration options init: function() { extend( config, { stats: { all: 0, bad: 0 }, moduleStats: { all: 0, bad: 0 }, started: +new Date(), updateRate: 1000, blocking: false, autostart: true, autorun: false, filter: "", queue: [], semaphore: 1 }); var tests, banner, result, qunit = id( "qunit" ); if ( qunit ) { qunit.innerHTML = "

" + escapeText( document.title ) + "

" + "

" + "
" + "

" + "
    "; } tests = id( "qunit-tests" ); banner = id( "qunit-banner" ); result = id( "qunit-testresult" ); if ( tests ) { tests.innerHTML = ""; } if ( banner ) { banner.className = ""; } if ( result ) { result.parentNode.removeChild( result ); } if ( tests ) { result = document.createElement( "p" ); result.id = "qunit-testresult"; result.className = "result"; tests.parentNode.insertBefore( result, tests ); result.innerHTML = "Running...
     "; } }, // Resets the test setup. Useful for tests that modify the DOM. /* DEPRECATED: Use multiple tests instead of resetting inside a test. Use testStart or testDone for custom cleanup. This method will throw an error in 2.0, and will be removed in 2.1 */ reset: function() { var fixture = id( "qunit-fixture" ); if ( fixture ) { fixture.innerHTML = config.fixture; } }, // Safe object type checking is: function( type, obj ) { return QUnit.objectType( obj ) === type; }, objectType: function( obj ) { if ( typeof obj === "undefined" ) { return "undefined"; } // Consider: typeof null === object if ( obj === null ) { return "null"; } var match = toString.call( obj ).match(/^\[object\s(.*)\]$/), type = match && match[1] || ""; switch ( type ) { case "Number": if ( isNaN(obj) ) { return "nan"; } return "number"; case "String": case "Boolean": case "Array": case "Date": case "RegExp": case "Function": return type.toLowerCase(); } if ( typeof obj === "object" ) { return "object"; } return undefined; }, push: function( result, actual, expected, message ) { if ( !config.current ) { throw new Error( "assertion outside test context, was " + sourceFromStacktrace() ); } var output, source, details = { module: config.current.module, name: config.current.testName, result: result, message: message, actual: actual, expected: expected }; message = escapeText( message ) || ( result ? "okay" : "failed" ); message = "" + message + ""; output = message; if ( !result ) { expected = escapeText( QUnit.jsDump.parse(expected) ); actual = escapeText( QUnit.jsDump.parse(actual) ); output += ""; if ( actual !== expected ) { output += ""; output += ""; } source = sourceFromStacktrace(); if ( source ) { details.source = source; output += ""; } output += "
    Expected:
    " + expected + "
    Result:
    " + actual + "
    Diff:
    " + QUnit.diff( expected, actual ) + "
    Source:
    " + escapeText( source ) + "
    "; } runLoggingCallbacks( "log", QUnit, details ); config.current.assertions.push({ result: !!result, message: output }); }, pushFailure: function( message, source, actual ) { if ( !config.current ) { throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) ); } var output, details = { module: config.current.module, name: config.current.testName, result: false, message: message }; message = escapeText( message ) || "error"; message = "" + message + ""; output = message; output += ""; if ( actual ) { output += ""; } if ( source ) { details.source = source; output += ""; } output += "
    Result:
    " + escapeText( actual ) + "
    Source:
    " + escapeText( source ) + "
    "; runLoggingCallbacks( "log", QUnit, details ); config.current.assertions.push({ result: false, message: output }); }, url: function( params ) { params = extend( extend( {}, QUnit.urlParams ), params ); var key, querystring = "?"; for ( key in params ) { if ( hasOwn.call( params, key ) ) { querystring += encodeURIComponent( key ) + "=" + encodeURIComponent( params[ key ] ) + "&"; } } return window.location.protocol + "//" + window.location.host + window.location.pathname + querystring.slice( 0, -1 ); }, extend: extend, id: id, addEvent: addEvent, addClass: addClass, hasClass: hasClass, removeClass: removeClass // load, equiv, jsDump, diff: Attached later }); /** * @deprecated: Created for backwards compatibility with test runner that set the hook function * into QUnit.{hook}, instead of invoking it and passing the hook function. * QUnit.constructor is set to the empty F() above so that we can add to it's prototype here. * Doing this allows us to tell if the following methods have been overwritten on the actual * QUnit object. */ extend( QUnit.constructor.prototype, { // Logging callbacks; all receive a single argument with the listed properties // run test/logs.html for any related changes begin: registerLoggingCallback( "begin" ), // done: { failed, passed, total, runtime } done: registerLoggingCallback( "done" ), // log: { result, actual, expected, message } log: registerLoggingCallback( "log" ), // testStart: { name } testStart: registerLoggingCallback( "testStart" ), // testDone: { name, failed, passed, total, runtime } testDone: registerLoggingCallback( "testDone" ), // moduleStart: { name } moduleStart: registerLoggingCallback( "moduleStart" ), // moduleDone: { name, failed, passed, total } moduleDone: registerLoggingCallback( "moduleDone" ) }); if ( !defined.document || document.readyState === "complete" ) { config.autorun = true; } QUnit.load = function() { runLoggingCallbacks( "begin", QUnit, {} ); // Initialize the config, saving the execution queue var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, urlConfigCheckboxesContainer, urlConfigCheckboxes, moduleFilter, numModules = 0, moduleNames = [], moduleFilterHtml = "", urlConfigHtml = "", oldconfig = extend( {}, config ); QUnit.init(); extend(config, oldconfig); config.blocking = false; len = config.urlConfig.length; for ( i = 0; i < len; i++ ) { val = config.urlConfig[i]; if ( typeof val === "string" ) { val = { id: val, label: val, tooltip: "[no tooltip available]" }; } config[ val.id ] = QUnit.urlParams[ val.id ]; urlConfigHtml += ""; } for ( i in config.modules ) { if ( config.modules.hasOwnProperty( i ) ) { moduleNames.push(i); } } numModules = moduleNames.length; moduleNames.sort( function( a, b ) { return a.localeCompare( b ); }); moduleFilterHtml += ""; // `userAgent` initialized at top of scope userAgent = id( "qunit-userAgent" ); if ( userAgent ) { userAgent.innerHTML = navigator.userAgent; } // `banner` initialized at top of scope banner = id( "qunit-header" ); if ( banner ) { banner.innerHTML = "" + banner.innerHTML + " "; } // `toolbar` initialized at top of scope toolbar = id( "qunit-testrunner-toolbar" ); if ( toolbar ) { // `filter` initialized at top of scope filter = document.createElement( "input" ); filter.type = "checkbox"; filter.id = "qunit-filter-pass"; addEvent( filter, "click", function() { var tmp, ol = id( "qunit-tests" ); if ( filter.checked ) { ol.className = ol.className + " hidepass"; } else { tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " "; ol.className = tmp.replace( / hidepass /, " " ); } if ( defined.sessionStorage ) { if (filter.checked) { sessionStorage.setItem( "qunit-filter-passed-tests", "true" ); } else { sessionStorage.removeItem( "qunit-filter-passed-tests" ); } } }); if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) { filter.checked = true; // `ol` initialized at top of scope ol = id( "qunit-tests" ); ol.className = ol.className + " hidepass"; } toolbar.appendChild( filter ); // `label` initialized at top of scope label = document.createElement( "label" ); label.setAttribute( "for", "qunit-filter-pass" ); label.setAttribute( "title", "Only show tests and assertions that fail. Stored in sessionStorage." ); label.innerHTML = "Hide passed tests"; toolbar.appendChild( label ); urlConfigCheckboxesContainer = document.createElement("span"); urlConfigCheckboxesContainer.innerHTML = urlConfigHtml; urlConfigCheckboxes = urlConfigCheckboxesContainer.getElementsByTagName("input"); // For oldIE support: // * Add handlers to the individual elements instead of the container // * Use "click" instead of "change" // * Fallback from event.target to event.srcElement addEvents( urlConfigCheckboxes, "click", function( event ) { var params = {}, target = event.target || event.srcElement; params[ target.name ] = target.checked ? true : undefined; window.location = QUnit.url( params ); }); toolbar.appendChild( urlConfigCheckboxesContainer ); if (numModules > 1) { moduleFilter = document.createElement( "span" ); moduleFilter.setAttribute( "id", "qunit-modulefilter-container" ); moduleFilter.innerHTML = moduleFilterHtml; addEvent( moduleFilter.lastChild, "change", function() { var selectBox = moduleFilter.getElementsByTagName("select")[0], selectedModule = decodeURIComponent(selectBox.options[selectBox.selectedIndex].value); window.location = QUnit.url({ module: ( selectedModule === "" ) ? undefined : selectedModule, // Remove any existing filters filter: undefined, testNumber: undefined }); }); toolbar.appendChild(moduleFilter); } } // `main` initialized at top of scope main = id( "qunit-fixture" ); if ( main ) { config.fixture = main.innerHTML; } if ( config.autostart ) { QUnit.start(); } }; if ( defined.document ) { addEvent( window, "load", QUnit.load ); } // `onErrorFnPrev` initialized at top of scope // Preserve other handlers onErrorFnPrev = window.onerror; // Cover uncaught exceptions // Returning true will suppress the default browser handler, // returning false will let it run. window.onerror = function ( error, filePath, linerNr ) { var ret = false; if ( onErrorFnPrev ) { ret = onErrorFnPrev( error, filePath, linerNr ); } // Treat return value as window.onerror itself does, // Only do our handling if not suppressed. if ( ret !== true ) { if ( QUnit.config.current ) { if ( QUnit.config.current.ignoreGlobalErrors ) { return true; } QUnit.pushFailure( error, filePath + ":" + linerNr ); } else { QUnit.test( "global failure", extend( function() { QUnit.pushFailure( error, filePath + ":" + linerNr ); }, { validTest: validTest } ) ); } return false; } return ret; }; function done() { config.autorun = true; // Log the last module results if ( config.previousModule ) { runLoggingCallbacks( "moduleDone", QUnit, { name: config.previousModule, failed: config.moduleStats.bad, passed: config.moduleStats.all - config.moduleStats.bad, total: config.moduleStats.all }); } delete config.previousModule; var i, key, banner = id( "qunit-banner" ), tests = id( "qunit-tests" ), runtime = +new Date() - config.started, passed = config.stats.all - config.stats.bad, html = [ "Tests completed in ", runtime, " milliseconds.
    ", "", passed, " assertions of ", config.stats.all, " passed, ", config.stats.bad, " failed." ].join( "" ); if ( banner ) { banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" ); } if ( tests ) { id( "qunit-testresult" ).innerHTML = html; } if ( config.altertitle && defined.document && document.title ) { // show ✖ for good, ✔ for bad suite result in title // use escape sequences in case file gets loaded with non-utf-8-charset document.title = [ ( config.stats.bad ? "\u2716" : "\u2714" ), document.title.replace( /^[\u2714\u2716] /i, "" ) ].join( " " ); } // clear own sessionStorage items if all tests passed if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) { // `key` & `i` initialized at top of scope for ( i = 0; i < sessionStorage.length; i++ ) { key = sessionStorage.key( i++ ); if ( key.indexOf( "qunit-test-" ) === 0 ) { sessionStorage.removeItem( key ); } } } // scroll back to top to show results if ( window.scrollTo ) { window.scrollTo(0, 0); } runLoggingCallbacks( "done", QUnit, { failed: config.stats.bad, passed: passed, total: config.stats.all, runtime: runtime }); } /** @return Boolean: true if this test should be ran */ function validTest( test ) { var include, filter = config.filter && config.filter.toLowerCase(), module = config.module && config.module.toLowerCase(), fullName = (test.module + ": " + test.testName).toLowerCase(); // Internally-generated tests are always valid if ( test.callback && test.callback.validTest === validTest ) { delete test.callback.validTest; return true; } if ( config.testNumber ) { return test.testNumber === config.testNumber; } if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) { return false; } if ( !filter ) { return true; } include = filter.charAt( 0 ) !== "!"; if ( !include ) { filter = filter.slice( 1 ); } // If the filter matches, we need to honour include if ( fullName.indexOf( filter ) !== -1 ) { return include; } // Otherwise, do the opposite return !include; } // so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions) // Later Safari and IE10 are supposed to support error.stack as well // See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack function extractStacktrace( e, offset ) { offset = offset === undefined ? 3 : offset; var stack, include, i; if ( e.stacktrace ) { // Opera return e.stacktrace.split( "\n" )[ offset + 3 ]; } else if ( e.stack ) { // Firefox, Chrome stack = e.stack.split( "\n" ); if (/^error$/i.test( stack[0] ) ) { stack.shift(); } if ( fileName ) { include = []; for ( i = offset; i < stack.length; i++ ) { if ( stack[ i ].indexOf( fileName ) !== -1 ) { break; } include.push( stack[ i ] ); } if ( include.length ) { return include.join( "\n" ); } } return stack[ offset ]; } else if ( e.sourceURL ) { // Safari, PhantomJS // hopefully one day Safari provides actual stacktraces // exclude useless self-reference for generated Error objects if ( /qunit.js$/.test( e.sourceURL ) ) { return; } // for actual exceptions, this is useful return e.sourceURL + ":" + e.line; } } function sourceFromStacktrace( offset ) { try { throw new Error(); } catch ( e ) { return extractStacktrace( e, offset ); } } /** * Escape text for attribute or text content. */ function escapeText( s ) { if ( !s ) { return ""; } s = s + ""; // Both single quotes and double quotes (for attributes) return s.replace( /['"<>&]/g, function( s ) { switch( s ) { case "'": return "'"; case "\"": return """; case "<": return "<"; case ">": return ">"; case "&": return "&"; } }); } function synchronize( callback, last ) { config.queue.push( callback ); if ( config.autorun && !config.blocking ) { process( last ); } } function process( last ) { function next() { process( last ); } var start = new Date().getTime(); config.depth = config.depth ? config.depth + 1 : 1; while ( config.queue.length && !config.blocking ) { if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) { config.queue.shift()(); } else { setTimeout( next, 13 ); break; } } config.depth--; if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { done(); } } function saveGlobal() { config.pollution = []; if ( config.noglobals ) { for ( var key in window ) { if ( hasOwn.call( window, key ) ) { // in Opera sometimes DOM element ids show up here, ignore them if ( /^qunit-test-output/.test( key ) ) { continue; } config.pollution.push( key ); } } } } function checkPollution() { var newGlobals, deletedGlobals, old = config.pollution; saveGlobal(); newGlobals = diff( config.pollution, old ); if ( newGlobals.length > 0 ) { QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") ); } deletedGlobals = diff( old, config.pollution ); if ( deletedGlobals.length > 0 ) { QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") ); } } // returns a new Array with the elements that are in a but not in b function diff( a, b ) { var i, j, result = a.slice(); for ( i = 0; i < result.length; i++ ) { for ( j = 0; j < b.length; j++ ) { if ( result[i] === b[j] ) { result.splice( i, 1 ); i--; break; } } } return result; } function extend( a, b ) { for ( var prop in b ) { if ( hasOwn.call( b, prop ) ) { // Avoid "Member not found" error in IE8 caused by messing with window.constructor if ( !( prop === "constructor" && a === window ) ) { if ( b[ prop ] === undefined ) { delete a[ prop ]; } else { a[ prop ] = b[ prop ]; } } } } return a; } /** * @param {HTMLElement} elem * @param {string} type * @param {Function} fn */ function addEvent( elem, type, fn ) { if ( elem.addEventListener ) { // Standards-based browsers elem.addEventListener( type, fn, false ); } else if ( elem.attachEvent ) { // support: IE <9 elem.attachEvent( "on" + type, fn ); } else { // Caller must ensure support for event listeners is present throw new Error( "addEvent() was called in a context without event listener support" ); } } /** * @param {Array|NodeList} elems * @param {string} type * @param {Function} fn */ function addEvents( elems, type, fn ) { var i = elems.length; while ( i-- ) { addEvent( elems[i], type, fn ); } } function hasClass( elem, name ) { return (" " + elem.className + " ").indexOf(" " + name + " ") > -1; } function addClass( elem, name ) { if ( !hasClass( elem, name ) ) { elem.className += (elem.className ? " " : "") + name; } } function removeClass( elem, name ) { var set = " " + elem.className + " "; // Class name may appear multiple times while ( set.indexOf(" " + name + " ") > -1 ) { set = set.replace(" " + name + " " , " "); } // If possible, trim it for prettiness, but not necessarily elem.className = typeof set.trim === "function" ? set.trim() : set.replace(/^\s+|\s+$/g, ""); } function id( name ) { return defined.document && document.getElementById && document.getElementById( name ); } function registerLoggingCallback( key ) { return function( callback ) { config[key].push( callback ); }; } // Supports deprecated method of completely overwriting logging callbacks function runLoggingCallbacks( key, scope, args ) { var i, callbacks; if ( QUnit.hasOwnProperty( key ) ) { QUnit[ key ].call(scope, args ); } else { callbacks = config[ key ]; for ( i = 0; i < callbacks.length; i++ ) { callbacks[ i ].call( scope, args ); } } } // 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:
    " + 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 + " (" + bad + ", " + good + ", " + this.assertions.length + ")"; 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 = "" + escapeText( msg ) + ""; if ( !result ) { source = sourceFromStacktrace( 2 ); if ( source ) { details.source = source; msg += "
    Source:
    " +
    					escapeText( source ) +
    					"
    "; } } 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.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. // Author: Philippe Rathé QUnit.equiv = (function() { // Call the o related callback with the given arguments. function bindCallbacks( o, callbacks, args ) { var prop = QUnit.objectType( o ); if ( prop ) { if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) { return callbacks[ prop ].apply( callbacks, args ); } else { return callbacks[ prop ]; // or undefined } } } // the real equiv function var innerEquiv, // stack to decide between skip/abort functions callers = [], // stack to avoiding loops from circular referencing parents = [], parentsB = [], getProto = Object.getPrototypeOf || function ( obj ) { /*jshint camelcase:false */ return obj.__proto__; }, callbacks = (function () { // for string, boolean, number and null function useStrictEquality( b, a ) { /*jshint eqeqeq:false */ if ( b instanceof a.constructor || a instanceof b.constructor ) { // to catch short annotation VS 'new' annotation of a // declaration // e.g. var i = 1; // var j = new Number(1); return a == b; } else { return a === b; } } return { "string": useStrictEquality, "boolean": useStrictEquality, "number": useStrictEquality, "null": useStrictEquality, "undefined": useStrictEquality, "nan": function( b ) { return isNaN( b ); }, "date": function( b, a ) { return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf(); }, "regexp": function( b, a ) { return QUnit.objectType( b ) === "regexp" && // the regex itself a.source === b.source && // and its modifiers a.global === b.global && // (gmi) ... a.ignoreCase === b.ignoreCase && a.multiline === b.multiline && a.sticky === b.sticky; }, // - skip when the property is a method of an instance (OOP) // - abort otherwise, // initial === would have catch identical references anyway "function": function() { var caller = callers[callers.length - 1]; return caller !== Object && typeof caller !== "undefined"; }, "array": function( b, a ) { var i, j, len, loop, aCircular, bCircular; // b could be an object literal here if ( QUnit.objectType( b ) !== "array" ) { return false; } len = a.length; if ( len !== b.length ) { // safe and faster return false; } // track reference to avoid circular references parents.push( a ); parentsB.push( b ); for ( i = 0; i < len; i++ ) { loop = false; for ( j = 0; j < parents.length; j++ ) { aCircular = parents[j] === a[i]; bCircular = parentsB[j] === b[i]; if ( aCircular || bCircular ) { if ( a[i] === b[i] || aCircular && bCircular ) { loop = true; } else { parents.pop(); parentsB.pop(); return false; } } } if ( !loop && !innerEquiv(a[i], b[i]) ) { parents.pop(); parentsB.pop(); return false; } } parents.pop(); parentsB.pop(); return true; }, "object": function( b, a ) { /*jshint forin:false */ var i, j, loop, aCircular, bCircular, // Default to true eq = true, aProperties = [], bProperties = []; // comparing constructors is more strict than using // instanceof if ( a.constructor !== b.constructor ) { // Allow objects with no prototype to be equivalent to // objects with Object as their constructor. if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) || ( getProto(b) === null && getProto(a) === Object.prototype ) ) ) { return false; } } // stack constructor before traversing properties callers.push( a.constructor ); // track reference to avoid circular references parents.push( a ); parentsB.push( b ); // be strict: don't ensure hasOwnProperty and go deep for ( i in a ) { loop = false; for ( j = 0; j < parents.length; j++ ) { aCircular = parents[j] === a[i]; bCircular = parentsB[j] === b[i]; if ( aCircular || bCircular ) { if ( a[i] === b[i] || aCircular && bCircular ) { loop = true; } else { eq = false; break; } } } aProperties.push(i); if ( !loop && !innerEquiv(a[i], b[i]) ) { eq = false; break; } } parents.pop(); parentsB.pop(); callers.pop(); // unstack, we are done for ( i in b ) { bProperties.push( i ); // collect b's properties } // Ensures identical properties name return eq && innerEquiv( aProperties.sort(), bProperties.sort() ); } }; }()); innerEquiv = function() { // can take multiple arguments var args = [].slice.apply( arguments ); if ( args.length < 2 ) { return true; // end transition } return (function( a, b ) { if ( a === b ) { return true; // catch the most you can } else if ( a === null || b === null || typeof a === "undefined" || typeof b === "undefined" || QUnit.objectType(a) !== QUnit.objectType(b) ) { return false; // don't lose time with error prone cases } else { return bindCallbacks(a, callbacks, [ b, a ]); } // apply transition with (1..n) arguments }( args[0], args[1] ) && innerEquiv.apply( this, args.splice(1, args.length - 1 )) ); }; return innerEquiv; }()); /** * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | * http://flesler.blogspot.com Licensed under BSD * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008 * * @projectDescription Advanced and extensible data dumping for Javascript. * @version 1.0.0 * @author Ariel Flesler * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} */ QUnit.jsDump = (function() { function quote( str ) { return "\"" + str.toString().replace( /"/g, "\\\"" ) + "\""; } function literal( o ) { return o + ""; } function join( pre, arr, post ) { var s = jsDump.separator(), base = jsDump.indent(), inner = jsDump.indent(1); if ( arr.join ) { arr = arr.join( "," + s + inner ); } if ( !arr ) { return pre + post; } return [ pre, inner + arr, base + post ].join(s); } function array( arr, stack ) { var i = arr.length, ret = new Array(i); this.up(); while ( i-- ) { ret[i] = this.parse( arr[i] , undefined , stack); } this.down(); return join( "[", ret, "]" ); } var reName = /^function (\w+)/, jsDump = { // type is used mostly internally, you can fix a (custom)type in advance parse: function( obj, type, stack ) { stack = stack || [ ]; var inStack, res, parser = this.parsers[ type || this.typeOf(obj) ]; type = typeof parser; inStack = inArray( obj, stack ); if ( inStack !== -1 ) { return "recursion(" + (inStack - stack.length) + ")"; } if ( type === "function" ) { stack.push( obj ); res = parser.call( this, obj, stack ); stack.pop(); return res; } return ( type === "string" ) ? parser : this.parsers.error; }, typeOf: function( obj ) { var type; if ( obj === null ) { type = "null"; } else if ( typeof obj === "undefined" ) { type = "undefined"; } else if ( QUnit.is( "regexp", obj) ) { type = "regexp"; } else if ( QUnit.is( "date", obj) ) { type = "date"; } else if ( QUnit.is( "function", obj) ) { type = "function"; } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) { type = "window"; } else if ( obj.nodeType === 9 ) { type = "document"; } else if ( obj.nodeType ) { type = "node"; } else if ( // native arrays toString.call( obj ) === "[object Array]" || // NodeList objects ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) ) ) { type = "array"; } else if ( obj.constructor === Error.prototype.constructor ) { type = "error"; } else { type = typeof obj; } return type; }, separator: function() { return this.multiline ? this.HTML ? "
    " : "\n" : this.HTML ? " " : " "; }, // extra can be a number, shortcut for increasing-calling-decreasing indent: function( extra ) { if ( !this.multiline ) { return ""; } var chr = this.indentChar; if ( this.HTML ) { chr = chr.replace( /\t/g, " " ).replace( / /g, " " ); } return new Array( this.depth + ( extra || 0 ) ).join(chr); }, up: function( a ) { this.depth += a || 1; }, down: function( a ) { this.depth -= a || 1; }, setParser: function( name, parser ) { this.parsers[name] = parser; }, // The next 3 are exposed so you can use them quote: quote, literal: literal, join: join, // depth: 1, // This is the list of parsers, to modify them, use jsDump.setParser parsers: { window: "[Window]", document: "[Document]", error: function(error) { return "Error(\"" + error.message + "\")"; }, unknown: "[Unknown]", "null": "null", "undefined": "undefined", "function": function( fn ) { var ret = "function", // functions never have name in IE name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1]; if ( name ) { ret += " " + name; } ret += "( "; ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" ); return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" ); }, array: array, nodelist: array, "arguments": array, object: function( map, stack ) { /*jshint forin:false */ var ret = [ ], keys, key, val, i; QUnit.jsDump.up(); keys = []; for ( key in map ) { keys.push( key ); } keys.sort(); for ( i = 0; i < keys.length; i++ ) { key = keys[ i ]; val = map[ key ]; ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) ); } QUnit.jsDump.down(); return join( "{", ret, "}" ); }, node: function( node ) { var len, i, val, open = QUnit.jsDump.HTML ? "<" : "<", close = QUnit.jsDump.HTML ? ">" : ">", tag = node.nodeName.toLowerCase(), ret = open + tag, attrs = node.attributes; if ( attrs ) { for ( i = 0, len = attrs.length; i < len; i++ ) { val = attrs[i].nodeValue; // IE6 includes all attributes in .attributes, even ones not explicitly set. // Those have values like undefined, null, 0, false, "" or "inherit". if ( val && val !== "inherit" ) { ret += " " + attrs[i].nodeName + "=" + QUnit.jsDump.parse( val, "attribute" ); } } } ret += close; // Show content of TextNode or CDATASection if ( node.nodeType === 3 || node.nodeType === 4 ) { ret += node.nodeValue; } return ret + open + "/" + tag + close; }, // function calls it internally, it's the arguments part of the function functionArgs: function( fn ) { var args, l = fn.length; if ( !l ) { return ""; } args = new Array(l); while ( l-- ) { // 97 is 'a' args[l] = String.fromCharCode(97+l); } return " " + args.join( ", " ) + " "; }, // object calls it internally, the key part of an item in a map key: quote, // function calls it internally, it's the content of the function functionCode: "[code]", // node calls it internally, it's an html attribute value attribute: quote, string: quote, date: quote, regexp: literal, number: literal, "boolean": literal }, // if true, entities are escaped ( <, >, \t, space and \n ) HTML: false, // indentation unit indentChar: " ", // if true, items in a collection, are separated by a \n, else just a space. multiline: true }; return jsDump; }()); /* * Javascript Diff Algorithm * By John Resig (http://ejohn.org/) * Modified by Chu Alan "sprite" * * Released under the MIT license. * * More Info: * http://ejohn.org/projects/javascript-diff-algorithm/ * * Usage: QUnit.diff(expected, actual) * * QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the quick brown fox jumped jumps over" */ QUnit.diff = (function() { /*jshint eqeqeq:false, eqnull:true */ function diff( o, n ) { var i, ns = {}, os = {}; for ( i = 0; i < n.length; i++ ) { if ( !hasOwn.call( ns, n[i] ) ) { ns[ n[i] ] = { rows: [], o: null }; } ns[ n[i] ].rows.push( i ); } for ( i = 0; i < o.length; i++ ) { if ( !hasOwn.call( os, o[i] ) ) { os[ o[i] ] = { rows: [], n: null }; } os[ o[i] ].rows.push( i ); } for ( i in ns ) { if ( hasOwn.call( ns, i ) ) { if ( ns[i].rows.length === 1 && hasOwn.call( os, i ) && os[i].rows.length === 1 ) { n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] }; o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] }; } } } for ( i = 0; i < n.length - 1; i++ ) { if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null && n[ i + 1 ] == o[ n[i].row + 1 ] ) { n[ i + 1 ] = { text: n[ i + 1 ], row: n[i].row + 1 }; o[ n[i].row + 1 ] = { text: o[ n[i].row + 1 ], row: i + 1 }; } } for ( i = n.length - 1; i > 0; i-- ) { if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null && n[ i - 1 ] == o[ n[i].row - 1 ]) { n[ i - 1 ] = { text: n[ i - 1 ], row: n[i].row - 1 }; o[ n[i].row - 1 ] = { text: o[ n[i].row - 1 ], row: i - 1 }; } } return { o: o, n: n }; } return function( o, n ) { o = o.replace( /\s+$/, "" ); n = n.replace( /\s+$/, "" ); var i, pre, str = "", out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ), oSpace = o.match(/\s+/g), nSpace = n.match(/\s+/g); if ( oSpace == null ) { oSpace = [ " " ]; } else { oSpace.push( " " ); } if ( nSpace == null ) { nSpace = [ " " ]; } else { nSpace.push( " " ); } if ( out.n.length === 0 ) { for ( i = 0; i < out.o.length; i++ ) { str += "" + out.o[i] + oSpace[i] + ""; } } else { if ( out.n[0].text == null ) { for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) { str += "" + out.o[n] + oSpace[n] + ""; } } for ( i = 0; i < out.n.length; i++ ) { if (out.n[i].text == null) { str += "" + out.n[i] + nSpace[i] + ""; } else { // `pre` initialized at top of scope pre = ""; for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) { pre += "" + out.o[n] + oSpace[n] + ""; } str += " " + out.n[i].text + nSpace[i] + pre; } } } return str; }; }()); // For browser, export only select globals if ( typeof window !== "undefined" ) { extend( window, QUnit.constructor.prototype ); window.QUnit = QUnit; } // 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; })() )); qunit-1.13.0/src/000077500000000000000000000000001226204013600135175ustar00rootroot00000000000000qunit-1.13.0/src/assert.js000066400000000000000000000115641226204013600153650ustar00rootroot00000000000000// `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 = "" + escapeText( msg ) + ""; if ( !result ) { source = sourceFromStacktrace( 2 ); if ( source ) { details.source = source; msg += "
    Source:
    " +
    					escapeText( source ) +
    					"
    "; } } 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.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" ); }; qunit-1.13.0/src/core.js000066400000000000000000000705011226204013600150100ustar00rootroot00000000000000var QUnit, assert, config, onErrorFnPrev, testId = 0, fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""), toString = Object.prototype.toString, hasOwn = Object.prototype.hasOwnProperty, // Keep a local reference to Date (GH-283) Date = window.Date, setTimeout = window.setTimeout, defined = { document: typeof window.document !== "undefined", setTimeout: typeof window.setTimeout !== "undefined", sessionStorage: (function() { var x = "qunit-test-string"; try { sessionStorage.setItem( x, x ); sessionStorage.removeItem( x ); return true; } catch( e ) { return false; } }()) }, /** * Provides a normalized error string, correcting an issue * with IE 7 (and prior) where Error.prototype.toString is * not properly implemented * * Based on http://es5.github.com/#x15.11.4.4 * * @param {String|Error} error * @return {String} error message */ errorString = function( error ) { var name, message, errorString = error.toString(); if ( errorString.substring( 0, 7 ) === "[object" ) { name = error.name ? error.name.toString() : "Error"; message = error.message ? error.message.toString() : ""; if ( name && message ) { return name + ": " + message; } else if ( name ) { return name; } else if ( message ) { return message; } else { return "Error"; } } else { return errorString; } }, /** * Makes a clone of an object using only Array or Object as base, * and copies over the own enumerable properties. * * @param {Object} obj * @return {Object} New object with only the own properties (recursively). */ objectValues = function( obj ) { // Grunt 0.3.x uses an older version of jshint that still has jshint/jshint#392. /*jshint newcap: false */ var key, val, vals = QUnit.is( "array", obj ) ? [] : {}; for ( key in obj ) { if ( hasOwn.call( obj, key ) ) { val = obj[key]; vals[key] = val === Object(val) ? objectValues(val) : val; } } return vals; }; // Root QUnit object. // `QUnit` initialized at top of scope QUnit = { // call on start of module test to prepend name to all tests module: function( name, testEnvironment ) { config.currentModule = name; config.currentModuleTestEnvironment = testEnvironment; config.modules[name] = true; }, asyncTest: function( testName, expected, callback ) { if ( arguments.length === 2 ) { callback = expected; expected = null; } QUnit.test( testName, expected, callback, true ); }, test: function( testName, expected, callback, async ) { var test, nameHtml = "" + escapeText( testName ) + ""; if ( arguments.length === 2 ) { callback = expected; expected = null; } if ( config.currentModule ) { nameHtml = "" + escapeText( config.currentModule ) + ": " + nameHtml; } test = new Test({ nameHtml: nameHtml, testName: testName, expected: expected, async: async, callback: callback, module: config.currentModule, moduleTestEnvironment: config.currentModuleTestEnvironment, stack: sourceFromStacktrace( 2 ) }); if ( !validTest( test ) ) { return; } test.queue(); }, // Specify the number of expected assertions to guarantee that failed test (no assertions are run at all) don't slip through. expect: function( asserts ) { if (arguments.length === 1) { config.current.expected = asserts; } else { return config.current.expected; } }, start: function( count ) { // QUnit hasn't been initialized yet. // Note: RequireJS (et al) may delay onLoad if ( config.semaphore === undefined ) { QUnit.begin(function() { // This is triggered at the top of QUnit.load, push start() to the event loop, to allow QUnit.load to finish first setTimeout(function() { QUnit.start( count ); }); }); return; } config.semaphore -= count || 1; // don't start until equal number of stop-calls if ( config.semaphore > 0 ) { return; } // ignore if start is called more often then stop if ( config.semaphore < 0 ) { config.semaphore = 0; QUnit.pushFailure( "Called start() while already started (QUnit.config.semaphore was 0 already)", null, sourceFromStacktrace(2) ); return; } // A slight delay, to avoid any current callbacks if ( defined.setTimeout ) { setTimeout(function() { if ( config.semaphore > 0 ) { return; } if ( config.timeout ) { clearTimeout( config.timeout ); } config.blocking = false; process( true ); }, 13); } else { config.blocking = false; process( true ); } }, stop: function( count ) { config.semaphore += count || 1; config.blocking = true; if ( config.testTimeout && defined.setTimeout ) { clearTimeout( config.timeout ); config.timeout = setTimeout(function() { QUnit.ok( false, "Test timed out" ); config.semaphore = 1; QUnit.start(); }, config.testTimeout ); } } }; // We use the prototype to distinguish between properties that should // be exposed as globals (and in exports) and those that shouldn't (function() { function F() {} F.prototype = QUnit; QUnit = new F(); // Make F QUnit's constructor so that we can add to the prototype later QUnit.constructor = F; }()); /** * Config object: Maintain internal state * Later exposed as QUnit.config * `config` initialized at top of scope */ config = { // The queue of tests to run queue: [], // block until document ready blocking: true, // when enabled, show only failing tests // gets persisted through sessionStorage and can be changed in UI via checkbox hidepassed: false, // by default, run previously failed tests first // very useful in combination with "Hide passed tests" checked reorder: true, // by default, modify document.title when suite is done altertitle: true, // when enabled, all tests must call expect() requireExpects: false, // add checkboxes that are persisted in the query-string // when enabled, the id is set to `true` as a `QUnit.config` property urlConfig: [ { id: "noglobals", label: "Check for Globals", tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings." }, { id: "notrycatch", label: "No try-catch", tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings." } ], // Set of all modules. modules: {}, // logging callback queues begin: [], done: [], log: [], testStart: [], testDone: [], moduleStart: [], moduleDone: [] }; // Initialize more QUnit.config and QUnit.urlParams (function() { var i, location = window.location || { search: "", protocol: "file:" }, params = location.search.slice( 1 ).split( "&" ), length = params.length, urlParams = {}, current; if ( params[ 0 ] ) { for ( i = 0; i < length; i++ ) { current = params[ i ].split( "=" ); 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 ]; } } QUnit.urlParams = urlParams; // String search anywhere in moduleName+testName config.filter = urlParams.filter; // Exact match of the module name config.module = urlParams.module; config.testNumber = parseInt( urlParams.testNumber, 10 ) || null; // Figure out if we're running the tests from a server or not QUnit.isLocal = location.protocol === "file:"; }()); extend( QUnit, { config: config, // Initialize the configuration options init: function() { extend( config, { stats: { all: 0, bad: 0 }, moduleStats: { all: 0, bad: 0 }, started: +new Date(), updateRate: 1000, blocking: false, autostart: true, autorun: false, filter: "", queue: [], semaphore: 1 }); var tests, banner, result, qunit = id( "qunit" ); if ( qunit ) { qunit.innerHTML = "

    " + escapeText( document.title ) + "

    " + "

    " + "
    " + "

    " + "
      "; } tests = id( "qunit-tests" ); banner = id( "qunit-banner" ); result = id( "qunit-testresult" ); if ( tests ) { tests.innerHTML = ""; } if ( banner ) { banner.className = ""; } if ( result ) { result.parentNode.removeChild( result ); } if ( tests ) { result = document.createElement( "p" ); result.id = "qunit-testresult"; result.className = "result"; tests.parentNode.insertBefore( result, tests ); result.innerHTML = "Running...
       "; } }, // Resets the test setup. Useful for tests that modify the DOM. /* DEPRECATED: Use multiple tests instead of resetting inside a test. Use testStart or testDone for custom cleanup. This method will throw an error in 2.0, and will be removed in 2.1 */ reset: function() { var fixture = id( "qunit-fixture" ); if ( fixture ) { fixture.innerHTML = config.fixture; } }, // Safe object type checking is: function( type, obj ) { return QUnit.objectType( obj ) === type; }, objectType: function( obj ) { if ( typeof obj === "undefined" ) { return "undefined"; } // Consider: typeof null === object if ( obj === null ) { return "null"; } var match = toString.call( obj ).match(/^\[object\s(.*)\]$/), type = match && match[1] || ""; switch ( type ) { case "Number": if ( isNaN(obj) ) { return "nan"; } return "number"; case "String": case "Boolean": case "Array": case "Date": case "RegExp": case "Function": return type.toLowerCase(); } if ( typeof obj === "object" ) { return "object"; } return undefined; }, push: function( result, actual, expected, message ) { if ( !config.current ) { throw new Error( "assertion outside test context, was " + sourceFromStacktrace() ); } var output, source, details = { module: config.current.module, name: config.current.testName, result: result, message: message, actual: actual, expected: expected }; message = escapeText( message ) || ( result ? "okay" : "failed" ); message = "" + message + ""; output = message; if ( !result ) { expected = escapeText( QUnit.jsDump.parse(expected) ); actual = escapeText( QUnit.jsDump.parse(actual) ); output += ""; if ( actual !== expected ) { output += ""; output += ""; } source = sourceFromStacktrace(); if ( source ) { details.source = source; output += ""; } output += "
      Expected:
      " + expected + "
      Result:
      " + actual + "
      Diff:
      " + QUnit.diff( expected, actual ) + "
      Source:
      " + escapeText( source ) + "
      "; } runLoggingCallbacks( "log", QUnit, details ); config.current.assertions.push({ result: !!result, message: output }); }, pushFailure: function( message, source, actual ) { if ( !config.current ) { throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) ); } var output, details = { module: config.current.module, name: config.current.testName, result: false, message: message }; message = escapeText( message ) || "error"; message = "" + message + ""; output = message; output += ""; if ( actual ) { output += ""; } if ( source ) { details.source = source; output += ""; } output += "
      Result:
      " + escapeText( actual ) + "
      Source:
      " + escapeText( source ) + "
      "; runLoggingCallbacks( "log", QUnit, details ); config.current.assertions.push({ result: false, message: output }); }, url: function( params ) { params = extend( extend( {}, QUnit.urlParams ), params ); var key, querystring = "?"; for ( key in params ) { if ( hasOwn.call( params, key ) ) { querystring += encodeURIComponent( key ) + "=" + encodeURIComponent( params[ key ] ) + "&"; } } return window.location.protocol + "//" + window.location.host + window.location.pathname + querystring.slice( 0, -1 ); }, extend: extend, id: id, addEvent: addEvent, addClass: addClass, hasClass: hasClass, removeClass: removeClass // load, equiv, jsDump, diff: Attached later }); /** * @deprecated: Created for backwards compatibility with test runner that set the hook function * into QUnit.{hook}, instead of invoking it and passing the hook function. * QUnit.constructor is set to the empty F() above so that we can add to it's prototype here. * Doing this allows us to tell if the following methods have been overwritten on the actual * QUnit object. */ extend( QUnit.constructor.prototype, { // Logging callbacks; all receive a single argument with the listed properties // run test/logs.html for any related changes begin: registerLoggingCallback( "begin" ), // done: { failed, passed, total, runtime } done: registerLoggingCallback( "done" ), // log: { result, actual, expected, message } log: registerLoggingCallback( "log" ), // testStart: { name } testStart: registerLoggingCallback( "testStart" ), // testDone: { name, failed, passed, total, runtime } testDone: registerLoggingCallback( "testDone" ), // moduleStart: { name } moduleStart: registerLoggingCallback( "moduleStart" ), // moduleDone: { name, failed, passed, total } moduleDone: registerLoggingCallback( "moduleDone" ) }); if ( !defined.document || document.readyState === "complete" ) { config.autorun = true; } QUnit.load = function() { runLoggingCallbacks( "begin", QUnit, {} ); // Initialize the config, saving the execution queue var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, urlConfigCheckboxesContainer, urlConfigCheckboxes, moduleFilter, numModules = 0, moduleNames = [], moduleFilterHtml = "", urlConfigHtml = "", oldconfig = extend( {}, config ); QUnit.init(); extend(config, oldconfig); config.blocking = false; len = config.urlConfig.length; for ( i = 0; i < len; i++ ) { val = config.urlConfig[i]; if ( typeof val === "string" ) { val = { id: val, label: val, tooltip: "[no tooltip available]" }; } config[ val.id ] = QUnit.urlParams[ val.id ]; urlConfigHtml += ""; } for ( i in config.modules ) { if ( config.modules.hasOwnProperty( i ) ) { moduleNames.push(i); } } numModules = moduleNames.length; moduleNames.sort( function( a, b ) { return a.localeCompare( b ); }); moduleFilterHtml += ""; // `userAgent` initialized at top of scope userAgent = id( "qunit-userAgent" ); if ( userAgent ) { userAgent.innerHTML = navigator.userAgent; } // `banner` initialized at top of scope banner = id( "qunit-header" ); if ( banner ) { banner.innerHTML = "" + banner.innerHTML + " "; } // `toolbar` initialized at top of scope toolbar = id( "qunit-testrunner-toolbar" ); if ( toolbar ) { // `filter` initialized at top of scope filter = document.createElement( "input" ); filter.type = "checkbox"; filter.id = "qunit-filter-pass"; addEvent( filter, "click", function() { var tmp, ol = id( "qunit-tests" ); if ( filter.checked ) { ol.className = ol.className + " hidepass"; } else { tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " "; ol.className = tmp.replace( / hidepass /, " " ); } if ( defined.sessionStorage ) { if (filter.checked) { sessionStorage.setItem( "qunit-filter-passed-tests", "true" ); } else { sessionStorage.removeItem( "qunit-filter-passed-tests" ); } } }); if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) { filter.checked = true; // `ol` initialized at top of scope ol = id( "qunit-tests" ); ol.className = ol.className + " hidepass"; } toolbar.appendChild( filter ); // `label` initialized at top of scope label = document.createElement( "label" ); label.setAttribute( "for", "qunit-filter-pass" ); label.setAttribute( "title", "Only show tests and assertions that fail. Stored in sessionStorage." ); label.innerHTML = "Hide passed tests"; toolbar.appendChild( label ); urlConfigCheckboxesContainer = document.createElement("span"); urlConfigCheckboxesContainer.innerHTML = urlConfigHtml; urlConfigCheckboxes = urlConfigCheckboxesContainer.getElementsByTagName("input"); // For oldIE support: // * Add handlers to the individual elements instead of the container // * Use "click" instead of "change" // * Fallback from event.target to event.srcElement addEvents( urlConfigCheckboxes, "click", function( event ) { var params = {}, target = event.target || event.srcElement; params[ target.name ] = target.checked ? true : undefined; window.location = QUnit.url( params ); }); toolbar.appendChild( urlConfigCheckboxesContainer ); if (numModules > 1) { moduleFilter = document.createElement( "span" ); moduleFilter.setAttribute( "id", "qunit-modulefilter-container" ); moduleFilter.innerHTML = moduleFilterHtml; addEvent( moduleFilter.lastChild, "change", function() { var selectBox = moduleFilter.getElementsByTagName("select")[0], selectedModule = decodeURIComponent(selectBox.options[selectBox.selectedIndex].value); window.location = QUnit.url({ module: ( selectedModule === "" ) ? undefined : selectedModule, // Remove any existing filters filter: undefined, testNumber: undefined }); }); toolbar.appendChild(moduleFilter); } } // `main` initialized at top of scope main = id( "qunit-fixture" ); if ( main ) { config.fixture = main.innerHTML; } if ( config.autostart ) { QUnit.start(); } }; if ( defined.document ) { addEvent( window, "load", QUnit.load ); } // `onErrorFnPrev` initialized at top of scope // Preserve other handlers onErrorFnPrev = window.onerror; // Cover uncaught exceptions // Returning true will suppress the default browser handler, // returning false will let it run. window.onerror = function ( error, filePath, linerNr ) { var ret = false; if ( onErrorFnPrev ) { ret = onErrorFnPrev( error, filePath, linerNr ); } // Treat return value as window.onerror itself does, // Only do our handling if not suppressed. if ( ret !== true ) { if ( QUnit.config.current ) { if ( QUnit.config.current.ignoreGlobalErrors ) { return true; } QUnit.pushFailure( error, filePath + ":" + linerNr ); } else { QUnit.test( "global failure", extend( function() { QUnit.pushFailure( error, filePath + ":" + linerNr ); }, { validTest: validTest } ) ); } return false; } return ret; }; function done() { config.autorun = true; // Log the last module results if ( config.previousModule ) { runLoggingCallbacks( "moduleDone", QUnit, { name: config.previousModule, failed: config.moduleStats.bad, passed: config.moduleStats.all - config.moduleStats.bad, total: config.moduleStats.all }); } delete config.previousModule; var i, key, banner = id( "qunit-banner" ), tests = id( "qunit-tests" ), runtime = +new Date() - config.started, passed = config.stats.all - config.stats.bad, html = [ "Tests completed in ", runtime, " milliseconds.
      ", "", passed, " assertions of ", config.stats.all, " passed, ", config.stats.bad, " failed." ].join( "" ); if ( banner ) { banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" ); } if ( tests ) { id( "qunit-testresult" ).innerHTML = html; } if ( config.altertitle && defined.document && document.title ) { // show ✖ for good, ✔ for bad suite result in title // use escape sequences in case file gets loaded with non-utf-8-charset document.title = [ ( config.stats.bad ? "\u2716" : "\u2714" ), document.title.replace( /^[\u2714\u2716] /i, "" ) ].join( " " ); } // clear own sessionStorage items if all tests passed if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) { // `key` & `i` initialized at top of scope for ( i = 0; i < sessionStorage.length; i++ ) { key = sessionStorage.key( i++ ); if ( key.indexOf( "qunit-test-" ) === 0 ) { sessionStorage.removeItem( key ); } } } // scroll back to top to show results if ( window.scrollTo ) { window.scrollTo(0, 0); } runLoggingCallbacks( "done", QUnit, { failed: config.stats.bad, passed: passed, total: config.stats.all, runtime: runtime }); } /** @return Boolean: true if this test should be ran */ function validTest( test ) { var include, filter = config.filter && config.filter.toLowerCase(), module = config.module && config.module.toLowerCase(), fullName = (test.module + ": " + test.testName).toLowerCase(); // Internally-generated tests are always valid if ( test.callback && test.callback.validTest === validTest ) { delete test.callback.validTest; return true; } if ( config.testNumber ) { return test.testNumber === config.testNumber; } if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) { return false; } if ( !filter ) { return true; } include = filter.charAt( 0 ) !== "!"; if ( !include ) { filter = filter.slice( 1 ); } // If the filter matches, we need to honour include if ( fullName.indexOf( filter ) !== -1 ) { return include; } // Otherwise, do the opposite return !include; } // so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions) // Later Safari and IE10 are supposed to support error.stack as well // See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack function extractStacktrace( e, offset ) { offset = offset === undefined ? 3 : offset; var stack, include, i; if ( e.stacktrace ) { // Opera return e.stacktrace.split( "\n" )[ offset + 3 ]; } else if ( e.stack ) { // Firefox, Chrome stack = e.stack.split( "\n" ); if (/^error$/i.test( stack[0] ) ) { stack.shift(); } if ( fileName ) { include = []; for ( i = offset; i < stack.length; i++ ) { if ( stack[ i ].indexOf( fileName ) !== -1 ) { break; } include.push( stack[ i ] ); } if ( include.length ) { return include.join( "\n" ); } } return stack[ offset ]; } else if ( e.sourceURL ) { // Safari, PhantomJS // hopefully one day Safari provides actual stacktraces // exclude useless self-reference for generated Error objects if ( /qunit.js$/.test( e.sourceURL ) ) { return; } // for actual exceptions, this is useful return e.sourceURL + ":" + e.line; } } function sourceFromStacktrace( offset ) { try { throw new Error(); } catch ( e ) { return extractStacktrace( e, offset ); } } /** * Escape text for attribute or text content. */ function escapeText( s ) { if ( !s ) { return ""; } s = s + ""; // Both single quotes and double quotes (for attributes) return s.replace( /['"<>&]/g, function( s ) { switch( s ) { case "'": return "'"; case "\"": return """; case "<": return "<"; case ">": return ">"; case "&": return "&"; } }); } function synchronize( callback, last ) { config.queue.push( callback ); if ( config.autorun && !config.blocking ) { process( last ); } } function process( last ) { function next() { process( last ); } var start = new Date().getTime(); config.depth = config.depth ? config.depth + 1 : 1; while ( config.queue.length && !config.blocking ) { if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) { config.queue.shift()(); } else { setTimeout( next, 13 ); break; } } config.depth--; if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { done(); } } function saveGlobal() { config.pollution = []; if ( config.noglobals ) { for ( var key in window ) { if ( hasOwn.call( window, key ) ) { // in Opera sometimes DOM element ids show up here, ignore them if ( /^qunit-test-output/.test( key ) ) { continue; } config.pollution.push( key ); } } } } function checkPollution() { var newGlobals, deletedGlobals, old = config.pollution; saveGlobal(); newGlobals = diff( config.pollution, old ); if ( newGlobals.length > 0 ) { QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") ); } deletedGlobals = diff( old, config.pollution ); if ( deletedGlobals.length > 0 ) { QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") ); } } // returns a new Array with the elements that are in a but not in b function diff( a, b ) { var i, j, result = a.slice(); for ( i = 0; i < result.length; i++ ) { for ( j = 0; j < b.length; j++ ) { if ( result[i] === b[j] ) { result.splice( i, 1 ); i--; break; } } } return result; } function extend( a, b ) { for ( var prop in b ) { if ( hasOwn.call( b, prop ) ) { // Avoid "Member not found" error in IE8 caused by messing with window.constructor if ( !( prop === "constructor" && a === window ) ) { if ( b[ prop ] === undefined ) { delete a[ prop ]; } else { a[ prop ] = b[ prop ]; } } } } return a; } /** * @param {HTMLElement} elem * @param {string} type * @param {Function} fn */ function addEvent( elem, type, fn ) { if ( elem.addEventListener ) { // Standards-based browsers elem.addEventListener( type, fn, false ); } else if ( elem.attachEvent ) { // support: IE <9 elem.attachEvent( "on" + type, fn ); } else { // Caller must ensure support for event listeners is present throw new Error( "addEvent() was called in a context without event listener support" ); } } /** * @param {Array|NodeList} elems * @param {string} type * @param {Function} fn */ function addEvents( elems, type, fn ) { var i = elems.length; while ( i-- ) { addEvent( elems[i], type, fn ); } } function hasClass( elem, name ) { return (" " + elem.className + " ").indexOf(" " + name + " ") > -1; } function addClass( elem, name ) { if ( !hasClass( elem, name ) ) { elem.className += (elem.className ? " " : "") + name; } } function removeClass( elem, name ) { var set = " " + elem.className + " "; // Class name may appear multiple times while ( set.indexOf(" " + name + " ") > -1 ) { set = set.replace(" " + name + " " , " "); } // If possible, trim it for prettiness, but not necessarily elem.className = typeof set.trim === "function" ? set.trim() : set.replace(/^\s+|\s+$/g, ""); } function id( name ) { return defined.document && document.getElementById && document.getElementById( name ); } function registerLoggingCallback( key ) { return function( callback ) { config[key].push( callback ); }; } // Supports deprecated method of completely overwriting logging callbacks function runLoggingCallbacks( key, scope, args ) { var i, callbacks; if ( QUnit.hasOwnProperty( key ) ) { QUnit[ key ].call(scope, args ); } else { callbacks = config[ key ]; for ( i = 0; i < callbacks.length; i++ ) { callbacks[ i ].call( scope, args ); } } } // 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; } qunit-1.13.0/src/diff.js000066400000000000000000000061351226204013600147720ustar00rootroot00000000000000/* * Javascript Diff Algorithm * By John Resig (http://ejohn.org/) * Modified by Chu Alan "sprite" * * Released under the MIT license. * * More Info: * http://ejohn.org/projects/javascript-diff-algorithm/ * * Usage: QUnit.diff(expected, actual) * * QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the quick brown fox jumped jumps over" */ QUnit.diff = (function() { /*jshint eqeqeq:false, eqnull:true */ function diff( o, n ) { var i, ns = {}, os = {}; for ( i = 0; i < n.length; i++ ) { if ( !hasOwn.call( ns, n[i] ) ) { ns[ n[i] ] = { rows: [], o: null }; } ns[ n[i] ].rows.push( i ); } for ( i = 0; i < o.length; i++ ) { if ( !hasOwn.call( os, o[i] ) ) { os[ o[i] ] = { rows: [], n: null }; } os[ o[i] ].rows.push( i ); } for ( i in ns ) { if ( hasOwn.call( ns, i ) ) { if ( ns[i].rows.length === 1 && hasOwn.call( os, i ) && os[i].rows.length === 1 ) { n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] }; o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] }; } } } for ( i = 0; i < n.length - 1; i++ ) { if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null && n[ i + 1 ] == o[ n[i].row + 1 ] ) { n[ i + 1 ] = { text: n[ i + 1 ], row: n[i].row + 1 }; o[ n[i].row + 1 ] = { text: o[ n[i].row + 1 ], row: i + 1 }; } } for ( i = n.length - 1; i > 0; i-- ) { if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null && n[ i - 1 ] == o[ n[i].row - 1 ]) { n[ i - 1 ] = { text: n[ i - 1 ], row: n[i].row - 1 }; o[ n[i].row - 1 ] = { text: o[ n[i].row - 1 ], row: i - 1 }; } } return { o: o, n: n }; } return function( o, n ) { o = o.replace( /\s+$/, "" ); n = n.replace( /\s+$/, "" ); var i, pre, str = "", out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ), oSpace = o.match(/\s+/g), nSpace = n.match(/\s+/g); if ( oSpace == null ) { oSpace = [ " " ]; } else { oSpace.push( " " ); } if ( nSpace == null ) { nSpace = [ " " ]; } else { nSpace.push( " " ); } if ( out.n.length === 0 ) { for ( i = 0; i < out.o.length; i++ ) { str += "" + out.o[i] + oSpace[i] + ""; } } else { if ( out.n[0].text == null ) { for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) { str += "" + out.o[n] + oSpace[n] + ""; } } for ( i = 0; i < out.n.length; i++ ) { if (out.n[i].text == null) { str += "" + out.n[i] + nSpace[i] + ""; } else { // `pre` initialized at top of scope pre = ""; for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) { pre += "" + out.o[n] + oSpace[n] + ""; } str += " " + out.n[i].text + nSpace[i] + pre; } } } return str; }; }()); qunit-1.13.0/src/dump.js000066400000000000000000000150631226204013600150270ustar00rootroot00000000000000/** * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | * http://flesler.blogspot.com Licensed under BSD * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008 * * @projectDescription Advanced and extensible data dumping for Javascript. * @version 1.0.0 * @author Ariel Flesler * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} */ QUnit.jsDump = (function() { function quote( str ) { return "\"" + str.toString().replace( /"/g, "\\\"" ) + "\""; } function literal( o ) { return o + ""; } function join( pre, arr, post ) { var s = jsDump.separator(), base = jsDump.indent(), inner = jsDump.indent(1); if ( arr.join ) { arr = arr.join( "," + s + inner ); } if ( !arr ) { return pre + post; } return [ pre, inner + arr, base + post ].join(s); } function array( arr, stack ) { var i = arr.length, ret = new Array(i); this.up(); while ( i-- ) { ret[i] = this.parse( arr[i] , undefined , stack); } this.down(); return join( "[", ret, "]" ); } var reName = /^function (\w+)/, jsDump = { // type is used mostly internally, you can fix a (custom)type in advance parse: function( obj, type, stack ) { stack = stack || [ ]; var inStack, res, parser = this.parsers[ type || this.typeOf(obj) ]; type = typeof parser; inStack = inArray( obj, stack ); if ( inStack !== -1 ) { return "recursion(" + (inStack - stack.length) + ")"; } if ( type === "function" ) { stack.push( obj ); res = parser.call( this, obj, stack ); stack.pop(); return res; } return ( type === "string" ) ? parser : this.parsers.error; }, typeOf: function( obj ) { var type; if ( obj === null ) { type = "null"; } else if ( typeof obj === "undefined" ) { type = "undefined"; } else if ( QUnit.is( "regexp", obj) ) { type = "regexp"; } else if ( QUnit.is( "date", obj) ) { type = "date"; } else if ( QUnit.is( "function", obj) ) { type = "function"; } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) { type = "window"; } else if ( obj.nodeType === 9 ) { type = "document"; } else if ( obj.nodeType ) { type = "node"; } else if ( // native arrays toString.call( obj ) === "[object Array]" || // NodeList objects ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) ) ) { type = "array"; } else if ( obj.constructor === Error.prototype.constructor ) { type = "error"; } else { type = typeof obj; } return type; }, separator: function() { return this.multiline ? this.HTML ? "
      " : "\n" : this.HTML ? " " : " "; }, // extra can be a number, shortcut for increasing-calling-decreasing indent: function( extra ) { if ( !this.multiline ) { return ""; } var chr = this.indentChar; if ( this.HTML ) { chr = chr.replace( /\t/g, " " ).replace( / /g, " " ); } return new Array( this.depth + ( extra || 0 ) ).join(chr); }, up: function( a ) { this.depth += a || 1; }, down: function( a ) { this.depth -= a || 1; }, setParser: function( name, parser ) { this.parsers[name] = parser; }, // The next 3 are exposed so you can use them quote: quote, literal: literal, join: join, // depth: 1, // This is the list of parsers, to modify them, use jsDump.setParser parsers: { window: "[Window]", document: "[Document]", error: function(error) { return "Error(\"" + error.message + "\")"; }, unknown: "[Unknown]", "null": "null", "undefined": "undefined", "function": function( fn ) { var ret = "function", // functions never have name in IE name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1]; if ( name ) { ret += " " + name; } ret += "( "; ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" ); return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" ); }, array: array, nodelist: array, "arguments": array, object: function( map, stack ) { /*jshint forin:false */ var ret = [ ], keys, key, val, i; QUnit.jsDump.up(); keys = []; for ( key in map ) { keys.push( key ); } keys.sort(); for ( i = 0; i < keys.length; i++ ) { key = keys[ i ]; val = map[ key ]; ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) ); } QUnit.jsDump.down(); return join( "{", ret, "}" ); }, node: function( node ) { var len, i, val, open = QUnit.jsDump.HTML ? "<" : "<", close = QUnit.jsDump.HTML ? ">" : ">", tag = node.nodeName.toLowerCase(), ret = open + tag, attrs = node.attributes; if ( attrs ) { for ( i = 0, len = attrs.length; i < len; i++ ) { val = attrs[i].nodeValue; // IE6 includes all attributes in .attributes, even ones not explicitly set. // Those have values like undefined, null, 0, false, "" or "inherit". if ( val && val !== "inherit" ) { ret += " " + attrs[i].nodeName + "=" + QUnit.jsDump.parse( val, "attribute" ); } } } ret += close; // Show content of TextNode or CDATASection if ( node.nodeType === 3 || node.nodeType === 4 ) { ret += node.nodeValue; } return ret + open + "/" + tag + close; }, // function calls it internally, it's the arguments part of the function functionArgs: function( fn ) { var args, l = fn.length; if ( !l ) { return ""; } args = new Array(l); while ( l-- ) { // 97 is 'a' args[l] = String.fromCharCode(97+l); } return " " + args.join( ", " ) + " "; }, // object calls it internally, the key part of an item in a map key: quote, // function calls it internally, it's the content of the function functionCode: "[code]", // node calls it internally, it's an html attribute value attribute: quote, string: quote, date: quote, regexp: literal, number: literal, "boolean": literal }, // if true, entities are escaped ( <, >, \t, space and \n ) HTML: false, // indentation unit indentChar: " ", // if true, items in a collection, are separated by a \n, else just a space. multiline: true }; return jsDump; }()); qunit-1.13.0/src/equiv.js000066400000000000000000000127161226204013600152150ustar00rootroot00000000000000// Test for equality any JavaScript type. // Author: Philippe Rathé QUnit.equiv = (function() { // Call the o related callback with the given arguments. function bindCallbacks( o, callbacks, args ) { var prop = QUnit.objectType( o ); if ( prop ) { if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) { return callbacks[ prop ].apply( callbacks, args ); } else { return callbacks[ prop ]; // or undefined } } } // the real equiv function var innerEquiv, // stack to decide between skip/abort functions callers = [], // stack to avoiding loops from circular referencing parents = [], parentsB = [], getProto = Object.getPrototypeOf || function ( obj ) { /*jshint camelcase:false */ return obj.__proto__; }, callbacks = (function () { // for string, boolean, number and null function useStrictEquality( b, a ) { /*jshint eqeqeq:false */ if ( b instanceof a.constructor || a instanceof b.constructor ) { // to catch short annotation VS 'new' annotation of a // declaration // e.g. var i = 1; // var j = new Number(1); return a == b; } else { return a === b; } } return { "string": useStrictEquality, "boolean": useStrictEquality, "number": useStrictEquality, "null": useStrictEquality, "undefined": useStrictEquality, "nan": function( b ) { return isNaN( b ); }, "date": function( b, a ) { return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf(); }, "regexp": function( b, a ) { return QUnit.objectType( b ) === "regexp" && // the regex itself a.source === b.source && // and its modifiers a.global === b.global && // (gmi) ... a.ignoreCase === b.ignoreCase && a.multiline === b.multiline && a.sticky === b.sticky; }, // - skip when the property is a method of an instance (OOP) // - abort otherwise, // initial === would have catch identical references anyway "function": function() { var caller = callers[callers.length - 1]; return caller !== Object && typeof caller !== "undefined"; }, "array": function( b, a ) { var i, j, len, loop, aCircular, bCircular; // b could be an object literal here if ( QUnit.objectType( b ) !== "array" ) { return false; } len = a.length; if ( len !== b.length ) { // safe and faster return false; } // track reference to avoid circular references parents.push( a ); parentsB.push( b ); for ( i = 0; i < len; i++ ) { loop = false; for ( j = 0; j < parents.length; j++ ) { aCircular = parents[j] === a[i]; bCircular = parentsB[j] === b[i]; if ( aCircular || bCircular ) { if ( a[i] === b[i] || aCircular && bCircular ) { loop = true; } else { parents.pop(); parentsB.pop(); return false; } } } if ( !loop && !innerEquiv(a[i], b[i]) ) { parents.pop(); parentsB.pop(); return false; } } parents.pop(); parentsB.pop(); return true; }, "object": function( b, a ) { /*jshint forin:false */ var i, j, loop, aCircular, bCircular, // Default to true eq = true, aProperties = [], bProperties = []; // comparing constructors is more strict than using // instanceof if ( a.constructor !== b.constructor ) { // Allow objects with no prototype to be equivalent to // objects with Object as their constructor. if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) || ( getProto(b) === null && getProto(a) === Object.prototype ) ) ) { return false; } } // stack constructor before traversing properties callers.push( a.constructor ); // track reference to avoid circular references parents.push( a ); parentsB.push( b ); // be strict: don't ensure hasOwnProperty and go deep for ( i in a ) { loop = false; for ( j = 0; j < parents.length; j++ ) { aCircular = parents[j] === a[i]; bCircular = parentsB[j] === b[i]; if ( aCircular || bCircular ) { if ( a[i] === b[i] || aCircular && bCircular ) { loop = true; } else { eq = false; break; } } } aProperties.push(i); if ( !loop && !innerEquiv(a[i], b[i]) ) { eq = false; break; } } parents.pop(); parentsB.pop(); callers.pop(); // unstack, we are done for ( i in b ) { bProperties.push( i ); // collect b's properties } // Ensures identical properties name return eq && innerEquiv( aProperties.sort(), bProperties.sort() ); } }; }()); innerEquiv = function() { // can take multiple arguments var args = [].slice.apply( arguments ); if ( args.length < 2 ) { return true; // end transition } return (function( a, b ) { if ( a === b ) { return true; // catch the most you can } else if ( a === null || b === null || typeof a === "undefined" || typeof b === "undefined" || QUnit.objectType(a) !== QUnit.objectType(b) ) { return false; // don't lose time with error prone cases } else { return bindCallbacks(a, callbacks, [ b, a ]); } // apply transition with (1..n) arguments }( args[0], args[1] ) && innerEquiv.apply( this, args.splice(1, args.length - 1 )) ); }; return innerEquiv; }()); qunit-1.13.0/src/export.js000066400000000000000000000004401226204013600153740ustar00rootroot00000000000000// For browser, export only select globals if ( typeof window !== "undefined" ) { extend( window, QUnit.constructor.prototype ); window.QUnit = QUnit; } // For CommonJS environments, export everything if ( typeof module !== "undefined" && module.exports ) { module.exports = QUnit; } qunit-1.13.0/src/intro.js000066400000000000000000000003271226204013600152120ustar00rootroot00000000000000/*! * QUnit @VERSION * http://qunitjs.com/ * * Copyright 2013 jQuery Foundation and other contributors * Released under the MIT license * http://jquery.org/license * * Date: @DATE */ (function( window ) { qunit-1.13.0/src/outro.js000066400000000000000000000001521226204013600152230ustar00rootroot00000000000000 // Get a reference to the global object, like window in browsers }( (function() { return this; })() )); qunit-1.13.0/src/qunit.css000066400000000000000000000110461226204013600153730ustar00rootroot00000000000000/*! * QUnit @VERSION * http://qunitjs.com/ * * Copyright 2013 jQuery Foundation and other contributors * Released under the MIT license * http://jquery.org/license * * Date: @DATE */ /** Font Family and Sizes */ #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; } #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } #qunit-tests { font-size: smaller; } /** Resets */ #qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter { margin: 0; padding: 0; } /** Header */ #qunit-header { padding: 0.5em 0 0.5em 1em; color: #8699a4; background-color: #0d3349; font-size: 1.5em; line-height: 1em; font-weight: normal; border-radius: 5px 5px 0 0; -moz-border-radius: 5px 5px 0 0; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px; } #qunit-header a { text-decoration: none; color: #c2ccd1; } #qunit-header a:hover, #qunit-header a:focus { color: #fff; } #qunit-testrunner-toolbar label { display: inline-block; padding: 0 .5em 0 .1em; } #qunit-banner { height: 5px; } #qunit-testrunner-toolbar { padding: 0.5em 0 0.5em 2em; color: #5E740B; background-color: #eee; overflow: hidden; } #qunit-userAgent { padding: 0.5em 0 0.5em 2.5em; background-color: #2b81af; color: #fff; text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; } #qunit-modulefilter-container { float: right; } /** Tests: Pass/Fail */ #qunit-tests { list-style-position: inside; } #qunit-tests li { padding: 0.4em 0.5em 0.4em 2.5em; border-bottom: 1px solid #fff; list-style-position: inside; } #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { display: none; } #qunit-tests li strong { cursor: pointer; } #qunit-tests li a { padding: 0.5em; color: #c2ccd1; text-decoration: none; } #qunit-tests li a:hover, #qunit-tests li a:focus { color: #000; } #qunit-tests li .runtime { float: right; font-size: smaller; } .qunit-assert-list { margin-top: 0.5em; padding: 0.5em; background-color: #fff; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; } .qunit-collapsed { display: none; } #qunit-tests table { border-collapse: collapse; margin-top: .2em; } #qunit-tests th { text-align: right; vertical-align: top; padding: 0 .5em 0 0; } #qunit-tests td { vertical-align: top; } #qunit-tests pre { margin: 0; white-space: pre-wrap; word-wrap: break-word; } #qunit-tests del { background-color: #e0f2be; color: #374e0c; text-decoration: none; } #qunit-tests ins { background-color: #ffcaca; color: #500; text-decoration: none; } /*** Test Counts */ #qunit-tests b.counts { color: black; } #qunit-tests b.passed { color: #5E740B; } #qunit-tests b.failed { color: #710909; } #qunit-tests li li { padding: 5px; background-color: #fff; border-bottom: none; list-style-position: inside; } /*** Passing Styles */ #qunit-tests li li.pass { color: #3c510c; background-color: #fff; border-left: 10px solid #C6E746; } #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } #qunit-tests .pass .test-name { color: #366097; } #qunit-tests .pass .test-actual, #qunit-tests .pass .test-expected { color: #999999; } #qunit-banner.qunit-pass { background-color: #C6E746; } /*** Failing Styles */ #qunit-tests li li.fail { color: #710909; background-color: #fff; border-left: 10px solid #EE5757; white-space: pre; } #qunit-tests > li:last-child { border-radius: 0 0 5px 5px; -moz-border-radius: 0 0 5px 5px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px; } #qunit-tests .fail { color: #000000; background-color: #EE5757; } #qunit-tests .fail .test-name, #qunit-tests .fail .module-name { color: #000000; } #qunit-tests .fail .test-actual { color: #EE5757; } #qunit-tests .fail .test-expected { color: green; } #qunit-banner.qunit-fail { background-color: #EE5757; } /** Result */ #qunit-testresult { padding: 0.5em 0.5em 0.5em 2.5em; color: #2b81af; background-color: #D2E0E6; border-bottom: 1px solid white; } #qunit-testresult .module-name { font-weight: bold; } /** Fixture */ #qunit-fixture { position: absolute; top: -10000px; left: -10000px; width: 1000px; height: 1000px; } qunit-1.13.0/src/test.js000066400000000000000000000203451226204013600150400ustar00rootroot00000000000000function 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:
      " + 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 + " (" + bad + ", " + good + ", " + this.assertions.length + ")"; 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 ); } } }; qunit-1.13.0/test/000077500000000000000000000000001226204013600137075ustar00rootroot00000000000000qunit-1.13.0/test/.jshintrc000066400000000000000000000006601226204013600155360ustar00rootroot00000000000000{ "predef": [ "QUnit", "module", "test", "asyncTest", "expect", "start", "stop", "raises" ], "bitwise": true, "camelcase": true, "curly": true, "eqeqeq": true, "forin": true, "immed": true, "latedef": false, "newcap": true, "noarg": true, "noempty": true, "nonew": true, "plusplus": false, "quotmark": false, "undef": true, "unused": true, "trailing": true, "browser": true, "onevar": false } qunit-1.13.0/test/async.html000066400000000000000000000012441226204013600157130ustar00rootroot00000000000000 QUnit Async Test Suite
      test markup
      qunit-1.13.0/test/async.js000066400000000000000000000001331226204013600153570ustar00rootroot00000000000000QUnit.start(); test("just a test", function( assert ) { expect(1); assert.ok(true); }); qunit-1.13.0/test/deepEqual.js000066400000000000000000001232671226204013600161650ustar00rootroot00000000000000QUnit.module("equiv"); test("Primitive types and constants", function ( assert ) { assert.equal(QUnit.equiv(null, null), true, "null"); assert.equal(QUnit.equiv(null, {}), false, "null"); assert.equal(QUnit.equiv(null, undefined), false, "null"); assert.equal(QUnit.equiv(null, 0), false, "null"); assert.equal(QUnit.equiv(null, false), false, "null"); assert.equal(QUnit.equiv(null, ''), false, "null"); assert.equal(QUnit.equiv(null, []), false, "null"); assert.equal(QUnit.equiv(undefined, undefined), true, "undefined"); assert.equal(QUnit.equiv(undefined, null), false, "undefined"); assert.equal(QUnit.equiv(undefined, 0), false, "undefined"); assert.equal(QUnit.equiv(undefined, false), false, "undefined"); assert.equal(QUnit.equiv(undefined, {}), false, "undefined"); assert.equal(QUnit.equiv(undefined, []), false, "undefined"); assert.equal(QUnit.equiv(undefined, ""), false, "undefined"); // Nan usually doest not equal to Nan using the '==' operator. // Only isNaN() is able to do it. assert.equal(QUnit.equiv(0/0, 0/0), true, "NaN"); // NaN VS NaN assert.equal(QUnit.equiv(1/0, 2/0), true, "Infinity"); // Infinity VS Infinity assert.equal(QUnit.equiv(-1/0, 2/0), false, "-Infinity, Infinity"); // -Infinity VS Infinity assert.equal(QUnit.equiv(-1/0, -2/0), true, "-Infinity, -Infinity"); // -Infinity VS -Infinity assert.equal(QUnit.equiv(0/0, 1/0), false, "NaN, Infinity"); // Nan VS Infinity assert.equal(QUnit.equiv(1/0, 0/0), false, "NaN, Infinity"); // Nan VS Infinity assert.equal(QUnit.equiv(0/0, null), false, "NaN"); assert.equal(QUnit.equiv(0/0, undefined), false, "NaN"); assert.equal(QUnit.equiv(0/0, 0), false, "NaN"); assert.equal(QUnit.equiv(0/0, false), false, "NaN"); assert.equal(QUnit.equiv(0/0, function () {}), false, "NaN"); assert.equal(QUnit.equiv(1/0, null), false, "NaN, Infinity"); assert.equal(QUnit.equiv(1/0, undefined), false, "NaN, Infinity"); assert.equal(QUnit.equiv(1/0, 0), false, "NaN, Infinity"); assert.equal(QUnit.equiv(1/0, 1), false, "NaN, Infinity"); assert.equal(QUnit.equiv(1/0, false), false, "NaN, Infinity"); assert.equal(QUnit.equiv(1/0, true), false, "NaN, Infinity"); assert.equal(QUnit.equiv(1/0, function () {}), false, "NaN, Infinity"); assert.equal(QUnit.equiv(0, 0), true, "number"); assert.equal(QUnit.equiv(0, 1), false, "number"); assert.equal(QUnit.equiv(1, 0), false, "number"); assert.equal(QUnit.equiv(1, 1), true, "number"); assert.equal(QUnit.equiv(1.1, 1.1), true, "number"); assert.equal(QUnit.equiv(0.0000005, 0.0000005), true, "number"); assert.equal(QUnit.equiv(0, ''), false, "number"); assert.equal(QUnit.equiv(0, '0'), false, "number"); assert.equal(QUnit.equiv(1, '1'), false, "number"); assert.equal(QUnit.equiv(0, false), false, "number"); assert.equal(QUnit.equiv(1, true), false, "number"); assert.equal(QUnit.equiv(true, true), true, "boolean"); assert.equal(QUnit.equiv(true, false), false, "boolean"); assert.equal(QUnit.equiv(false, true), false, "boolean"); assert.equal(QUnit.equiv(false, 0), false, "boolean"); assert.equal(QUnit.equiv(false, null), false, "boolean"); assert.equal(QUnit.equiv(false, undefined), false, "boolean"); assert.equal(QUnit.equiv(true, 1), false, "boolean"); assert.equal(QUnit.equiv(true, null), false, "boolean"); assert.equal(QUnit.equiv(true, undefined), false, "boolean"); assert.equal(QUnit.equiv('', ''), true, "string"); assert.equal(QUnit.equiv('a', 'a'), true, "string"); assert.equal(QUnit.equiv("foobar", "foobar"), true, "string"); assert.equal(QUnit.equiv("foobar", "foo"), false, "string"); assert.equal(QUnit.equiv('', 0), false, "string"); assert.equal(QUnit.equiv('', false), false, "string"); assert.equal(QUnit.equiv('', null), false, "string"); assert.equal(QUnit.equiv('', undefined), false, "string"); // Rename for lint validation. // We know this is bad, we are asserting whether we can coop with bad code like this. var SafeNumber = Number, SafeString = String, SafeBoolean = Boolean, SafeObject = Object; // primitives vs. objects assert.equal(QUnit.equiv(0, new SafeNumber()), true, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeNumber(), 0), true, "primitives vs. objects"); assert.equal(QUnit.equiv(1, new SafeNumber(1)), true, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeNumber(1), 1), true, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeNumber(0), 1), false, "primitives vs. objects"); assert.equal(QUnit.equiv(0, new SafeNumber(1)), false, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeString(), ""), true, "primitives vs. objects"); assert.equal(QUnit.equiv("", new SafeString()), true, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeString("My String"), "My String"), true, "primitives vs. objects"); assert.equal(QUnit.equiv("My String", new SafeString("My String")), true, "primitives vs. objects"); assert.equal(QUnit.equiv("Bad String", new SafeString("My String")), false, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeString("Bad String"), "My String"), false, "primitives vs. objects"); assert.equal(QUnit.equiv(false, new SafeBoolean()), true, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeBoolean(), false), true, "primitives vs. objects"); assert.equal(QUnit.equiv(true, new SafeBoolean(true)), true, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeBoolean(true), true), true, "primitives vs. objects"); assert.equal(QUnit.equiv(true, new SafeBoolean(1)), true, "primitives vs. objects"); assert.equal(QUnit.equiv(false, new SafeBoolean(false)), true, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeBoolean(false), false), true, "primitives vs. objects"); assert.equal(QUnit.equiv(false, new SafeBoolean(0)), true, "primitives vs. objects"); assert.equal(QUnit.equiv(true, new SafeBoolean(false)), false, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeBoolean(false), true), false, "primitives vs. objects"); assert.equal(QUnit.equiv(new SafeObject(), {}), true, "object literal vs. instantiation"); assert.equal(QUnit.equiv({}, new SafeObject()), true, "object literal vs. instantiation"); assert.equal(QUnit.equiv(new SafeObject(), {a:1}), false, "object literal vs. instantiation"); assert.equal(QUnit.equiv({a:1}, new SafeObject()), false, "object literal vs. instantiation"); assert.equal(QUnit.equiv({a:undefined}, new SafeObject()), false, "object literal vs. instantiation"); assert.equal(QUnit.equiv(new SafeObject(), {a:undefined}), false, "object literal vs. instantiation"); }); test("Objects basics", function( assert ) { assert.equal(QUnit.equiv({}, {}), true); assert.equal(QUnit.equiv({}, null), false); assert.equal(QUnit.equiv({}, undefined), false); assert.equal(QUnit.equiv({}, 0), false); assert.equal(QUnit.equiv({}, false), false); // This test is a hard one, it is very important // REASONS: // 1) They are of the same type "object" // 2) [] instanceof Object is true // 3) Their properties are the same (doesn't exists) assert.equal(QUnit.equiv({}, []), false); assert.equal(QUnit.equiv({a:1}, {a:1}), true); assert.equal(QUnit.equiv({a:1}, {a:"1"}), false); assert.equal(QUnit.equiv({a:[]}, {a:[]}), true); assert.equal(QUnit.equiv({a:{}}, {a:null}), false); assert.equal(QUnit.equiv({a:1}, {}), false); assert.equal(QUnit.equiv({}, {a:1}), false); // Hard ones assert.equal(QUnit.equiv({a:undefined}, {}), false); assert.equal(QUnit.equiv({}, {a:undefined}), false); assert.equal(QUnit.equiv( { a: [{ bar: undefined }] }, { a: [{ bat: undefined }] } ), false); // Objects with no prototype, created via Object.create(null), are used e.g. as dictionaries. // Being able to test equivalence against object literals is quite useful. if (typeof Object.create === 'function') { assert.equal(QUnit.equiv(Object.create(null), {}), true, "empty object without prototype VS empty object"); var nonEmptyWithNoProto = Object.create(null); nonEmptyWithNoProto.foo = "bar"; assert.equal(QUnit.equiv(nonEmptyWithNoProto, { foo: "bar" }), true, "object without prototype VS object"); } }); test("Arrays basics", function( assert ) { assert.equal(QUnit.equiv([], []), true); // May be a hard one, can invoke a crash at execution. // because their types are both "object" but null isn't // like a true object, it doesn't have any property at all. assert.equal(QUnit.equiv([], null), false); assert.equal(QUnit.equiv([], undefined), false); assert.equal(QUnit.equiv([], false), false); assert.equal(QUnit.equiv([], 0), false); assert.equal(QUnit.equiv([], ""), false); // May be a hard one, but less hard // than {} with [] (note the order) assert.equal(QUnit.equiv([], {}), false); assert.equal(QUnit.equiv([null],[]), false); assert.equal(QUnit.equiv([undefined],[]), false); assert.equal(QUnit.equiv([],[null]), false); assert.equal(QUnit.equiv([],[undefined]), false); assert.equal(QUnit.equiv([null],[undefined]), false); assert.equal(QUnit.equiv([[]],[[]]), true); assert.equal(QUnit.equiv([[],[],[]],[[],[],[]]), true); assert.equal(QUnit.equiv( [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), true); assert.equal(QUnit.equiv( [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // shorter false); assert.equal(QUnit.equiv( [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // deepest element not an array false); // same multidimensional assert.equal(QUnit.equiv( [1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,[ [6,7,8,9, [ [ 1,2,3,4,[ 2,3,4,[ 1,2,[ 1,2,3,4,[ 1,2,3,4,5,6,7,8,9,[ 0 ],1,2,3,4,5,6,7,8,9 ],5,6,7,8,9 ],4,5,6,7,8,9 ],5,6,7,8,9 ],5,6,7 ] ] ] ] ]]], [1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,[ [6,7,8,9, [ [ 1,2,3,4,[ 2,3,4,[ 1,2,[ 1,2,3,4,[ 1,2,3,4,5,6,7,8,9,[ 0 ],1,2,3,4,5,6,7,8,9 ],5,6,7,8,9 ],4,5,6,7,8,9 ],5,6,7,8,9 ],5,6,7 ] ] ] ] ]]]), true, "Multidimensional"); // different multidimensional assert.equal(QUnit.equiv( [1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,[ [6,7,8,9, [ [ 1,2,3,4,[ 2,3,4,[ 1,2,[ 1,2,3,4,[ 1,2,3,4,5,6,7,8,9,[ 0 ],1,2,3,4,5,6,7,8,9 ],5,6,7,8,9 ],4,5,6,7,8,9 ],5,6,7,8,9 ],5,6,7 ] ] ] ] ]]], [1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,[ [6,7,8,9, [ [ 1,2,3,4,[ 2,3,4,[ 1,2,[ '1',2,3,4,[ // string instead of number 1,2,3,4,5,6,7,8,9,[ 0 ],1,2,3,4,5,6,7,8,9 ],5,6,7,8,9 ],4,5,6,7,8,9 ],5,6,7,8,9 ],5,6,7 ] ] ] ] ]]]), false, "Multidimensional"); // different multidimensional assert.equal(QUnit.equiv( [1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,[ [6,7,8,9, [ [ 1,2,3,4,[ 2,3,4,[ 1,2,[ 1,2,3,4,[ 1,2,3,4,5,6,7,8,9,[ 0 ],1,2,3,4,5,6,7,8,9 ],5,6,7,8,9 ],4,5,6,7,8,9 ],5,6,7,8,9 ],5,6,7 ] ] ] ] ]]], [1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,6,7,8,9, [ 1,2,3,4,5,[ [6,7,8,9, [ [ 1,2,3,4,[ 2,3,[ // missing an element (4) 1,2,[ 1,2,3,4,[ 1,2,3,4,5,6,7,8,9,[ 0 ],1,2,3,4,5,6,7,8,9 ],5,6,7,8,9 ],4,5,6,7,8,9 ],5,6,7,8,9 ],5,6,7 ] ] ] ] ]]]), false, "Multidimensional"); }); test("Functions", function( assert ) { var f0 = function () {}; var f1 = function () {}; // f2 and f3 have the same code, formatted differently var f2 = function () {return 0;}; var f3 = function () { /*jshint asi:true */ return 0 // this comment and no semicoma as difference }; assert.equal(QUnit.equiv(function() {}, function() {}), false, "Anonymous functions"); // exact source code assert.equal(QUnit.equiv(function() {}, function() {return true;}), false, "Anonymous functions"); assert.equal(QUnit.equiv(f0, f0), true, "Function references"); // same references assert.equal(QUnit.equiv(f0, f1), false, "Function references"); // exact source code, different references assert.equal(QUnit.equiv(f2, f3), false, "Function references"); // equivalent source code, different references assert.equal(QUnit.equiv(f1, f2), false, "Function references"); // different source code, different references assert.equal(QUnit.equiv(function() {}, true), false); assert.equal(QUnit.equiv(function() {}, undefined), false); assert.equal(QUnit.equiv(function() {}, null), false); assert.equal(QUnit.equiv(function() {}, {}), false); }); test("Date instances", function( assert ) { // Date, we don't need to test Date.parse() because it returns a number. // Only test the Date instances by setting them a fix date. // The date use is midnight January 1, 1970 var d1 = new Date(); d1.setTime(0); // fix the date var d2 = new Date(); d2.setTime(0); // fix the date var d3 = new Date(); // The very now // Anyway their types differs, just in case the code fails in the order in which it deals with date assert.equal(QUnit.equiv(d1, 0), false); // d1.valueOf() returns 0, but d1 and 0 are different // test same values date and different instances equality assert.equal(QUnit.equiv(d1, d2), true); // test different date and different instances difference assert.equal(QUnit.equiv(d1, d3), false); }); test("RegExp", function( assert ) { // Must test cases that imply those traps: // var a = /./; // a instanceof Object; // Oops // a instanceof RegExp; // Oops // typeof a === "function"; // Oops, false in IE and Opera, true in FF and Safari ("object") // Tests same regex with same modifiers in different order var r = /foo/; var r5 = /foo/gim; var r6 = /foo/gmi; var r7 = /foo/igm; var r8 = /foo/img; var r9 = /foo/mig; var r10 = /foo/mgi; var ri1 = /foo/i; var ri2 = /foo/i; var rm1 = /foo/m; var rm2 = /foo/m; var rg1 = /foo/g; var rg2 = /foo/g; assert.equal(QUnit.equiv(r5, r6), true, "Modifier order"); assert.equal(QUnit.equiv(r5, r7), true, "Modifier order"); assert.equal(QUnit.equiv(r5, r8), true, "Modifier order"); assert.equal(QUnit.equiv(r5, r9), true, "Modifier order"); assert.equal(QUnit.equiv(r5, r10), true, "Modifier order"); assert.equal(QUnit.equiv(r, r5), false, "Modifier"); assert.equal(QUnit.equiv(ri1, ri2), true, "Modifier"); assert.equal(QUnit.equiv(r, ri1), false, "Modifier"); assert.equal(QUnit.equiv(ri1, rm1), false, "Modifier"); assert.equal(QUnit.equiv(r, rm1), false, "Modifier"); assert.equal(QUnit.equiv(rm1, ri1), false, "Modifier"); assert.equal(QUnit.equiv(rm1, rm2), true, "Modifier"); assert.equal(QUnit.equiv(rg1, rm1), false, "Modifier"); assert.equal(QUnit.equiv(rm1, rg1), false, "Modifier"); assert.equal(QUnit.equiv(rg1, rg2), true, "Modifier"); // Different regex, same modifiers var r11 = /[a-z]/gi; var r13 = /[0-9]/gi; // oops! different assert.equal(QUnit.equiv(r11, r13), false, "Regex pattern"); var r14 = /0/ig; var r15 = /"0"/ig; // oops! different assert.equal(QUnit.equiv(r14, r15), false, "Regex pattern"); var r1 = /[\n\r\u2028\u2029]/g; var r2 = /[\n\r\u2028\u2029]/g; var r3 = /[\n\r\u2028\u2028]/g; // differs from r1 var r4 = /[\n\r\u2028\u2029]/; // differs from r1 assert.equal(QUnit.equiv(r1, r2), true, "Regex pattern"); assert.equal(QUnit.equiv(r1, r3), false, "Regex pattern"); assert.equal(QUnit.equiv(r1, r4), false, "Regex pattern"); // More complex regex var regex1 = "^[-_.a-z0-9]+@([-_a-z0-9]+\\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; var regex2 = "^[-_.a-z0-9]+@([-_a-z0-9]+\\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; // regex 3 is different: '.' not escaped var regex3 = "^[-_.a-z0-9]+@([-_a-z0-9]+.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; var r21 = new RegExp(regex1); var r22 = new RegExp(regex2); var r23 = new RegExp(regex3); // diff from r21, not same pattern var r23a = new RegExp(regex3, "gi"); // diff from r23, not same modifier var r24a = new RegExp(regex3, "ig"); // same as r23a assert.equal(QUnit.equiv(r21, r22), true, "Complex Regex"); assert.equal(QUnit.equiv(r21, r23), false, "Complex Regex"); assert.equal(QUnit.equiv(r23, r23a), false, "Complex Regex"); assert.equal(QUnit.equiv(r23a, r24a), true, "Complex Regex"); // typeof r1 is "function" in some browsers and "object" in others so we must cover this test var re = / /; assert.equal(QUnit.equiv(re, function () {}), false, "Regex internal"); assert.equal(QUnit.equiv(re, {}), false, "Regex internal"); }); test("Complex objects", function( assert ) { function fn1() { return "fn1"; } function fn2() { return "fn2"; } // Try to invert the order of some properties to make sure it is covered. // It can failed when properties are compared between unsorted arrays. assert.equal(QUnit.equiv( { a: 1, b: null, c: [{}], d: { a: 3.14159, b: false, c: { e: fn1, f: [[[]]], g: { j: { k: { n: { r: "r", s: [1,2,3], t: undefined, u: 0, v: { w: { x: { y: "Yahoo!", z: null } } } }, q: [], p: 1/0, o: 99 }, l: undefined, m: null } }, d: 0, i: true, h: "false" } }, e: undefined, g: "", h: "h", f: {}, i: [] }, { a: 1, b: null, c: [{}], d: { b: false, a: 3.14159, c: { d: 0, e: fn1, f: [[[]]], g: { j: { k: { n: { r: "r", t: undefined, u: 0, s: [1,2,3], v: { w: { x: { z: null, y: "Yahoo!" } } } }, o: 99, p: 1/0, q: [] }, l: undefined, m: null } }, i: true, h: "false" } }, e: undefined, g: "", f: {}, h: "h", i: [] } ), true); assert.equal(QUnit.equiv( { a: 1, b: null, c: [{}], d: { a: 3.14159, b: false, c: { d: 0, e: fn1, f: [[[]]], g: { j: { k: { n: { //r: "r", // different: missing a property s: [1,2,3], t: undefined, u: 0, v: { w: { x: { y: "Yahoo!", z: null } } } }, o: 99, p: 1/0, q: [] }, l: undefined, m: null } }, h: "false", i: true } }, e: undefined, f: {}, g: "", h: "h", i: [] }, { a: 1, b: null, c: [{}], d: { a: 3.14159, b: false, c: { d: 0, e: fn1, f: [[[]]], g: { j: { k: { n: { r: "r", s: [1,2,3], t: undefined, u: 0, v: { w: { x: { y: "Yahoo!", z: null } } } }, o: 99, p: 1/0, q: [] }, l: undefined, m: null } }, h: "false", i: true } }, e: undefined, f: {}, g: "", h: "h", i: [] } ), false); assert.equal(QUnit.equiv( { a: 1, b: null, c: [{}], d: { a: 3.14159, b: false, c: { d: 0, e: fn1, f: [[[]]], g: { j: { k: { n: { r: "r", s: [1,2,3], t: undefined, u: 0, v: { w: { x: { y: "Yahoo!", z: null } } } }, o: 99, p: 1/0, q: [] }, l: undefined, m: null } }, h: "false", i: true } }, e: undefined, f: {}, g: "", h: "h", i: [] }, { a: 1, b: null, c: [{}], d: { a: 3.14159, b: false, c: { d: 0, e: fn1, f: [[[]]], g: { j: { k: { n: { r: "r", s: [1,2,3], //t: undefined, // different: missing a property with an undefined value u: 0, v: { w: { x: { y: "Yahoo!", z: null } } } }, o: 99, p: 1/0, q: [] }, l: undefined, m: null } }, h: "false", i: true } }, e: undefined, f: {}, g: "", h: "h", i: [] } ), false); assert.equal(QUnit.equiv( { a: 1, b: null, c: [{}], d: { a: 3.14159, b: false, c: { d: 0, e: fn1, f: [[[]]], g: { j: { k: { n: { r: "r", s: [1,2,3], t: undefined, u: 0, v: { w: { x: { y: "Yahoo!", z: null } } } }, o: 99, p: 1/0, q: [] }, l: undefined, m: null } }, h: "false", i: true } }, e: undefined, f: {}, g: "", h: "h", i: [] }, { a: 1, b: null, c: [{}], d: { a: 3.14159, b: false, c: { d: 0, e: fn1, f: [[[]]], g: { j: { k: { n: { r: "r", s: [1,2,3], t: undefined, u: 0, v: { w: { x: { y: "Yahoo!", z: null } } } }, o: 99, p: 1/0, q: {} // different was [] }, l: undefined, m: null } }, h: "false", i: true } }, e: undefined, f: {}, g: "", h: "h", i: [] } ), false); var same1 = { a: [ "string", null, 0, "1", 1, { prop: null, foo: [1,2,null,{}, [], [1,2,3]], bar: undefined }, 3, "Hey!", "Κάνε πάντα γνωÏίζουμε ας των, μηχανής επιδιόÏθωσης επιδιοÏθώσεις ÏŽÏ‚ μια. Κλπ ας" ], unicode: "è€ æ±‰è¯ä¸å˜åœ¨ 港澳和海外的åŽäººåœˆä¸ 贵州 我去了书店 现在尚有争", b: "b", c: fn1 }; var same2 = { a: [ "string", null, 0, "1", 1, { prop: null, foo: [1,2,null,{}, [], [1,2,3]], bar: undefined }, 3, "Hey!", "Κάνε πάντα γνωÏίζουμε ας των, μηχανής επιδιόÏθωσης επιδιοÏθώσεις ÏŽÏ‚ μια. Κλπ ας" ], unicode: "è€ æ±‰è¯ä¸å˜åœ¨ 港澳和海外的åŽäººåœˆä¸ 贵州 我去了书店 现在尚有争", b: "b", c: fn1 }; var diff1 = { a: [ "string", null, 0, "1", 1, { prop: null, foo: [1,2,null,{}, [], [1,2,3,4]], // different: 4 was add to the array bar: undefined }, 3, "Hey!", "Κάνε πάντα γνωÏίζουμε ας των, μηχανής επιδιόÏθωσης επιδιοÏθώσεις ÏŽÏ‚ μια. Κλπ ας" ], unicode: "è€ æ±‰è¯ä¸å˜åœ¨ 港澳和海外的åŽäººåœˆä¸ 贵州 我去了书店 现在尚有争", b: "b", c: fn1 }; var diff2 = { a: [ "string", null, 0, "1", 1, { prop: null, foo: [1,2,null,{}, [], [1,2,3]], newprop: undefined, // different: newprop was added bar: undefined }, 3, "Hey!", "Κάνε πάντα γνωÏίζουμε ας των, μηχανής επιδιόÏθωσης επιδιοÏθώσεις ÏŽÏ‚ μια. Κλπ ας" ], unicode: "è€ æ±‰è¯ä¸å˜åœ¨ 港澳和海外的åŽäººåœˆä¸ 贵州 我去了书店 现在尚有争", b: "b", c: fn1 }; var diff3 = { a: [ "string", null, 0, "1", 1, { prop: null, foo: [1,2,null,{}, [], [1,2,3]], bar: undefined }, 3, "Hey!", "Κάνε πάντα γνωÏίζουμε ας των, μηχανής επιδιόÏθωσης επιδιοÏθώσεις ÏŽÏ‚ μια. Κλπ α" // different: missing last char ], unicode: "è€ æ±‰è¯ä¸å˜åœ¨ 港澳和海外的åŽäººåœˆä¸ 贵州 我去了书店 现在尚有争", b: "b", c: fn1 }; var diff4 = { a: [ "string", null, 0, "1", 1, { prop: null, foo: [1,2,undefined,{}, [], [1,2,3]], // different: undefined instead of null bar: undefined }, 3, "Hey!", "Κάνε πάντα γνωÏίζουμε ας των, μηχανής επιδιόÏθωσης επιδιοÏθώσεις ÏŽÏ‚ μια. Κλπ ας" ], unicode: "è€ æ±‰è¯ä¸å˜åœ¨ 港澳和海外的åŽäººåœˆä¸ 贵州 我去了书店 现在尚有争", b: "b", c: fn1 }; var diff5 = { a: [ "string", null, 0, "1", 1, { prop: null, foo: [1,2,null,{}, [], [1,2,3]], bat: undefined // different: property name not "bar" }, 3, "Hey!", "Κάνε πάντα γνωÏίζουμε ας των, μηχανής επιδιόÏθωσης επιδιοÏθώσεις ÏŽÏ‚ μια. Κλπ ας" ], unicode: "è€ æ±‰è¯ä¸å˜åœ¨ 港澳和海外的åŽäººåœˆä¸ 贵州 我去了书店 现在尚有争", b: "b", c: fn1 }; var diff6 = { a: [ "string", null, 0, "1", 1, { prop: null, foo: [1,2,null,{}, [], [1,2,3]], bar: undefined }, 3, "Hey!", "Κάνε πάντα γνωÏίζουμε ας των, μηχανής επιδιόÏθωσης επιδιοÏθώσεις ÏŽÏ‚ μια. Κλπ ας" ], unicode: "è€ æ±‰è¯ä¸å˜åœ¨ 港澳和海外的åŽäººåœˆä¸ 贵州 我去了书店 现在尚有争", b: "b", c: fn2 // different: fn2 instead of fn1 }; assert.equal(QUnit.equiv(same1, same2), true); assert.equal(QUnit.equiv(same2, same1), true); assert.equal(QUnit.equiv(same2, diff1), false); assert.equal(QUnit.equiv(diff1, same2), false); assert.equal(QUnit.equiv(same1, diff1), false); assert.equal(QUnit.equiv(same1, diff2), false); assert.equal(QUnit.equiv(same1, diff3), false); assert.equal(QUnit.equiv(same1, diff3), false); assert.equal(QUnit.equiv(same1, diff4), false); assert.equal(QUnit.equiv(same1, diff5), false); assert.equal(QUnit.equiv(same1, diff6), false); assert.equal(QUnit.equiv(diff5, diff1), false); }); test("Complex Arrays", function( assert ) { function fn() { } assert.equal(QUnit.equiv( [1, 2, 3, true, {}, null, [ { a: ["", '1', 0] }, 5, 6, 7 ], "foo"], [1, 2, 3, true, {}, null, [ { a: ["", '1', 0] }, 5, 6, 7 ], "foo"]), true); assert.equal(QUnit.equiv( [1, 2, 3, true, {}, null, [ { a: ["", '1', 0] }, 5, 6, 7 ], "foo"], [1, 2, 3, true, {}, null, [ { b: ["", '1', 0] // not same property name }, 5, 6, 7 ], "foo"]), false); var a = [{ b: fn, c: false, "do": "reserved word", "for": { ar: [3,5,9,"hey!", [], { ar: [1,[ 3,4,6,9, null, [], [] ]], e: fn, f: undefined }] }, e: 0.43445 }, 5, "string", 0, fn, false, null, undefined, 0, [ 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 ], [], [[[], "foo", null, { n: 1/0, z: { a: [3,4,5,6,"yep!", undefined, undefined], b: {} } }, {}]]]; assert.equal(QUnit.equiv(a, [{ b: fn, c: false, "do": "reserved word", "for": { ar: [3,5,9,"hey!", [], { ar: [1,[ 3,4,6,9, null, [], [] ]], e: fn, f: undefined }] }, e: 0.43445 }, 5, "string", 0, fn, false, null, undefined, 0, [ 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 ], [], [[[], "foo", null, { n: 1/0, z: { a: [3,4,5,6,"yep!", undefined, undefined], b: {} } }, {}]]]), true); assert.equal(QUnit.equiv(a, [{ b: fn, c: false, "do": "reserved word", "for": { ar: [3,5,9,"hey!", [], { ar: [1,[ 3,4,6,9, null, [], [] ]], e: fn, f: undefined }] }, e: 0.43445 }, 5, "string", 0, fn, false, null, undefined, 0, [ 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[2]]]], "3"], {}, 1/0 // different: [[[[[2]]]]] instead of [[[[[3]]]]] ], [], [[[], "foo", null, { n: 1/0, z: { a: [3,4,5,6,"yep!", undefined, undefined], b: {} } }, {}]]]), false); assert.equal(QUnit.equiv(a, [{ b: fn, c: false, "do": "reserved word", "for": { ar: [3,5,9,"hey!", [], { ar: [1,[ 3,4,6,9, null, [], [] ]], e: fn, f: undefined }] }, e: 0.43445 }, 5, "string", 0, fn, false, null, undefined, 0, [ 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 ], [], [[[], "foo", null, { n: -1/0, // different, -Infinity instead of Infinity z: { a: [3,4,5,6,"yep!", undefined, undefined], b: {} } }, {}]]]), false); assert.equal(QUnit.equiv(a, [{ b: fn, c: false, "do": "reserved word", "for": { ar: [3,5,9,"hey!", [], { ar: [1,[ 3,4,6,9, null, [], [] ]], e: fn, f: undefined }] }, e: 0.43445 }, 5, "string", 0, fn, false, null, undefined, 0, [ 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 ], [], [[[], "foo", { // different: null is missing n: 1/0, z: { a: [3,4,5,6,"yep!", undefined, undefined], b: {} } }, {}]]]), false); assert.equal(QUnit.equiv(a, [{ b: fn, c: false, "do": "reserved word", "for": { ar: [3,5,9,"hey!", [], { ar: [1,[ 3,4,6,9, null, [], [] ]], e: fn // different: missing property f: undefined }] }, e: 0.43445 }, 5, "string", 0, fn, false, null, undefined, 0, [ 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 ], [], [[[], "foo", null, { n: 1/0, z: { a: [3,4,5,6,"yep!", undefined, undefined], b: {} } }, {}]]]), false); }); test("Prototypal inheritance", function( assert ) { function Gizmo(id) { this.id = id; } function Hoozit(id) { this.id = id; } Hoozit.prototype = new Gizmo(); var gizmo = new Gizmo("ok"); var hoozit = new Hoozit("ok"); // Try this test many times after test on instances that hold function // to make sure that our code does not mess with last object constructor memoization. assert.equal(QUnit.equiv(function () {}, function () {}), false); // Hoozit inherit from Gizmo // hoozit instanceof Hoozit; // true // hoozit instanceof Gizmo; // true assert.equal(QUnit.equiv(hoozit, gizmo), true); Gizmo.prototype.bar = true; // not a function just in case we skip them // Hoozit inherit from Gizmo // They are equivalent assert.equal(QUnit.equiv(hoozit, gizmo), true); // Make sure this is still true !important // The reason for this is that I forgot to reset the last // caller to where it were called from. assert.equal(QUnit.equiv(function () {}, function () {}), false); // Make sure this is still true !important assert.equal(QUnit.equiv(hoozit, gizmo), true); Hoozit.prototype.foo = true; // not a function just in case we skip them // Gizmo does not inherit from Hoozit // gizmo instanceof Gizmo; // true // gizmo instanceof Hoozit; // false // They are not equivalent assert.equal(QUnit.equiv(hoozit, gizmo), false); // Make sure this is still true !important assert.equal(QUnit.equiv(function () {}, function () {}), false); }); test("Instances", function( assert ) { function A() {} var a1 = new A(); var a2 = new A(); function B() { this.fn = function () {}; } var b1 = new B(); var b2 = new B(); assert.equal(QUnit.equiv(a1, a2), true, "Same property, same constructor"); // b1.fn and b2.fn are functions but they are different references // But we decided to skip function for instances. assert.equal(QUnit.equiv(b1, b2), true, "Same property, same constructor"); assert.equal(QUnit.equiv(a1, b1), false, "Same properties but different constructor"); // failed function Car(year) { var privateVar = 0; this.year = year; this.isOld = function() { return privateVar > 10; }; } function Human(year) { var privateVar = 1; this.year = year; this.isOld = function() { return privateVar > 80; }; } var car = new Car(30); var carSame = new Car(30); var carDiff = new Car(10); var human = new Human(30); /** * difference: * - year: 30 * same: * - year: 30, * - isOld: function () {} */ assert.equal(QUnit.equiv(car, car), true); assert.equal(QUnit.equiv(car, carDiff), false); assert.equal(QUnit.equiv(car, carSame), true); assert.equal(QUnit.equiv(car, human), false); }); test("Complex instance nesting (with function values in literals and/or in nested instances)", function( assert ) { function A(fn) { this.a = {}; this.fn = fn; this.b = {a: []}; this.o = {}; this.fn1 = fn; } function B(fn) { this.fn = fn; this.fn1 = function () {}; this.a = new A(function () {}); } function fnOutside() { } function C(fn) { function fnInside() { } this.x = 10; this.fn = fn; this.fn1 = function () {}; this.fn2 = fnInside; this.fn3 = { a: true, b: fnOutside // ok make reference to a function in all instances scope }; this.o1 = {}; // This function will be ignored. // Even if it is not visible for all instances (e.g. locked in a closures), // it is from a property that makes part of an instance (e.g. from the C constructor) this.b1 = new B(function () {}); this.b2 = new B({ x: { b2: new B(function() {}) } }); } function D(fn) { function fnInside() { } this.x = 10; this.fn = fn; this.fn1 = function () {}; this.fn2 = fnInside; this.fn3 = { a: true, b: fnOutside, // ok make reference to a function in all instances scope // This function won't be ingored. // It isn't visible for all C instances // and it is not in a property of an instance. (in an Object instances e.g. the object literal) c: fnInside }; this.o1 = {}; // This function will be ignored. // Even if it is not visible for all instances (e.g. locked in a closures), // it is from a property that makes part of an instance (e.g. from the C constructor) this.b1 = new B(function () {}); this.b2 = new B({ x: { b2: new B(function() {}) } }); } function E(fn) { function fnInside() { } this.x = 10; this.fn = fn; this.fn1 = function () {}; this.fn2 = fnInside; this.fn3 = { a: true, b: fnOutside // ok make reference to a function in all instances scope }; this.o1 = {}; // This function will be ignored. // Even if it is not visible for all instances (e.g. locked in a closures), // it is from a property that makes part of an instance (e.g. from the C constructor) this.b1 = new B(function () {}); this.b2 = new B({ x: { b1: new B({a: function() {}}), b2: new B(function() {}) } }); } var a1 = new A(function () {}); var a2 = new A(function () {}); assert.equal(QUnit.equiv(a1, a2), true); assert.equal(QUnit.equiv(a1, a2), true); // different instances var b1 = new B(function () {}); var b2 = new B(function () {}); assert.equal(QUnit.equiv(b1, b2), true); var c1 = new C(function () {}); var c2 = new C(function () {}); assert.equal(QUnit.equiv(c1, c2), true); var d1 = new D(function () {}); var d2 = new D(function () {}); assert.equal(QUnit.equiv(d1, d2), false); var e1 = new E(function () {}); var e2 = new E(function () {}); assert.equal(QUnit.equiv(e1, e2), false); }); test("Object with circular references", function( assert ) { var circularA = { abc: null }, circularB = { abc: null }; circularA.abc = circularA; circularB.abc = circularB; assert.equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambiguous test)"); circularA.def = 1; circularB.def = 1; assert.equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambiguous test)"); circularA.def = 1; circularB.def = 0; assert.equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object (unambiguous test)"); }); test("Array with circular references", function( assert ) { var circularA = [], circularB = []; circularA.push(circularA); circularB.push(circularB); assert.equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambiguous test)"); circularA.push( "abc" ); circularB.push( "abc" ); assert.equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambiguous test)"); circularA.push( "hello" ); circularB.push( "goodbye" ); assert.equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on array (unambiguous test)"); }); test("Mixed object/array with references to self wont loop", function( assert ) { var circularA = [{abc:null}], circularB = [{abc:null}]; circularA[0].abc = circularA; circularB[0].abc = circularB; circularA.push(circularA); circularB.push(circularB); assert.equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambiguous test)"); circularA[0].def = 1; circularB[0].def = 1; assert.equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambiguous test)"); circularA[0].def = 1; circularB[0].def = 0; assert.equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object/array (unambiguous test)"); }); test("Compare self-referent to tree", function ( assert ) { var temp, circularA = [0], treeA = [0, null], circularO = {}, treeO = { o: null }; circularA[1] = circularA; circularO.o = circularO; assert.equal(QUnit.equiv(circularA, treeA), false, "Array: Should not consider circular equal to tree"); assert.equal(QUnit.equiv(circularO, treeO), false, "Object: Should not consider circular equal to tree"); temp = [ 0, circularA ]; assert.equal(QUnit.equiv(circularA, temp), true, "Array: Reference is circular for one, but equal on other"); assert.equal(QUnit.equiv(temp, circularA), true, "Array: Reference is circular for one, but equal on other"); temp = { o: circularO }; assert.equal(QUnit.equiv(circularO, temp), true, "Object: Reference is circular for one, but equal on other"); assert.equal(QUnit.equiv(temp, circularO), true, "Object: Reference is circular for one, but equal on other"); }); test("Test that must be done at the end because they extend some primitive's prototype", function( assert ) { // Try that a function looks like our regular expression. // This tests if we check that a and b are really both instance of RegExp Function.prototype.global = true; Function.prototype.multiline = true; Function.prototype.ignoreCase = false; Function.prototype.source = "my regex"; var re = /my regex/gm; assert.equal(QUnit.equiv(re, function () {}), false, "A function that looks that a regex isn't a regex"); // This test will ensures it works in both ways, and ALSO especially that we can make differences // between RegExp and Function constructor because typeof on a RegExpt instance is "function" assert.equal(QUnit.equiv(function () {}, re), false, "Same conversely, but ensures that function and regexp are distinct because their constructor are different"); }); qunit-1.13.0/test/headless.html000066400000000000000000000012411226204013600163630ustar00rootroot00000000000000 QUnit Headless Test Suite
      test markup
      qunit-1.13.0/test/index.html000066400000000000000000000006111226204013600157020ustar00rootroot00000000000000 QUnit Main Test Suite
      test markup
      qunit-1.13.0/test/logs.html000066400000000000000000000005571226204013600155500ustar00rootroot00000000000000 QUnit Logs Test Suite
      test markup
      qunit-1.13.0/test/logs.js000066400000000000000000000114701226204013600152140ustar00rootroot00000000000000// TODO disable reordering for this suite! var begin = 0, moduleStart = 0, moduleDone = 0, testStart = 0, testDone = 0, log = 0, moduleContext, moduleDoneContext, testContext, testDoneContext, logContext; QUnit.begin(function() { begin++; }); QUnit.done(function() { }); QUnit.moduleStart(function(context) { moduleStart++; moduleContext = context; }); QUnit.moduleDone(function(context) { moduleDone++; moduleDoneContext = context; }); QUnit.testStart(function(context) { testStart++; testContext = context; }); QUnit.testDone(function(context) { testDone++; testDoneContext = context; }); QUnit.log(function(context) { log++; logContext = context; }); QUnit.module("logs1"); test("test1", function( assert ) { expect( 15 ); assert.equal( begin, 1, "QUnit.begin calls" ); assert.equal( moduleStart, 1, "QUnit.moduleStart calls" ); assert.equal( testStart, 1, "QUnit.testStart calls" ); assert.equal( testDone, 0, "QUnit.testDone calls" ); assert.equal( moduleDone, 0, "QUnit.moduleDone calls" ); assert.deepEqual( logContext, { name: "test1", module: "logs1", result: true, message: "QUnit.moduleDone calls", actual: 0, expected: 0 }, "log context after equal(actual, expected, message)" ); assert.equal( "foo", "foo" ); assert.deepEqual(logContext, { name: "test1", module: "logs1", result: true, message: undefined, actual: "foo", expected: "foo" }, "log context after equal(actual, expected)" ); assert.ok( true, "ok(true, message)" ); assert.deepEqual( logContext, { module: "logs1", name: "test1", result: true, message: "ok(true, message)" }, "log context after ok(true, message)" ); assert.strictEqual( testDoneContext, undefined, "testDone context" ); assert.deepEqual( testContext, { module: "logs1", name: "test1" }, "test context" ); assert.strictEqual( moduleDoneContext, undefined, "moduleDone context" ); assert.deepEqual( moduleContext, { name: "logs1" }, "module context" ); assert.equal( log, 14, "QUnit.log calls" ); }); test("test2", function( assert ) { expect( 11 ); assert.equal( begin, 1, "QUnit.begin calls" ); assert.equal( moduleStart, 1, "QUnit.moduleStart calls" ); assert.equal( testStart, 2, "QUnit.testStart calls" ); assert.equal( testDone, 1, "QUnit.testDone calls" ); assert.equal( moduleDone, 0, "QUnit.moduleDone calls" ); assert.equal( typeof testDoneContext.runtime, "number" , "testDone context: runtime" ); delete testDoneContext.runtime; // DEPRECATED: remove this delete when removing the duration property delete testDoneContext.duration; assert.deepEqual( testDoneContext, { module: "logs1", name: "test1", failed: 0, passed: 15, total: 15 }, "testDone context" ); assert.deepEqual( testContext, { module: "logs1", name: "test2" }, "test context" ); assert.strictEqual( moduleDoneContext, undefined, "moduleDone context" ); assert.deepEqual( moduleContext, { name: "logs1" }, "module context" ); assert.equal( log, 25, "QUnit.log calls" ); }); QUnit.module("logs2"); test( "test1", function( assert ) { expect( 9 ); assert.equal( begin, 1, "QUnit.begin calls" ); assert.equal( moduleStart, 2, "QUnit.moduleStart calls" ); assert.equal( testStart, 3, "QUnit.testStart calls" ); assert.equal( testDone, 2, "QUnit.testDone calls" ); assert.equal( moduleDone, 1, "QUnit.moduleDone calls" ); assert.deepEqual( testContext, { module: "logs2", name: "test1" }, "test context" ); assert.deepEqual( moduleDoneContext, { name: "logs1", failed: 0, passed: 26, total: 26 }, "moduleDone context" ); assert.deepEqual( moduleContext, { name: "logs2" }, "module context" ); assert.equal( log, 34, "QUnit.log calls" ); }); test( "test2", function( assert ) { expect( 8 ); assert.equal( begin, 1, "QUnit.begin calls" ); assert.equal( moduleStart, 2, "QUnit.moduleStart calls" ); assert.equal( testStart, 4, "QUnit.testStart calls" ); assert.equal( testDone, 3, "QUnit.testDone calls" ); assert.equal( moduleDone, 1, "QUnit.moduleDone calls" ); assert.deepEqual( testContext, { module: "logs2", name: "test2" }, "test context" ); assert.deepEqual( moduleContext, { name: "logs2" }, "module context" ); assert.equal( log, 42, "QUnit.log calls" ); }); var testAutorun = true; QUnit.done(function() { if ( !testAutorun ) { return; } testAutorun = false; moduleStart = moduleDone = 0; // Since these tests run *after* done, and as such // QUnit is not able to know whether more tests are coming // the module starts/ends after each test. QUnit.module( "autorun" ); setTimeout(function() { test( "first", function( assert ) { assert.equal( moduleStart, 1, "test started" ); assert.equal( moduleDone, 0, "test in progress" ); }); test( "second", function( assert ) { assert.equal( moduleStart, 2, "test started" ); assert.equal( moduleDone, 1, "test in progress" ); }); }, 5000 ); }); qunit-1.13.0/test/narwhal-test.js000066400000000000000000000012421226204013600166550ustar00rootroot00000000000000/*jshint node:true, undef:false */ /*globals QUnit:true */ // Run with: $ narwhal test/narwhal-test.js var QUnit = require("../dist/qunit"); QUnit.log(function(details) { if (!details.result) { var output = "FAILED: " + (details.message ? details.message + ", " : ""); if (details.actual) { output += "expected: " + details.expected + ", actual: " + details.actual; } if (details.source) { output += ", " + details.source; } print(output); } }); QUnit.test("fail twice with stacktrace", function(assert) { /*jshint expr:true */ assert.equal(true, false); assert.equal(true, false, "gotta fail"); // Throws ReferenceError x.y.z; }); QUnit.load(); qunit-1.13.0/test/node-test.js000066400000000000000000000012421226204013600161460ustar00rootroot00000000000000/*jshint node:true, undef:false */ /*globals QUnit:true */ // Run with: $ node test/node-test.js var QUnit = require("../dist/qunit"); QUnit.log(function(details) { if (!details.result) { var output = "FAILED: " + (details.message ? details.message + ", " : ""); if (details.actual) { output += "expected: " + details.expected + ", actual: " + details.actual; } if (details.source) { output += ", " + details.source; } console.log(output); } }); QUnit.test("fail twice with stacktrace", function(assert) { /*jshint expr:true */ assert.equal(true, false); assert.equal(true, false, "gotta fail"); // Throws ReferenceError x.y.z; }); QUnit.load(); qunit-1.13.0/test/setTimeout.html000066400000000000000000000005241226204013600167400ustar00rootroot00000000000000 QUnit Fake setTimeout Test Suite
      qunit-1.13.0/test/setTimeout.js000066400000000000000000000005641226204013600164140ustar00rootroot00000000000000QUnit.config.updateRate = 1; module( "Module that mucks with time", { setup: function() { this.setTimeout = window.setTimeout; window.setTimeout = function() {}; }, teardown: function() { window.setTimeout = this.setTimeout; } }); test( "just a test", function( assert ) { assert.ok(true); }); test( "just a test", function( assert ) { assert.ok(true); }); qunit-1.13.0/test/swarminject.js000077500000000000000000000005471226204013600166040ustar00rootroot00000000000000// load testswarm agent (function() { var url = window.location.search; url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); if ( !url || url.indexOf("http") !== 0 ) { return; } /*jshint evil:true */ document.write(""); })(); qunit-1.13.0/test/test.js000066400000000000000000000470051226204013600152320ustar00rootroot00000000000000(function( window ) { function getPreviousTests( rTestName, rModuleName ) { var testSpan, moduleSpan, matches = [], i = 0, rModule = /(^| )module-name( |$)/, testNames = typeof document.getElementsByClassName !== "undefined" ? document.getElementsByClassName("test-name") : (function( spans ) { var span, tests = [], i = 0, rTest = /(^| )test-name( |$)/; for ( ; (span = spans[i]); i++ ) { if ( rTest.test( span.className ) ) { tests.push( span ); } } return tests; })( document.getElementsByTagName("span") ); for ( ; (testSpan = testNames[i]); i++ ) { moduleSpan = testSpan; while ( (moduleSpan = moduleSpan.previousSibling) ) { if ( rModule.test( moduleSpan.className ) ) { break; } } if ( (!rTestName || rTestName.test( testSpan.innerHTML )) && (!rModuleName || moduleSpan && rModuleName.test( moduleSpan.innerHTML )) ) { while ( (testSpan = testSpan.parentNode) ) { if ( testSpan.nodeName.toLowerCase() === "li" ) { matches.push( testSpan ); } } } } return matches; } test("module without setup/teardown (default)", function( assert ) { expect(1); assert.ok(true); }); test("expect in test", function( assert ) { expect( 3 ); assert.ok(true); assert.ok(true); assert.ok(true); }); test("expect in test", function( assert ) { expect( 1 ); assert.ok(true); }); test("expect query and multiple issue", function( assert ) { expect(2); assert.ok(true); var expected = expect(); assert.equal(expected, 2); expect(expected + 1); assert.ok(true); }); QUnit.module( "assertion helpers" ); QUnit.test( "QUnit.assert compatibility", function( assert ) { expect( 5 ); assert.ok( true, "Calling method on `assert` argument to test() callback" ); // Should also work, although discouraged and not documented QUnit.assert.ok( true, "Calling method on QUnit.assert object" ); // Test compatibility aliases QUnit.ok( true, "Calling aliased method in QUnit root object" ); assert.ok( true, "Calling aliased function in global namespace" ); // Regression fix for #341 // The assert-context way of testing discouraged global variables, // it doesn't make sense of it itself to be a global variable. // Only allows for mistakes (e.g. forgetting to list 'assert' as parameter) assert.notStrictEqual( window.assert, QUnit.assert, "Assert does not get exposed as a global variable" ); }); QUnit.module( "setup test", { setup: function( assert ) { assert.ok(true); } }); test("module with setup", function( assert ) { expect(2); assert.ok(true); }); test("module with setup, expect in test call", function( assert ) { expect( 2 ); assert.ok(true); }); // TODO: More to the html-reporter test once we have that. if ( typeof document !== "undefined" ) { QUnit.module( "", { setup: function() { }, teardown: function( assert ) { // We can't use ok(false) inside script tags since some browsers // don't evaluate script tags inserted through innerHTML after domready. // Counting them before/after doesn't cover everything either as qunit-modulefilter // is created before any test is ran. So use ids instead. if ( document.getElementById( "qunit-unescaped-module" ) ) { // This can either be from in #qunit-modulefilter or #qunit-testresult assert.ok( false, "Unescaped module name" ); } if ( document.getElementById( "qunit-unescaped-test" ) ) { assert.ok( false, "Unescaped test name" ); } if ( document.getElementById( "qunit-unescaped-assertion" ) ) { assert.ok( false, "Unescaped test name" ); } } }); test( "", function( assert ) { expect( 1 ); assert.ok( true, "" ); }); } var state; QUnit.module( "setup/teardown test", { setup: function( assert ) { state = true; assert.ok(true); // Assert that we can introduce and delete globals in setup/teardown // without noglobals sounding any alarm. // Using an implied global variable instead of explicit window property // because there is no way to delete a window.property in IE6-8 // `delete x` only works for `x = 1, and `delete window.x` throws exception. // No one-code fits all solution possible afaic. Resort to @cc. /*@cc_on @if (@_jscript_version < 9) x = 1; @else @*/ window.x = 1; /*@end @*/ }, teardown: function( assert ) { assert.ok(true); /*@cc_on @if (@_jscript_version < 9) delete x; @else @*/ delete window.x; /*@end @*/ } }); test("module with setup/teardown", function( assert ) { expect(3); assert.ok(true); }); QUnit.module( "setup/teardown test 2" ); test("module without setup/teardown", function( assert ) { expect(1); assert.ok(true); }); var OrgDate; QUnit.module( "Date test", { setup: function( assert ) { OrgDate = Date; window.Date = function () { assert.ok( false, 'QUnit should internally be independent from Date-related manipulation and testing' ); return new OrgDate(); }; }, teardown: function() { window.Date = OrgDate; } }); test("sample test for Date test", function ( assert ) { expect(1); assert.ok(true); }); if (typeof setTimeout !== 'undefined') { state = 'fail'; QUnit.module( "teardown and stop", { teardown: function( assert ) { assert.equal(state, "done", "Test teardown."); } }); test("teardown must be called after test ended", function() { expect(1); stop(); setTimeout(function() { state = "done"; start(); }, 13); }); test("parameter passed to stop increments semaphore n times", function() { expect(1); stop(3); setTimeout(function() { state = "not enough starts"; start(); start(); }, 13); setTimeout(function() { state = "done"; start(); }, 15); }); test("parameter passed to start decrements semaphore n times", function() { expect(1); stop(); stop(); stop(); setTimeout(function() { state = "done"; start(3); }, 18); }); QUnit.module( "async setup test", { setup: function( assert ) { stop(); setTimeout(function() { assert.ok(true); start(); }, 500); } }); asyncTest("module with async setup", function( assert ) { expect(2); assert.ok(true); start(); }); QUnit.module( "async teardown test", { teardown: function( assert ) { stop(); setTimeout(function() { assert.ok(true); start(); }, 500); } }); asyncTest("module with async teardown", function( assert ) { expect(2); assert.ok(true); start(); }); QUnit.module( "asyncTest" ); asyncTest("asyncTest", function( assert ) { expect( 2 ); assert.ok(true); setTimeout(function() { state = "done"; assert.ok(true); start(); }, 13); }); asyncTest("asyncTest with expect()", function( assert ) { expect(2); assert.ok(true); setTimeout(function() { state = "done"; assert.ok(true); start(); }, 13); }); test("sync", function( assert ) { expect( 2 ); stop(); setTimeout(function() { assert.ok(true); start(); }, 13); stop(); setTimeout(function() { assert.ok(true); start(); }, 125); }); test("test synchronous calls to stop", function( assert ) { expect( 2 ); stop(); setTimeout(function() { assert.ok(true, 'first'); start(); stop(); setTimeout(function() { assert.ok(true, 'second'); start(); }, 150); }, 150); }); } QUnit.module( "save scope", { setup: function() { this.foo = "bar"; }, teardown: function( assert ) { assert.deepEqual(this.foo, "bar"); } }); test("scope check", function( assert ) { expect(2); assert.deepEqual(this.foo, "bar"); }); QUnit.module( "simple testEnvironment setup", { foo: "bar", // example of meta-data bugid: "#5311" }); test("scope check", function( assert ) { assert.deepEqual(this.foo, "bar"); }); test("modify testEnvironment", function() { expect(0); this.foo = "hamster"; }); test("testEnvironment reset for next test", function( assert ) { assert.deepEqual(this.foo, "bar"); }); QUnit.module( "testEnvironment with object", { options: { recipe: "soup", ingredients: ["hamster", "onions"] } }); test("scope check", function( assert ) { assert.deepEqual(this.options, { recipe: "soup", ingredients: ["hamster", "onions"] }); }); test("modify testEnvironment",function() { expect(0); // since we only do a shallow copy, nested children of testEnvironment can be modified // and survice this.options.ingredients.push("carrots"); }); test("testEnvironment reset for next test",function( assert ) { assert.deepEqual(this.options, { recipe: "soup", ingredients: ["hamster", "onions", "carrots"] }, "Is this a bug or a feature? Could do a deep copy") ; }); QUnit.module( "testEnvironment tests" ); function makeurl() { var testEnv = QUnit.config.current.testEnvironment; var url = testEnv.url || 'http://example.com/search'; var q = testEnv.q || 'a search test'; return url + '?q='+encodeURIComponent(q); } test("makeurl working", function( assert ) { expect( 2 ); assert.equal( QUnit.config.current.testEnvironment, this, 'The current testEnvironment QUnit.config'); assert.equal( makeurl(), 'http://example.com/search?q=a%20search%20test', 'makeurl returns a default url if nothing specified in the testEnvironment'); }); QUnit.module( "testEnvironment with makeurl settings", { url: 'http://google.com/', q: 'another_search_test' }); test("makeurl working with settings from testEnvironment", function( assert ) { assert.equal( makeurl(), 'http://google.com/?q=another_search_test', 'rather than passing arguments, we use test metadata to from the url'); }); QUnit.module( "jsDump" ); test("jsDump output", function( assert ) { assert.equal( QUnit.jsDump.parse([1, 2]), "[\n 1,\n 2\n]" ); assert.equal( QUnit.jsDump.parse({top: 5, left: 0}), "{\n \"left\": 0,\n \"top\": 5\n}" ); if (typeof document !== 'undefined' && document.getElementById("qunit-header")) { assert.equal( QUnit.jsDump.parse(document.getElementById("qunit-header")), "

      " ); assert.equal( QUnit.jsDump.parse(document.getElementsByTagName("h1")), "[\n

      \n]" ); } }); QUnit.module( "assertions" ); test("propEqual", function( assert ) { expect( 5 ); var objectCreate = Object.create || function ( origin ) { function O() {} O.prototype = origin; var r = new O(); return r; }; function Foo( x, y, z ) { this.x = x; this.y = y; this.z = z; } Foo.prototype.doA = function () {}; Foo.prototype.doB = function () {}; Foo.prototype.bar = 'prototype'; function Bar() { } Bar.prototype = objectCreate( Foo.prototype ); Bar.prototype.constructor = Bar; assert.propEqual( new Foo( 1, '2', [] ), { x: 1, y: '2', z: [] } ); assert.notPropEqual( new Foo( '1', 2, 3 ), { x: 1, y: '2', z: 3 }, 'Primitive values are strictly compared' ); assert.notPropEqual( new Foo( 1, '2', [] ), { x: 1, y: '2', z: {} }, 'Array type is preserved' ); assert.notPropEqual( new Foo( 1, '2', {} ), { x: 1, y: '2', z: [] }, 'Empty array is not the same as empty object' ); assert.propEqual( new Foo( 1, '2', new Foo( [ 3 ], new Bar(), null ) ), { x: 1, y: '2', z: { x: [ 3 ], y: {}, z: null } }, 'Complex nesting of different types, inheritance and constructors' ); }); test("throws", function( assert ) { expect(8); function CustomError( message ) { this.message = message; } CustomError.prototype.toString = function() { return this.message; }; assert.throws( function() { throw "my error"; } ); assert.throws( function() { throw "my error"; }, "simple string throw, no 'expected' value given" ); // This test is for IE 7 and prior which does not properly // implement Error.prototype.toString assert.throws( function() { throw new Error("error message"); }, /error message/, "use regexp against instance of Error" ); assert.throws( function() { throw new CustomError(); }, CustomError, 'thrown error is an instance of CustomError' ); assert.throws( function() { throw new CustomError("some error description"); }, /description/, "use a regex to match against the stringified error" ); assert.throws( function() { throw new CustomError("some error description"); }, function( err ) { if ( (err instanceof CustomError) && /description/.test(err) ) { return true; } }, "custom validation function" ); assert.throws( function() { /*jshint evil:true */ ( window.execScript || function( data ) { window["eval"].call( window, data ); })( "throw 'error';" ); }, 'globally-executed errors caught' ); this.CustomError = CustomError; assert.throws( function() { throw new this.CustomError("some error description"); }, /description/, "throw error from property of 'this' context" ); }); if (typeof document !== "undefined") { QUnit.module( "fixture" ); test("setup", function() { expect(0); document.getElementById("qunit-fixture").innerHTML = "foobar"; }); test("basics", function( assert ) { assert.equal( document.getElementById("qunit-fixture").innerHTML, "test markup", "automatically reset" ); }); test("running test name displayed", function( assert ) { expect(2); var displaying = document.getElementById("qunit-testresult"); assert.ok( /running test name displayed/.test(displaying.innerHTML), "Expect test name to be found in displayed text" ); assert.ok( /fixture/.test(displaying.innerHTML), "Expect module name to be found in displayed text" ); }); (function() { var delayNextSetup, sleep = function( n ) { stop(); setTimeout( function() { start(); }, n ); }; QUnit.module( "timing", { setup: function() { if ( delayNextSetup ) { delayNextSetup = false; sleep( 250 ); } } }); test("setup", function() { expect( 0 ); delayNextSetup = true; }); test("basics", function( assert ) { expect( 2 ); var previous = getPreviousTests(/^setup$/, /^timing$/)[0], runtime = previous.lastChild.previousSibling; assert.ok( /(^| )runtime( |$)/.test( runtime.className ), "Runtime element exists" ); assert.ok( /^\d+ ms$/.test( runtime.innerHTML ), "Runtime reported in ms" ); }); test("values", function( assert ) { expect( 2 ); var basics = getPreviousTests(/^setup$/, /^timing$/)[0], slow = getPreviousTests(/^basics$/, /^timing$/)[0]; assert.ok( parseInt( basics.lastChild.previousSibling.innerHTML, 10 ) < 50, "Fast runtime for trivial test" ); assert.ok( parseInt( slow.lastChild.previousSibling.innerHTML, 10 ) > 250, "Runtime includes setup" ); }); })(); } QUnit.module( "custom assertions" ); (function() { QUnit.assert.mod2 = function( value, expected, message ) { var actual = value % 2; QUnit.push(actual === expected, actual, expected, message); }; test("mod2", function( assert ) { expect( 2 ); assert.mod2(2, 0, "2 % 2 == 0"); assert.mod2(3, 1, "3 % 2 == 1"); }); })(); QUnit.module( "recursions" ); function Wrap(x) { this.wrap = x; if (x === undefined) { this.first = true; } } function chainwrap(depth, first, prev) { depth = depth || 0; var last = prev || new Wrap(); first = first || last; if (depth === 1) { first.wrap = last; } if (depth > 1) { last = chainwrap(depth-1, first, new Wrap(last)); } return last; } test("Check jsDump recursion", function( assert ) { expect(4); var noref = chainwrap(0); var nodump = QUnit.jsDump.parse(noref); assert.equal(nodump, '{\n "first": true,\n "wrap": undefined\n}'); var selfref = chainwrap(1); var selfdump = QUnit.jsDump.parse(selfref); assert.equal(selfdump, '{\n "first": true,\n "wrap": recursion(-1)\n}'); var parentref = chainwrap(2); var parentdump = QUnit.jsDump.parse(parentref); assert.equal(parentdump, '{\n "wrap": {\n "first": true,\n "wrap": recursion(-2)\n }\n}'); var circref = chainwrap(10); var circdump = QUnit.jsDump.parse(circref); assert.ok(new RegExp("recursion\\(-10\\)").test(circdump), "(" +circdump + ") should show -10 recursion level"); }); test("Check equal/deepEqual recursion", function( assert ) { var noRecursion = chainwrap(0); assert.equal(noRecursion, noRecursion, "I should be equal to me."); assert.deepEqual(noRecursion, noRecursion, "... and so in depth."); var selfref = chainwrap(1); assert.equal(selfref, selfref, "Even so if I nest myself."); assert.deepEqual(selfref, selfref, "... into the depth."); var circref = chainwrap(10); assert.equal(circref, circref, "Or hide that through some levels of indirection."); assert.deepEqual(circref, circref, "... and checked on all levels!"); }); test("Circular reference with arrays", function( assert ) { // pure array self-ref var arr = []; arr.push(arr); var arrdump = QUnit.jsDump.parse(arr); assert.equal(arrdump, '[\n recursion(-1)\n]'); assert.equal(arr, arr[0], 'no endless stack when trying to dump arrays with circular ref'); // mix obj-arr circular ref var obj = {}; var childarr = [obj]; obj.childarr = childarr; var objdump = QUnit.jsDump.parse(obj); var childarrdump = QUnit.jsDump.parse(childarr); assert.equal(objdump, '{\n "childarr": [\n recursion(-2)\n ]\n}'); assert.equal(childarrdump, '[\n {\n "childarr": recursion(-2)\n }\n]'); assert.equal(obj.childarr, childarr, 'no endless stack when trying to dump array/object mix with circular ref'); assert.equal(childarr[0], obj, 'no endless stack when trying to dump array/object mix with circular ref'); }); test("Circular reference - test reported by soniciq in #105", function( assert ) { var MyObject = function() {}; MyObject.prototype.parent = function(obj) { if (obj === undefined) { return this._parent; } this._parent = obj; }; MyObject.prototype.children = function(obj) { if (obj === undefined) { return this._children; } this._children = obj; }; var a = new MyObject(), b = new MyObject(); var barr = [b]; a.children(barr); b.parent(a); assert.equal(a.children(), barr); assert.deepEqual(a.children(), [b]); }); (function() { var reset = QUnit.reset; QUnit.module( "reset" ); test("reset runs assertions", function( assert ) { expect(0); QUnit.reset = function() { assert.ok( false, "reset should not modify test status" ); reset.apply( this, arguments ); }; }); test("reset runs assertions, cleanup", function() { expect(0); QUnit.reset = reset; }); })(); function testAfterDone() { var testName = "ensure has correct number of assertions"; function secondAfterDoneTest() { QUnit.config.done = []; // Because when this does happen, the assertion count parameter doesn't actually // work we use this test to check the assertion count. QUnit.module( "check previous test's assertion counts" ); test('count previous two test\'s assertions', function ( assert ) { var tests = getPreviousTests(/^ensure has correct number of assertions/, /^Synchronous test after load of page$/); assert.equal(tests[0].firstChild.lastChild.getElementsByTagName("b")[1].innerHTML, "99"); assert.equal(tests[1].firstChild.lastChild.getElementsByTagName("b")[1].innerHTML, "99"); }); } QUnit.config.done = []; QUnit.done(secondAfterDoneTest); QUnit.module( "Synchronous test after load of page" ); asyncTest('Async test', function( assert ) { start(); for (var i = 1; i < 100; i++) { assert.ok(i); } }); test(testName, function( assert ) { expect( 99 ); for (var i = 1; i < 100; i++) { assert.ok(i); } }); // We need two of these types of tests in order to ensure that assertions // don't move between tests. test(testName + ' 2', function( assert ) { expect( 99 ); for (var i = 1; i < 100; i++) { assert.ok(i); } }); } if (typeof setTimeout !== 'undefined') { QUnit.done(testAfterDone); } // Get a reference to the global object, like window in browsers }( (function() { return this; }.call()) ));