├── src ├── refresh.png ├── captchaImages │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ └── 10.png ├── jquery.simpleCaptcha.css ├── simpleCaptcha.php └── jquery.simpleCaptcha.js ├── tests ├── refresh.png ├── index.html ├── test-php.php ├── qunit.html ├── lib │ ├── qunit-1.10.0.css │ ├── jquery.mockjax.js │ ├── qunit-1.10.0.js │ └── History.md └── qunit-tests.js ├── CHANGELOG ├── package.json ├── simpleCaptcha.jquery.json └── README.md /src/refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/refresh.png -------------------------------------------------------------------------------- /tests/refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/tests/refresh.png -------------------------------------------------------------------------------- /src/captchaImages/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/captchaImages/01.png -------------------------------------------------------------------------------- /src/captchaImages/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/captchaImages/02.png -------------------------------------------------------------------------------- /src/captchaImages/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/captchaImages/03.png -------------------------------------------------------------------------------- /src/captchaImages/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/captchaImages/04.png -------------------------------------------------------------------------------- /src/captchaImages/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/captchaImages/05.png -------------------------------------------------------------------------------- /src/captchaImages/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/captchaImages/06.png -------------------------------------------------------------------------------- /src/captchaImages/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/captchaImages/07.png -------------------------------------------------------------------------------- /src/captchaImages/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/captchaImages/08.png -------------------------------------------------------------------------------- /src/captchaImages/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/captchaImages/09.png -------------------------------------------------------------------------------- /src/captchaImages/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakerella/jquerySimpleCaptcha/HEAD/src/captchaImages/10.png -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 2 | Version 1.0 3 | - Upgraded to use jQuery 1.7 (breaks plugin for older versions of jQ) 4 | - Changed structure of plugin code to use objects (complete code restructuring) 5 | - Changed structure of PHP code to use class/methods (complete code restructuring) 6 | - Added better events 7 | - Added ability to "refresh" the captcha options (manually and by user button click) 8 | - Added testing suite 9 | 10 | Version 0.2 11 | - Changed to use title attribute of image for hash (versus alt) (We don't want the hash showing as images load) 12 | - Fixed simpleCaptcha.php to return properly formatted JSON (fixes bug in jQuery 1.4) 13 | 14 | Version 0.1 15 | - Initial Release -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-simple-captcha", 3 | "version": "1.0.0", 4 | "description": "Easy to use and understand captcha implementation for jQuery", 5 | "main": "src/jquery.simpleCaptcha.js", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Please run tests using QUnit web UI\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/jakerella/jquerySimpleCaptcha.git" 15 | }, 16 | "keywords": [ 17 | "jquery-plugin", 18 | "captcha", 19 | "form", 20 | "spam" 21 | ], 22 | "author": "Jordan Kasper()", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/jakerella/jquerySimpleCaptcha/issues" 26 | }, 27 | "homepage": "https://github.com/jakerella/jquerySimpleCaptcha" 28 | } 29 | -------------------------------------------------------------------------------- /simpleCaptcha.jquery.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simpleCaptcha", 3 | "title": "jQuery SimpleCaptcha", 4 | "description": "Easy-to-use and understand captcha implementation.", 5 | "keywords": [ 6 | "form", 7 | "captcha", 8 | "spam", 9 | "human" 10 | ], 11 | "version": "1.0.0", 12 | "author": { 13 | "name": "Jordan Kasper", 14 | "email": "jquery@jordankasper.com", 15 | "url": "http://jordankasper.com" 16 | }, 17 | "licenses": [ 18 | { 19 | "type": "MIT", 20 | "url": "http://www.opensource.org/licenses/mit-license.php" 21 | } 22 | ], 23 | "dependencies": { 24 | "jquery": ">=1.7" 25 | }, 26 | "homepage": "https://github.com/jakerella/jquerySimpleCaptcha", 27 | "docs": "https://github.com/jakerella/jquerySimpleCaptcha", 28 | "download": "https://github.com/jakerella/jquerySimpleCaptcha", 29 | "bugs": "https://github.com/jakerella/jquerySimpleCaptcha/issues", 30 | "demo": "http://jordankasper.com/jquery/captcha/examples.php" 31 | } -------------------------------------------------------------------------------- /src/jquery.simpleCaptcha.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 Jordan Kasper 3 | * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 4 | * 5 | * Refresh icon by Sallee Jeremy (http://www.iconfinder.com/icondetails/48523/128/refresh_sync_icon) 6 | */ 7 | 8 | .simpleCaptcha { display: inline-block; padding: 0.5em; border: 1px solid #acf; border-radius: 5px; background-color: #f9f9ff; } 9 | .simpleCaptcha p { margin: 0.5em; } 10 | .simpleCaptcha .captchaIntro, .simpleCaptcha .refreshCaptcha { float: left; } 11 | .simpleCaptcha .captchaText { font-weight: bold; } 12 | .simpleCaptcha .refreshButton { height: 1.2em; cursor: pointer; position: relative; top: 0.3em; margin-left: 0.2em; } 13 | .simpleCaptcha .refreshButtonText { position: absolute; left: -9999px; } 14 | .simpleCaptcha .captchaImages { clear: left; } 15 | .simpleCaptcha .captchaImage { margin: 0 2px; border: 2px solid transparent; cursor: pointer; } 16 | .simpleCaptcha .simpleCaptchaSelected { border: 2px solid #393; border-radius: 4px; background-color: #cfc; } -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | jQuery.simpleCaptcha Tests 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 |

jQuery.simpleCaptcha Tests

17 | 18 |

19 | This is the collection of tests for the jQuery.simpleCaptcha plugin. Please test ALL of them 20 | in MULTIPLE browsers (At least Chrome, Firefox, and IE - preferrably Safari and Opera as well). 21 | If you don't have a particular language or browser installed on your system to test with, try 22 | using a Virtual Machine or try to get another 23 | contributor to test for you. 24 |

25 | 26 | 30 | 31 |
32 | 33 | -------------------------------------------------------------------------------- /tests/test-php.php: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | jQuery.simpleCaptcha Tests 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 |

jQuery.simpleCaptcha Functional Tests - PHP

25 | 26 |

27 | TODO: Description... 28 |

29 | 30 | Correct captcha selection match

"; 34 | } else { 35 | echo "

captcha selection does not match expected answer: (selction) ".$_POST['captchaSelection']." != ".$_SESSION['simpleCaptchaAnswer']." (answer).

"; 36 | } 37 | } 38 | ?> 39 | 40 |
41 |

POST form

42 | 43 |
44 | 45 | 46 |
47 | 48 |
49 | 50 |
51 | 52 |
53 |
54 | 55 | 60 | 61 |

$_REQUEST object for debugging:

62 |
63 | 64 | 65 | -------------------------------------------------------------------------------- /tests/qunit.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | jQuery.simpleCaptcha QUnit Test Runner 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 26 | 27 | 28 |
29 | 30 |

jQuery.simpleCaptcha QUnit Test Runner

31 |
32 | 33 | 34 |
35 |

36 |
37 |

38 |
    39 | 40 |
    41 | 42 |
    43 |

    Simple POST form

    44 | 45 |
    46 | 47 | 48 |
    49 | 50 |
    51 | 52 |
    53 | 54 |
    55 |
    56 | 57 |
    58 | 59 |
    60 | 61 | 66 | 67 | -------------------------------------------------------------------------------- /tests/lib/qunit-1.10.0.css: -------------------------------------------------------------------------------- 1 | /** 2 | * QUnit v1.10.0 - A JavaScript Unit Testing Framework 3 | * 4 | * http://qunitjs.com 5 | * 6 | * Copyright 2012 jQuery Foundation and other contributors 7 | * Released under the MIT license. 8 | * http://jquery.org/license 9 | */ 10 | 11 | /** Font Family and Sizes */ 12 | 13 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { 14 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; 15 | } 16 | 17 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } 18 | #qunit-tests { font-size: smaller; } 19 | 20 | 21 | /** Resets */ 22 | 23 | #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter { 24 | margin: 0; 25 | padding: 0; 26 | } 27 | 28 | 29 | /** Header */ 30 | 31 | #qunit-header { 32 | padding: 0.5em 0 0.5em 1em; 33 | 34 | color: #8699a4; 35 | background-color: #0d3349; 36 | 37 | font-size: 1.5em; 38 | line-height: 1em; 39 | font-weight: normal; 40 | 41 | border-radius: 5px 5px 0 0; 42 | -moz-border-radius: 5px 5px 0 0; 43 | -webkit-border-top-right-radius: 5px; 44 | -webkit-border-top-left-radius: 5px; 45 | } 46 | 47 | #qunit-header a { 48 | text-decoration: none; 49 | color: #c2ccd1; 50 | } 51 | 52 | #qunit-header a:hover, 53 | #qunit-header a:focus { 54 | color: #fff; 55 | } 56 | 57 | #qunit-testrunner-toolbar label { 58 | display: inline-block; 59 | padding: 0 .5em 0 .1em; 60 | } 61 | 62 | #qunit-banner { 63 | height: 5px; 64 | } 65 | 66 | #qunit-testrunner-toolbar { 67 | padding: 0.5em 0 0.5em 2em; 68 | color: #5E740B; 69 | background-color: #eee; 70 | overflow: hidden; 71 | } 72 | 73 | #qunit-userAgent { 74 | padding: 0.5em 0 0.5em 2.5em; 75 | background-color: #2b81af; 76 | color: #fff; 77 | text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; 78 | } 79 | 80 | #qunit-modulefilter-container { 81 | float: right; 82 | } 83 | 84 | /** Tests: Pass/Fail */ 85 | 86 | #qunit-tests { 87 | list-style-position: inside; 88 | } 89 | 90 | #qunit-tests li { 91 | padding: 0.4em 0.5em 0.4em 2.5em; 92 | border-bottom: 1px solid #fff; 93 | list-style-position: inside; 94 | } 95 | 96 | #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { 97 | display: none; 98 | } 99 | 100 | #qunit-tests li strong { 101 | cursor: pointer; 102 | } 103 | 104 | #qunit-tests li a { 105 | padding: 0.5em; 106 | color: #c2ccd1; 107 | text-decoration: none; 108 | } 109 | #qunit-tests li a:hover, 110 | #qunit-tests li a:focus { 111 | color: #000; 112 | } 113 | 114 | #qunit-tests ol { 115 | margin-top: 0.5em; 116 | padding: 0.5em; 117 | 118 | background-color: #fff; 119 | 120 | border-radius: 5px; 121 | -moz-border-radius: 5px; 122 | -webkit-border-radius: 5px; 123 | } 124 | 125 | #qunit-tests table { 126 | border-collapse: collapse; 127 | margin-top: .2em; 128 | } 129 | 130 | #qunit-tests th { 131 | text-align: right; 132 | vertical-align: top; 133 | padding: 0 .5em 0 0; 134 | } 135 | 136 | #qunit-tests td { 137 | vertical-align: top; 138 | } 139 | 140 | #qunit-tests pre { 141 | margin: 0; 142 | white-space: pre-wrap; 143 | word-wrap: break-word; 144 | } 145 | 146 | #qunit-tests del { 147 | background-color: #e0f2be; 148 | color: #374e0c; 149 | text-decoration: none; 150 | } 151 | 152 | #qunit-tests ins { 153 | background-color: #ffcaca; 154 | color: #500; 155 | text-decoration: none; 156 | } 157 | 158 | /*** Test Counts */ 159 | 160 | #qunit-tests b.counts { color: black; } 161 | #qunit-tests b.passed { color: #5E740B; } 162 | #qunit-tests b.failed { color: #710909; } 163 | 164 | #qunit-tests li li { 165 | padding: 5px; 166 | background-color: #fff; 167 | border-bottom: none; 168 | list-style-position: inside; 169 | } 170 | 171 | /*** Passing Styles */ 172 | 173 | #qunit-tests li li.pass { 174 | color: #3c510c; 175 | background-color: #fff; 176 | border-left: 10px solid #C6E746; 177 | } 178 | 179 | #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } 180 | #qunit-tests .pass .test-name { color: #366097; } 181 | 182 | #qunit-tests .pass .test-actual, 183 | #qunit-tests .pass .test-expected { color: #999999; } 184 | 185 | #qunit-banner.qunit-pass { background-color: #C6E746; } 186 | 187 | /*** Failing Styles */ 188 | 189 | #qunit-tests li li.fail { 190 | color: #710909; 191 | background-color: #fff; 192 | border-left: 10px solid #EE5757; 193 | white-space: pre; 194 | } 195 | 196 | #qunit-tests > li:last-child { 197 | border-radius: 0 0 5px 5px; 198 | -moz-border-radius: 0 0 5px 5px; 199 | -webkit-border-bottom-right-radius: 5px; 200 | -webkit-border-bottom-left-radius: 5px; 201 | } 202 | 203 | #qunit-tests .fail { color: #000000; background-color: #EE5757; } 204 | #qunit-tests .fail .test-name, 205 | #qunit-tests .fail .module-name { color: #000000; } 206 | 207 | #qunit-tests .fail .test-actual { color: #EE5757; } 208 | #qunit-tests .fail .test-expected { color: green; } 209 | 210 | #qunit-banner.qunit-fail { background-color: #EE5757; } 211 | 212 | 213 | /** Result */ 214 | 215 | #qunit-testresult { 216 | padding: 0.5em 0.5em 0.5em 2.5em; 217 | 218 | color: #2b81af; 219 | background-color: #D2E0E6; 220 | 221 | border-bottom: 1px solid white; 222 | } 223 | #qunit-testresult .module-name { 224 | font-weight: bold; 225 | } 226 | 227 | /** Fixture */ 228 | 229 | #qunit-fixture { 230 | position: absolute; 231 | top: -10000px; 232 | left: -10000px; 233 | width: 1000px; 234 | height: 1000px; 235 | } 236 | -------------------------------------------------------------------------------- /src/simpleCaptcha.php: -------------------------------------------------------------------------------- 1 | IMAGE_FILE 22 | 'house' => 'captchaImages/01.png', 23 | 'key' => 'captchaImages/02.png', 24 | 'flag' => 'captchaImages/03.png', 25 | 'clock' => 'captchaImages/04.png', 26 | 'bug' => 'captchaImages/05.png', 27 | 'pen' => 'captchaImages/06.png', 28 | 'light bulb' => 'captchaImages/07.png', 29 | 'musical note' => 'captchaImages/08.png', 30 | 'heart' => 'captchaImages/09.png', 31 | 'world' => 'captchaImages/10.png' 32 | ); 33 | 34 | // You should change this for security reasons, 10-20 characters is good 35 | private $salt = "o^G-j7%8W3xP!2_"; 36 | 37 | // ------------------------------------------------- // 38 | // ------------------- STOP EDITING ---------------- // 39 | // ------------------------------------------------- // 40 | // (All other options should be edited in the plugin JavaScript.) 41 | 42 | 43 | 44 | const MIN_IMAGES = 3; 45 | const DEFAULT_NUM_IMAGES = 5; 46 | private $sessionData = null; 47 | private $answer = null; 48 | 49 | public function __construct() { 50 | $this->getDataFromSession(); 51 | 52 | if (!$this->sessionData) { 53 | $this->resetSessionData(); 54 | } 55 | } 56 | 57 | public function resetSessionData() { 58 | $this->sessionData = array( 59 | 'time' => time(), 60 | 'images' => array(), 61 | 'salt' => null 62 | ); 63 | $this->sessionData['salt'] = $this->salt . $this->sessionData['time']; 64 | } 65 | 66 | public function getImageByHash($hash) { 67 | if (isset($this->sessionData['images'][$hash])) { 68 | $fn = $this->sessionData['images'][$hash]; 69 | 70 | if (file_exists($fn)) { 71 | $mime = null; 72 | if (function_exists("finfo_open")) { 73 | // PHP 5.3 74 | $finfo = finfo_open(FILEINFO_MIME_TYPE); 75 | $mime = finfo_file($finfo, $fn); 76 | 77 | } else if (function_exists("mime_content_type")) { 78 | // PHP 5.2 79 | $mime = mime_content_type($fn); 80 | } 81 | 82 | if (!$mime) { $mime = "image/png"; } 83 | 84 | header("Content-Type: {$mime}"); 85 | readfile($fn); 86 | exit; 87 | 88 | } else { 89 | throw new InvalidArgumentException("That captcha image file does not exist", 404); 90 | } 91 | } else { 92 | throw new InvalidArgumentException("No captcha image exists with that hash: ".json_encode($this->sessionData->images), 404); 93 | } 94 | } 95 | 96 | public function getAllImageData() { 97 | $iData = array( 98 | 'text' => '', 99 | 'images' => array() 100 | ); 101 | 102 | if (!isset($this->images) || !is_array($this->images) || sizeof($this->images) < SimpleCaptcha::MIN_IMAGES) { 103 | throw new InvalidArgumentException("There aren\'t enough images on the server!", 400); 104 | } 105 | 106 | $numImages = SimpleCaptcha::DEFAULT_NUM_IMAGES; 107 | if (isset($_REQUEST['numImages']) && 108 | intval($_REQUEST['numImages']) && 109 | intval($_REQUEST['numImages']) > SimpleCaptcha::MIN_IMAGES) { 110 | $numImages = intval($_REQUEST['numImages']); 111 | } 112 | $totalSize = sizeof($this->images); 113 | $numImages = min(array($totalSize, $numImages)); 114 | 115 | $keys = array_keys($this->images); 116 | $used = array(); 117 | 118 | mt_srand(((float) microtime() * 587) / 33); // add some randomness 119 | 120 | for ($i=0; $i<$numImages; ++$i) { 121 | $r = rand(0, $totalSize-1); 122 | while (array_search($keys[$r], $used) !== false) { 123 | $r = rand(0, $totalSize-1); 124 | } 125 | array_push($used, $keys[$r]); 126 | } 127 | 128 | $iData['text'] = $used[rand(0, $numImages-1)]; 129 | $this->answer = sha1($iData['text'] . $this->sessionData['salt']); 130 | 131 | shuffle($used); 132 | 133 | for ($i=0; $isessionData['salt']); 135 | array_push($iData['images'], $hash); 136 | $this->sessionData['images'][$hash] = $this->images[$used[$i]]; 137 | } 138 | 139 | return $iData; 140 | } 141 | 142 | 143 | public function writeSessionData() { 144 | $_SESSION['simpleCaptchaAnswer'] = $this->answer; 145 | $_SESSION['simpleCaptchaData'] = json_encode($this->sessionData); 146 | // And for backward compatibility... 147 | $_SESSION['simpleCaptchaTimestamp'] = $this->sessionData['time']; 148 | } 149 | 150 | public function getDataFromSession() { 151 | if (isset($_SESSION['simpleCaptchaData'])) { 152 | $this->sessionData = json_decode($_SESSION['simpleCaptchaData'], true); 153 | } 154 | if (isset($_SESSION['simpleCaptchaAnswer'])) { 155 | $this->answer = $_SESSION['simpleCaptchaAnswer']; 156 | } 157 | } 158 | 159 | 160 | // Static helper methods 161 | 162 | public static function getProtocol() { 163 | $protocol = "HTTP/1.1"; 164 | if(isset($_SERVER['SERVER_PROTOCOL'])) { 165 | $protocol = $_SERVER['SERVER_PROTOCOL']; 166 | } 167 | return $protocol; 168 | } 169 | 170 | } 171 | 172 | 173 | // ------------------- Handle Incoming Requests ------------------- // 174 | 175 | $sc = new SimpleCaptcha(); 176 | try { 177 | 178 | if (isset($_REQUEST['hash'])) { 179 | // Just getting one image file by it's hash 180 | $sc->getImageByHash($_REQUEST['hash']); 181 | 182 | } else { 183 | // Getting all image data and hashes 184 | $sc->resetSessionData(); 185 | $imageData = $sc->getAllImageData(); 186 | 187 | // Finish up by writing data to the session and the ouput buffer 188 | $sc->writeSessionData(); 189 | header("Content-Type: application/json"); 190 | echo json_encode($imageData); 191 | } 192 | 193 | } catch (InvalidArgumentException $iae) { 194 | $code = $iae->getCode(); 195 | if (!$code) { $code = 400; } 196 | header(SimpleCaptcha::getProtocol()." {$code} ".$iae->getMessage()); 197 | echo $iae->getMessage(); 198 | 199 | } catch (Exception $e) { 200 | $code = $e->getCode(); 201 | if (!$code) { $code = 500; } 202 | header(SimpleCaptcha::getProtocol()." {$code} ".$e->getMessage()); 203 | echo $e->getMessage(); 204 | } 205 | 206 | exit; // make sure we stop the script 207 | ?> -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | jquerySimpleCaptcha 2 | =================== 3 | 4 | SimpleCaptcha allows you to drop in an easy-to-use and understand captcha implementation for helping to curb spambots on your system. The plug-in makes things very easy for you with a limited amount of setup required and standard xhtml and css classes in place to make changing the appearance super easy. 5 | 6 | Features 7 | -------- 8 | 9 | * __Simple to Use:__ This CAPTCHA implementation is easy to use by both the developer and the user! 10 | * __User Experience Focused:__ Uses human-understandable images instead of hard to read text 11 | * __Events:__ Events are triggered at various points so you can hook into the processing if you need to 12 | * __Standard HTML and CSS:__ Standard-compliant xhtml with extensive classes used to allow for easy UI manipulation through CSS 13 | 14 | 15 | The Setup 16 | --------- 17 | 18 | There are three pieces to this plug-in: (1) the JavaScript file, (2) the PHP script, and (3) the images. Here are the steps you need to take to get things working: 19 | 20 | * Upload the PHP script (src/simpleCaptcha.php) to your site (remember where, and what you named it!) 21 | * Upload the JavaScript plugin file (src/jquery.simpleCaptcha.js) to your site and include it in your page (after you include the jQuery core) 22 | * Make a folder on your server for the images to use in the captcha system (and optionally upload the sample images to that folder) 23 | * Update the PHP script (src/simpleCaptcha.php) with your image filenames and the text the user should see for each 24 | * (Optional) Upload (or copy) the CSS and "refresh" image to your server 25 | 26 | 27 | Basic Usage 28 | ----------- 29 | 30 | ```html 31 |
    32 | ... 33 |
    34 | ... 35 |
    36 | 37 | 42 | ``` 43 | 44 | When your form is submitted, you just need to check one variable to see if the form was submitted by a human: 45 | 46 | ```php 47 | 56 | ``` 57 | 58 | __Note that the element you call `simpleCaptcha()` on should be in a `
    `!__ 59 | 60 | 61 | Options 62 | ------- 63 | 64 | * _allowRefresh_: Whether the user should see a UI element allowing them to refresh the captcha choices _(default: `true`)_ 65 | * _numImages_: How many images to show the user (providing there are at least that many defined in the script file) _(default: `5`)_ 66 | * _textClass_: Class to look for to place the text for the correct captcha image. _(default: `"captchaText"`)_ 67 | * _introText_: Text to place above captcha images (can contain html). __IMPORTANT__ You should probably include a tag with the textClass name on it, for example: `` _(default: `"

    To make sure you are a human, we need you to click on the .

    "`)_ 68 | * _refreshButton_: Html to use for the "refresh" button/content. Note that you can make this whatever you like, but it will be placed AFTER the "introText", and a click handler will be attached to initiate the refresh, so best to make it something "clickable". _(default: `""`)_ 69 | * _refreshClass_: Class to use for the captcha refresh block (if there is one) _(default: `"refreshCaptcha"`)_ 70 | * _inputName_: Name to use for the captcha hidden input, this is what you will need to check on the receiving end of the form submission. _(default: `"captchaSelection"`)_ 71 | * _scriptPath_: Path to the script file to use for the initial AJAX call (can be a relative path to the current page). _(default: `"simpleCaptcha.php"`)_ 72 | * _introClass_: Class to use for the captcha introduction text container. _(default: `"captchaIntro"`)_ 73 | * _imageBoxClass_: Class to use for the captchas images container. _(default: `"captchaImages"`)_ 74 | * _imageClass_: Class to use for each captcha image. _(default: `"captchaImage"`)_ 75 | 76 | 77 | Events 78 | ------ 79 | 80 | * _init.simpleCaptcha_: The basic UI container, form element and event handlers have been added to the page. Note that at this point the captcha images, hashes, and answer text will NOT have been laoded, see the "dataload" and ready" events below. You should only ever receive ONE of these events per page load. _(Arguments: `captcha` (`SimpleCaptcha` object))_ 81 | * _dataload.simpleCaptcha_: The captcha images, hashes, and text have been loaded via the server script (although the UI may not yet be updated). _(Arguments: `returnData` (object))_ 82 | * _ready.simpleCaptcha_: The captcha images, hashes, and answer text have been loaded in the UI and everything is ready to go. Note that you may receive multiple of these if the user requests a "refresh", see below. _(Arguments: `captcha` (`SimpleCaptcha` object))_ 83 | * _select.simpleCaptcha_: The user has selected a captcha image (this is NOT when the form is submitted). Note that this is called EACH time, not just on the initial selection (in other words, they may change their selection). _(Arguments: `captcha` (`SimpleCaptcha` object), `hash` (string))_ 84 | * _refresh.simpleCaptcha_: The user has requested that the captcha images be reloaded. Note that you shoul also receive "dataload" and "ready" events after this. _(Arguments: `captcha` (`SimpleCaptcha` object))_ 85 | * _error.simpleCaptcha_: There is an error during any part of the process. _(Arguments: `errorMessage` (string))_ 86 | 87 | 88 | Event Example 89 | ------------- 90 | 91 | ```javascript 92 | $('#captcha') 93 | .bind('select.simpleCaptcha', function(hashSelected) { 94 | // do something when the user selects a captcha image 95 | }) 96 | .simpleCaptcha({}); 97 | ``` 98 | 99 | 100 | How it Works 101 | ------------ 102 | 103 | _What Happens_ 104 | When you call $("#someDivInYourForm").simpleCaptcha({...}) the plug-in will make an XMLHttpRequest (AJAX call) to the PHP script which will then randomly select the number of images you specify (or a default) and from those, one to be the "correct" option. The script places a hash of the image text of the correct option (and some random characters) into the session and sends back the hashes - as well as the file locations - for all options. The hash is placed in the "alt" text of the image tag, and when a user clicks on an image, its hash is placed in the value of the hidden input. 105 | 106 | _Telling humans from machines_ 107 | When a user submits the form that the simpleCaptcha UI is in, they will also submit the simpleCaptcha hidden form input, __you must check this input to see if they got the answer right__. All you do is compare their answer (a hash) against what is in the session variable. [Check the examples](http://jordankasper.com/jquery/captcha/examples) to see how to do this. 108 | 109 | _Advanced Stuff_ 110 | There are other options and possibilities with this plug-in. For example, the PHP script also places a timestamp of when the captcha was generated into the session ("simpleCaptchaTimestamp"). This allows you to check - when the form is submitted - to see how long the "user" took. 111 | 112 | There are also classes that you can specify to allow you to hook into the UI easier, events that are triggered when the captcha is loaded and when a selection is made, and of course the ability to tinker with the location of the script, or even rewrite the script in the language of your choice. 113 | 114 | Known Issues 115 | ------------ 116 | 117 | * You can only have one simpleCaptcha instance per page (really its that you can only have one active captcha per session) 118 | * Inaccessible to the visually impaired 119 | * No keyboard controls 120 | * Requires PHP and sessions (although other languages should be easy enough to port to, send them to me if you have one!) 121 | -------------------------------------------------------------------------------- /src/jquery.simpleCaptcha.js: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Jordan Kasper 2 | * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 3 | * Copyright notice and license must remain intact for legal use 4 | * 5 | * Requires: jQuery 1.7+ 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 8 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 9 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 10 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 11 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 12 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 13 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 14 | * 15 | * For more usage documentation and examples, visit: 16 | * https://github.com/jakerella/jquerySimpleCaptcha 17 | * 18 | */ 19 | ;(function($) { 20 | 21 | // PRIVATE VARS & METHODS 22 | var ns = 'simpleCaptcha'; 23 | 24 | 25 | /** 26 | * This method will add a captcha to the selected element which includes making an 27 | * ajax request for the images & hashes and displaying the information 28 | * 29 | * Typical usage: 30 | * $('#divInForm').simpleCaptcha({ 31 | * // options 32 | * }); 33 | * 34 | * Optionally, if a captcha is already on this node you can call the method again with: 35 | * - the name of an option to retrieve that option's value (i.e. var num = $('#divInForm').simpleCaptcha('numImages'); ) 36 | * - "refresh" to reset the images and hashes from a new AJAX call to the PHP script (i.e. $('#divInForm').prefillForm('refresh'); ) 37 | * 38 | * @param {object|string} o If an OBJECT, creates a new simpleCaptcha in the selected element and uses the object as options 39 | * @return {jQuery} The jQuery object for chain calling (NOTE: If an option was requested then this method returns that option value, not the jQuery chain) 40 | */ 41 | $.fn.simpleCaptcha = function(o) { 42 | var n = $(this); 43 | var c; 44 | o = (o)?o:{}; 45 | 46 | if (n.length === 1 && n.hasClass(ns) && n.data(ns) && o && o.length) { 47 | // Get simpleCaptcha option value 48 | c = n.data(ns); 49 | if (c && o === 'refresh') { 50 | // refresh the data 51 | c.refresh(); 52 | 53 | } else if (c) { 54 | // send back the option value 55 | return c[o]; 56 | } 57 | 58 | } else if (!o.node && n.length) { 59 | // Use the first selected element 60 | o.node = n.filter(':first'); 61 | } 62 | 63 | if (!c && o.node) { 64 | // if we don't have a captcha object yet, create one and start it up 65 | c = new $.jk.SimpleCaptcha(o); 66 | c.loadImageData(function(d) { if (d) { c.addImagesToUI(); } }); 67 | } 68 | 69 | if (!c) { n.trigger('error.'+ns, ['No node provided for the simpleCaptcha UI']); } 70 | 71 | return n; 72 | }; 73 | 74 | 75 | // CONSTRUCTOR 76 | if (!$.jk) { $.jk = {}; } 77 | $.jk.SimpleCaptcha = function(o) { 78 | var t = this; 79 | o = (o)?o:{}; 80 | t.data = {}; 81 | 82 | // Audit options and merge with object 83 | if (o.numImages && (!Number(o.numImages) || o.numImages < 1)) { o.numImages = t.numImages; } 84 | $.extend(t, ((o)?o:{})); 85 | t.allowRefresh = !!t.allowRefresh; // force boolean value 86 | 87 | var n; 88 | t.node = $( ((o.node)?o.node:null) ); 89 | if (t.node && t.node.length === 1){ 90 | n = t.node; 91 | } else { 92 | // if we don't have a single node, nothing more we can do... 93 | return t; 94 | } 95 | 96 | n.addClass(ns) 97 | .html('') // clear out the container 98 | .append( 99 | "
    "+t.introText+"
    "+ 100 | "
    "+ 101 | "" 102 | ) 103 | // set the class as node data 104 | .data(ns, t) 105 | 106 | // handler for selecting images 107 | .find('.'+t.imageBoxClass) 108 | .on('click', 'img.'+t.imageClass, function(e) { 109 | e.preventDefault(); 110 | n.find('img.'+t.imageClass).removeClass(ns+'Selected'); 111 | var hash = $(this).addClass(ns+'Selected').attr('data-hash'); 112 | n.find('.'+ns+"Input").val(hash); 113 | 114 | n.trigger('select.'+ns, [t, hash]); 115 | return false; 116 | }) 117 | // handle an "enter" & "space" while an image has focus, emulating a click 118 | .on('keyup', 'img.'+t.imageClass, function(e) { 119 | if (e.which == 13 || e.which == 32) { 120 | $(this).click(); 121 | } 122 | }); 123 | 124 | if (t.allowRefresh) { 125 | var b = $(t.refreshButton); 126 | n.find('.'+t.introClass) 127 | .after("
    ") 128 | .siblings('.'+t.refreshClass) 129 | .append(b); 130 | b.on('click', function(e) { 131 | e.preventDefault(); 132 | t.refresh(); 133 | return false; 134 | }); 135 | } 136 | 137 | n.trigger('init.'+ns, [t]); 138 | }; 139 | 140 | 141 | // PUBLIC PROPERTIES (Default options) 142 | // Assign default options to the class prototype 143 | $.extend($.jk.SimpleCaptcha.prototype, { 144 | allowRefresh: true, // Boolean Whether the user should see a UI element allowing them to refresh the captcha choices 145 | scriptPath: 'simpleCaptcha.php', // String Relative path to the script file to use (usually simpleCaptcha.php). 146 | numImages: 5, // Number How many images to show the user (providing there are at least that many defined in the script file). 147 | introText: "

    To make sure you are a human, we need you to click on the .

    ", 148 | // String Text to place above captcha images (can contain html). IMPORTANT: You should probably include a tag with the textClass name on it, for example: 149 | refreshButton: "Refresh", 150 | // String Html to use for the "refresh" button/content. Note that you can make this whatever you like, but it will be placed AFTER the "introText", and a click handler will be attached to initiate the refresh, so best to make it something "clickable". 151 | refreshClass: 'refreshCaptcha', // String Class to use for the captcha refresh block (if there is one) 152 | inputName: 'captchaSelection', // String Name to use for the captcha hidden input, this is what you will need to check on the receiving end of the form submission. 153 | introClass: 'captchaIntro', // String Class to use for the captcha introduction text container. 154 | textClass: 'captchaText', // String Class to look for to place the text for the correct captcha image. 155 | imageBoxClass: 'captchaImages', // String Class to use for the captchas images container. 156 | imageClass: 'captchaImage', // String Class to use for each captcha image. 157 | node: null // Node | String The node (or selector) to use for the captcha UI. If not set, the current node selected bu $(...).simpleCaptcha(); will be used 158 | }); 159 | 160 | 161 | // PUBLIC METHODS 162 | $.extend($.jk.SimpleCaptcha.prototype, { 163 | 164 | loadImageData: function(cb) { 165 | var t = this; 166 | cb = ($.isFunction(cb))?cb:(function(){}); 167 | 168 | $.ajax({ 169 | url: t.scriptPath, 170 | data: { numImages: t.numImages }, 171 | type: 'post', 172 | dataType: 'json', 173 | success: function(d, s) { 174 | if (d && d.images && d.text) { 175 | t.data = d; 176 | t.node.trigger('dataload.'+ns, [d]); 177 | cb(d); 178 | } else { 179 | t.node.trigger('error.'+ns, ['Invalid data was returned from the server.']); 180 | cb(null); 181 | } 182 | }, 183 | error: function(xhr, s) { 184 | console.debug('in error handler:', xhr); 185 | cb(null); 186 | t.node.trigger('error.'+ns, ['There was a serious problem: '+xhr.status]); 187 | } 188 | }); 189 | }, 190 | 191 | addImagesToUI: function() { 192 | var t = this; 193 | // Add image text to correct place 194 | t.node.find('.'+t.textClass).text(t.data.text); 195 | 196 | // Build images html 197 | var h = ""; 198 | for (var i=0; i"; 200 | } 201 | // Add images to container (replacing existing ones, if any) 202 | t.node.find('.'+t.imageBoxClass).html(h); 203 | 204 | t.node.trigger('ready.'+ns, [t]); 205 | }, 206 | 207 | refresh: function() { 208 | var t = this; 209 | t.node.trigger('refresh.'+ns, [t]); 210 | t.loadImageData(function(d) { 211 | if (d) { t.addImagesToUI(); } 212 | }); 213 | } 214 | 215 | }); 216 | 217 | 218 | })(jQuery); -------------------------------------------------------------------------------- /tests/qunit-tests.js: -------------------------------------------------------------------------------- 1 | 2 | // ---------------- Global Settings --------------- // 3 | 4 | // trap our namespaced errors and let the individual tests handle it 5 | window.onerror = function ( error, filePath, linerNr ) { 6 | if (error.namespace == 'simpleCaptcha') { 7 | console.log('trapped window error on namespace', error); 8 | return false; 9 | } 10 | }; 11 | 12 | // Mockjax settings for image hash requests 13 | 14 | var reqHashesGood = { 15 | url: 'simpleCaptcha.php', 16 | type: 'post', 17 | status: 200, 18 | dataType: 'json', 19 | response: function(req) { 20 | console.log('Mockjax request: ', req); 21 | var resp = { text: "answer", images: [] }; 22 | for (var i=0; iTo make sure you are a human, we need you to click on the .

    ", "introText is set correctly"); 64 | a.equal(sc.refreshButton, "Refresh", "refreshButton is set correctly"); 65 | a.equal(sc.refreshClass, 'refreshCaptcha', "refreshClass is set correctly"); 66 | a.equal(sc.inputName, 'captchaSelection', "inputName is set correctly"); 67 | a.equal(sc.introClass, 'captchaIntro', "introClass is set correctly"); 68 | a.equal(sc.textClass, 'captchaText', "textClass is set correctly"); 69 | a.equal(sc.imageBoxClass, 'captchaImages', "imageBoxClass is set correctly"); 70 | a.equal(sc.imageClass, 'captchaImage', "imageClass is set correctly"); 71 | a.equal(sc.node.length, 0, "node is set correctly"); 72 | }); 73 | 74 | test("Default DOM present", function(a) { 75 | var sc = new $.jk.SimpleCaptcha({node: '#simplePost'}); 76 | 77 | var iNode = sc.node.find('.'+sc.introClass); 78 | var rNode = sc.node.find('.'+sc.refreshClass); 79 | 80 | a.equal(iNode.length, 1, "Intro text container present"); 81 | a.equal(iNode.html(), $(sc.introText).get(0).outerHTML, "Intro content is correct"); 82 | a.equal(rNode.length, 1, "Refresh container present"); 83 | a.equal(rNode.html(), $(sc.refreshButton).get(0).outerHTML, "Refresh content is correct"); 84 | a.equal(sc.node.find('.'+sc.imageBoxClass).length, 1, "Image box present"); 85 | a.equal(sc.node.find('input[name='+sc.inputName+']').length, 1, "Form input present"); 86 | }); 87 | 88 | test("allowRefresh option - true", function(a) { 89 | var sc = new $.jk.SimpleCaptcha({ 90 | node: '#simplePost', 91 | allowRefresh: true 92 | }); 93 | 94 | var rn = sc.node.find('.refreshCaptcha'); 95 | a.equal(rn.length, 1, "Refresh container present"); 96 | a.equal(rn.html(), $(sc.refreshButton).get(0).outerHTML, "Refresh content is correct"); 97 | }); 98 | 99 | test("allowRefresh option - false", function(a) { 100 | var sc = new $.jk.SimpleCaptcha({ 101 | node: '#simplePost', 102 | allowRefresh: false 103 | }); 104 | 105 | var rn = sc.node.find('.refreshCaptcha'); 106 | a.equal(rn.length, 0, "Refresh container not present (which is correct)"); 107 | }); 108 | 109 | test("introClass option - custom", function(a) { 110 | var sc = new $.jk.SimpleCaptcha({ 111 | node: '#simplePost', 112 | introClass: 'theIntroArea', 113 | allowRefresh: true 114 | }); 115 | 116 | var iNode = sc.node.find('.theIntroArea'); 117 | a.equal(iNode.length, 1, "Intro container present"); 118 | a.equal(iNode.html(), $(sc.introText).get(0).outerHTML, "Intro content is correct"); 119 | }); 120 | 121 | test("introText option - custom", function(a) { 122 | var sc = new $.jk.SimpleCaptcha({ 123 | node: '#simplePost', 124 | introText: "

    Are you a robot? Then don't pick the .

    " 125 | }); 126 | 127 | var iNode = sc.node.find('.'+sc.introClass); 128 | a.equal(iNode.length, 1, "Intro container present"); 129 | a.equal(iNode.html(), $(sc.introText).get(0).outerHTML, "Intro content is correct"); 130 | }); 131 | 132 | test("refreshClass option - custom", function(a) { 133 | var sc = new $.jk.SimpleCaptcha({ 134 | node: '#simplePost', 135 | refreshClass: 'theRefreshArea', 136 | allowRefresh: true 137 | }); 138 | 139 | var rNode = sc.node.find('.theRefreshArea'); 140 | a.equal(rNode.length, 1, "Refresh container present"); 141 | a.equal(rNode.html(), $(sc.refreshButton).get(0).outerHTML, "Refresh content is correct"); 142 | }); 143 | 144 | test("refreshButton option - custom", function(a) { 145 | var sc = new $.jk.SimpleCaptcha({ 146 | node: '#simplePost', 147 | refreshButton: "", 148 | allowRefresh: true 149 | }); 150 | 151 | var rNode = sc.node.find('.'+sc.refreshClass); 152 | a.equal(rNode.length, 1, "Refresh container present"); 153 | a.equal(rNode.html(), $(sc.refreshButton).get(0).outerHTML, "Refresh content is correct"); 154 | }); 155 | 156 | test("imageBoxClass option - custom", function(a) { 157 | var sc = new $.jk.SimpleCaptcha({ 158 | node: '#simplePost', 159 | imageBoxClass: 'theImageArea' 160 | }); 161 | 162 | var ibNode = sc.node.find('.theImageArea'); 163 | a.equal(ibNode.length, 1, "Image Box container present"); 164 | a.equal(ibNode.html(), "", "Image Box content is correct (empty)"); 165 | }); 166 | 167 | test("Form input name - custom", function(a) { 168 | var sc = new $.jk.SimpleCaptcha({ 169 | node: '#simplePost', 170 | inputName: "myAnswer" 171 | }); 172 | 173 | a.equal(sc.node.find('input[name=myAnswer]').length, 1, "Custom form input present"); 174 | }); 175 | 176 | 177 | // ------------------------------- // 178 | 179 | module("Captcha Image UI Tests"); 180 | 181 | test("Captcha image UI build correctly", function(a) { 182 | var sc = new $.jk.SimpleCaptcha({node: '#simplePost'}); 183 | 184 | sc.data = { "images": [], "text": "answer" }; 185 | for (var i=0; i(" + bad + ", " + good + ", " + this.assertions.length + ")"; 217 | 218 | addEvent(b, "click", function() { 219 | var next = b.nextSibling.nextSibling, 220 | display = next.style.display; 221 | next.style.display = display === "none" ? "block" : "none"; 222 | }); 223 | 224 | addEvent(b, "dblclick", function( e ) { 225 | var target = e && e.target ? e.target : window.event.srcElement; 226 | if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) { 227 | target = target.parentNode; 228 | } 229 | if ( window.location && target.nodeName.toLowerCase() === "strong" ) { 230 | window.location = QUnit.url({ testNumber: test.testNumber }); 231 | } 232 | }); 233 | 234 | // `li` initialized at top of scope 235 | li = id( this.id ); 236 | li.className = bad ? "fail" : "pass"; 237 | li.removeChild( li.firstChild ); 238 | a = li.firstChild; 239 | li.appendChild( b ); 240 | li.appendChild ( a ); 241 | li.appendChild( ol ); 242 | 243 | } else { 244 | for ( i = 0; i < this.assertions.length; i++ ) { 245 | if ( !this.assertions[i].result ) { 246 | bad++; 247 | config.stats.bad++; 248 | config.moduleStats.bad++; 249 | } 250 | } 251 | } 252 | 253 | runLoggingCallbacks( "testDone", QUnit, { 254 | name: this.testName, 255 | module: this.module, 256 | failed: bad, 257 | passed: this.assertions.length - bad, 258 | total: this.assertions.length 259 | }); 260 | 261 | QUnit.reset(); 262 | 263 | config.current = undefined; 264 | }, 265 | 266 | queue: function() { 267 | var bad, 268 | test = this; 269 | 270 | synchronize(function() { 271 | test.init(); 272 | }); 273 | function run() { 274 | // each of these can by async 275 | synchronize(function() { 276 | test.setup(); 277 | }); 278 | synchronize(function() { 279 | test.run(); 280 | }); 281 | synchronize(function() { 282 | test.teardown(); 283 | }); 284 | synchronize(function() { 285 | test.finish(); 286 | }); 287 | } 288 | 289 | // `bad` initialized at top of scope 290 | // defer when previous test run passed, if storage is available 291 | bad = QUnit.config.reorder && defined.sessionStorage && 292 | +sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName ); 293 | 294 | if ( bad ) { 295 | run(); 296 | } else { 297 | synchronize( run, true ); 298 | } 299 | } 300 | }; 301 | 302 | // Root QUnit object. 303 | // `QUnit` initialized at top of scope 304 | QUnit = { 305 | 306 | // call on start of module test to prepend name to all tests 307 | module: function( name, testEnvironment ) { 308 | config.currentModule = name; 309 | config.currentModuleTestEnvironment = testEnvironment; 310 | config.modules[name] = true; 311 | }, 312 | 313 | asyncTest: function( testName, expected, callback ) { 314 | if ( arguments.length === 2 ) { 315 | callback = expected; 316 | expected = null; 317 | } 318 | 319 | QUnit.test( testName, expected, callback, true ); 320 | }, 321 | 322 | test: function( testName, expected, callback, async ) { 323 | var test, 324 | name = "" + escapeInnerText( testName ) + ""; 325 | 326 | if ( arguments.length === 2 ) { 327 | callback = expected; 328 | expected = null; 329 | } 330 | 331 | if ( config.currentModule ) { 332 | name = "" + config.currentModule + ": " + name; 333 | } 334 | 335 | test = new Test({ 336 | name: name, 337 | testName: testName, 338 | expected: expected, 339 | async: async, 340 | callback: callback, 341 | module: config.currentModule, 342 | moduleTestEnvironment: config.currentModuleTestEnvironment, 343 | stack: sourceFromStacktrace( 2 ) 344 | }); 345 | 346 | if ( !validTest( test ) ) { 347 | return; 348 | } 349 | 350 | test.queue(); 351 | }, 352 | 353 | // Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through. 354 | expect: function( asserts ) { 355 | if (arguments.length === 1) { 356 | config.current.expected = asserts; 357 | } else { 358 | return config.current.expected; 359 | } 360 | }, 361 | 362 | start: function( count ) { 363 | config.semaphore -= count || 1; 364 | // don't start until equal number of stop-calls 365 | if ( config.semaphore > 0 ) { 366 | return; 367 | } 368 | // ignore if start is called more often then stop 369 | if ( config.semaphore < 0 ) { 370 | config.semaphore = 0; 371 | } 372 | // A slight delay, to avoid any current callbacks 373 | if ( defined.setTimeout ) { 374 | window.setTimeout(function() { 375 | if ( config.semaphore > 0 ) { 376 | return; 377 | } 378 | if ( config.timeout ) { 379 | clearTimeout( config.timeout ); 380 | } 381 | 382 | config.blocking = false; 383 | process( true ); 384 | }, 13); 385 | } else { 386 | config.blocking = false; 387 | process( true ); 388 | } 389 | }, 390 | 391 | stop: function( count ) { 392 | config.semaphore += count || 1; 393 | config.blocking = true; 394 | 395 | if ( config.testTimeout && defined.setTimeout ) { 396 | clearTimeout( config.timeout ); 397 | config.timeout = window.setTimeout(function() { 398 | QUnit.ok( false, "Test timed out" ); 399 | config.semaphore = 1; 400 | QUnit.start(); 401 | }, config.testTimeout ); 402 | } 403 | } 404 | }; 405 | 406 | // Asssert helpers 407 | // All of these must call either QUnit.push() or manually do: 408 | // - runLoggingCallbacks( "log", .. ); 409 | // - config.current.assertions.push({ .. }); 410 | QUnit.assert = { 411 | /** 412 | * Asserts rough true-ish result. 413 | * @name ok 414 | * @function 415 | * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); 416 | */ 417 | ok: function( result, msg ) { 418 | if ( !config.current ) { 419 | throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) ); 420 | } 421 | result = !!result; 422 | 423 | var source, 424 | details = { 425 | module: config.current.module, 426 | name: config.current.testName, 427 | result: result, 428 | message: msg 429 | }; 430 | 431 | msg = escapeInnerText( msg || (result ? "okay" : "failed" ) ); 432 | msg = "" + msg + ""; 433 | 434 | if ( !result ) { 435 | source = sourceFromStacktrace( 2 ); 436 | if ( source ) { 437 | details.source = source; 438 | msg += "
    Source:
    " + escapeInnerText( source ) + "
    "; 439 | } 440 | } 441 | runLoggingCallbacks( "log", QUnit, details ); 442 | config.current.assertions.push({ 443 | result: result, 444 | message: msg 445 | }); 446 | }, 447 | 448 | /** 449 | * Assert that the first two arguments are equal, with an optional message. 450 | * Prints out both actual and expected values. 451 | * @name equal 452 | * @function 453 | * @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" ); 454 | */ 455 | equal: function( actual, expected, message ) { 456 | QUnit.push( expected == actual, actual, expected, message ); 457 | }, 458 | 459 | /** 460 | * @name notEqual 461 | * @function 462 | */ 463 | notEqual: function( actual, expected, message ) { 464 | QUnit.push( expected != actual, actual, expected, message ); 465 | }, 466 | 467 | /** 468 | * @name deepEqual 469 | * @function 470 | */ 471 | deepEqual: function( actual, expected, message ) { 472 | QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); 473 | }, 474 | 475 | /** 476 | * @name notDeepEqual 477 | * @function 478 | */ 479 | notDeepEqual: function( actual, expected, message ) { 480 | QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); 481 | }, 482 | 483 | /** 484 | * @name strictEqual 485 | * @function 486 | */ 487 | strictEqual: function( actual, expected, message ) { 488 | QUnit.push( expected === actual, actual, expected, message ); 489 | }, 490 | 491 | /** 492 | * @name notStrictEqual 493 | * @function 494 | */ 495 | notStrictEqual: function( actual, expected, message ) { 496 | QUnit.push( expected !== actual, actual, expected, message ); 497 | }, 498 | 499 | throws: function( block, expected, message ) { 500 | var actual, 501 | ok = false; 502 | 503 | // 'expected' is optional 504 | if ( typeof expected === "string" ) { 505 | message = expected; 506 | expected = null; 507 | } 508 | 509 | config.current.ignoreGlobalErrors = true; 510 | try { 511 | block.call( config.current.testEnvironment ); 512 | } catch (e) { 513 | actual = e; 514 | } 515 | config.current.ignoreGlobalErrors = false; 516 | 517 | if ( actual ) { 518 | // we don't want to validate thrown error 519 | if ( !expected ) { 520 | ok = true; 521 | // expected is a regexp 522 | } else if ( QUnit.objectType( expected ) === "regexp" ) { 523 | ok = expected.test( actual ); 524 | // expected is a constructor 525 | } else if ( actual instanceof expected ) { 526 | ok = true; 527 | // expected is a validation function which returns true is validation passed 528 | } else if ( expected.call( {}, actual ) === true ) { 529 | ok = true; 530 | } 531 | 532 | QUnit.push( ok, actual, null, message ); 533 | } else { 534 | QUnit.pushFailure( message, null, 'No exception was thrown.' ); 535 | } 536 | } 537 | }; 538 | 539 | /** 540 | * @deprecate since 1.8.0 541 | * Kept assertion helpers in root for backwards compatibility 542 | */ 543 | extend( QUnit, QUnit.assert ); 544 | 545 | /** 546 | * @deprecated since 1.9.0 547 | * Kept global "raises()" for backwards compatibility 548 | */ 549 | QUnit.raises = QUnit.assert.throws; 550 | 551 | /** 552 | * @deprecated since 1.0.0, replaced with error pushes since 1.3.0 553 | * Kept to avoid TypeErrors for undefined methods. 554 | */ 555 | QUnit.equals = function() { 556 | QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" ); 557 | }; 558 | QUnit.same = function() { 559 | QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" ); 560 | }; 561 | 562 | // We want access to the constructor's prototype 563 | (function() { 564 | function F() {} 565 | F.prototype = QUnit; 566 | QUnit = new F(); 567 | // Make F QUnit's constructor so that we can add to the prototype later 568 | QUnit.constructor = F; 569 | }()); 570 | 571 | /** 572 | * Config object: Maintain internal state 573 | * Later exposed as QUnit.config 574 | * `config` initialized at top of scope 575 | */ 576 | config = { 577 | // The queue of tests to run 578 | queue: [], 579 | 580 | // block until document ready 581 | blocking: true, 582 | 583 | // when enabled, show only failing tests 584 | // gets persisted through sessionStorage and can be changed in UI via checkbox 585 | hidepassed: false, 586 | 587 | // by default, run previously failed tests first 588 | // very useful in combination with "Hide passed tests" checked 589 | reorder: true, 590 | 591 | // by default, modify document.title when suite is done 592 | altertitle: true, 593 | 594 | // when enabled, all tests must call expect() 595 | requireExpects: false, 596 | 597 | // add checkboxes that are persisted in the query-string 598 | // when enabled, the id is set to `true` as a `QUnit.config` property 599 | urlConfig: [ 600 | { 601 | id: "noglobals", 602 | label: "Check for Globals", 603 | tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings." 604 | }, 605 | { 606 | id: "notrycatch", 607 | label: "No try-catch", 608 | tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings." 609 | } 610 | ], 611 | 612 | // Set of all modules. 613 | modules: {}, 614 | 615 | // logging callback queues 616 | begin: [], 617 | done: [], 618 | log: [], 619 | testStart: [], 620 | testDone: [], 621 | moduleStart: [], 622 | moduleDone: [] 623 | }; 624 | 625 | // Initialize more QUnit.config and QUnit.urlParams 626 | (function() { 627 | var i, 628 | location = window.location || { search: "", protocol: "file:" }, 629 | params = location.search.slice( 1 ).split( "&" ), 630 | length = params.length, 631 | urlParams = {}, 632 | current; 633 | 634 | if ( params[ 0 ] ) { 635 | for ( i = 0; i < length; i++ ) { 636 | current = params[ i ].split( "=" ); 637 | current[ 0 ] = decodeURIComponent( current[ 0 ] ); 638 | // allow just a key to turn on a flag, e.g., test.html?noglobals 639 | current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true; 640 | urlParams[ current[ 0 ] ] = current[ 1 ]; 641 | } 642 | } 643 | 644 | QUnit.urlParams = urlParams; 645 | 646 | // String search anywhere in moduleName+testName 647 | config.filter = urlParams.filter; 648 | 649 | // Exact match of the module name 650 | config.module = urlParams.module; 651 | 652 | config.testNumber = parseInt( urlParams.testNumber, 10 ) || null; 653 | 654 | // Figure out if we're running the tests from a server or not 655 | QUnit.isLocal = location.protocol === "file:"; 656 | }()); 657 | 658 | // Export global variables, unless an 'exports' object exists, 659 | // in that case we assume we're in CommonJS (dealt with on the bottom of the script) 660 | if ( typeof exports === "undefined" ) { 661 | extend( window, QUnit ); 662 | 663 | // Expose QUnit object 664 | window.QUnit = QUnit; 665 | } 666 | 667 | // Extend QUnit object, 668 | // these after set here because they should not be exposed as global functions 669 | extend( QUnit, { 670 | config: config, 671 | 672 | // Initialize the configuration options 673 | init: function() { 674 | extend( config, { 675 | stats: { all: 0, bad: 0 }, 676 | moduleStats: { all: 0, bad: 0 }, 677 | started: +new Date(), 678 | updateRate: 1000, 679 | blocking: false, 680 | autostart: true, 681 | autorun: false, 682 | filter: "", 683 | queue: [], 684 | semaphore: 0 685 | }); 686 | 687 | var tests, banner, result, 688 | qunit = id( "qunit" ); 689 | 690 | if ( qunit ) { 691 | qunit.innerHTML = 692 | "

    " + escapeInnerText( document.title ) + "

    " + 693 | "

    " + 694 | "
    " + 695 | "

    " + 696 | "
      "; 697 | } 698 | 699 | tests = id( "qunit-tests" ); 700 | banner = id( "qunit-banner" ); 701 | result = id( "qunit-testresult" ); 702 | 703 | if ( tests ) { 704 | tests.innerHTML = ""; 705 | } 706 | 707 | if ( banner ) { 708 | banner.className = ""; 709 | } 710 | 711 | if ( result ) { 712 | result.parentNode.removeChild( result ); 713 | } 714 | 715 | if ( tests ) { 716 | result = document.createElement( "p" ); 717 | result.id = "qunit-testresult"; 718 | result.className = "result"; 719 | tests.parentNode.insertBefore( result, tests ); 720 | result.innerHTML = "Running...
       "; 721 | } 722 | }, 723 | 724 | // Resets the test setup. Useful for tests that modify the DOM. 725 | reset: function() { 726 | var fixture = id( "qunit-fixture" ); 727 | if ( fixture ) { 728 | fixture.innerHTML = config.fixture; 729 | } 730 | }, 731 | 732 | // Trigger an event on an element. 733 | // @example triggerEvent( document.body, "click" ); 734 | triggerEvent: function( elem, type, event ) { 735 | if ( document.createEvent ) { 736 | event = document.createEvent( "MouseEvents" ); 737 | event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, 738 | 0, 0, 0, 0, 0, false, false, false, false, 0, null); 739 | 740 | elem.dispatchEvent( event ); 741 | } else if ( elem.fireEvent ) { 742 | elem.fireEvent( "on" + type ); 743 | } 744 | }, 745 | 746 | // Safe object type checking 747 | is: function( type, obj ) { 748 | return QUnit.objectType( obj ) == type; 749 | }, 750 | 751 | objectType: function( obj ) { 752 | if ( typeof obj === "undefined" ) { 753 | return "undefined"; 754 | // consider: typeof null === object 755 | } 756 | if ( obj === null ) { 757 | return "null"; 758 | } 759 | 760 | var type = toString.call( obj ).match(/^\[object\s(.*)\]$/)[1] || ""; 761 | 762 | switch ( type ) { 763 | case "Number": 764 | if ( isNaN(obj) ) { 765 | return "nan"; 766 | } 767 | return "number"; 768 | case "String": 769 | case "Boolean": 770 | case "Array": 771 | case "Date": 772 | case "RegExp": 773 | case "Function": 774 | return type.toLowerCase(); 775 | } 776 | if ( typeof obj === "object" ) { 777 | return "object"; 778 | } 779 | return undefined; 780 | }, 781 | 782 | push: function( result, actual, expected, message ) { 783 | if ( !config.current ) { 784 | throw new Error( "assertion outside test context, was " + sourceFromStacktrace() ); 785 | } 786 | 787 | var output, source, 788 | details = { 789 | module: config.current.module, 790 | name: config.current.testName, 791 | result: result, 792 | message: message, 793 | actual: actual, 794 | expected: expected 795 | }; 796 | 797 | message = escapeInnerText( message ) || ( result ? "okay" : "failed" ); 798 | message = "" + message + ""; 799 | output = message; 800 | 801 | if ( !result ) { 802 | expected = escapeInnerText( QUnit.jsDump.parse(expected) ); 803 | actual = escapeInnerText( QUnit.jsDump.parse(actual) ); 804 | output += ""; 805 | 806 | if ( actual != expected ) { 807 | output += ""; 808 | output += ""; 809 | } 810 | 811 | source = sourceFromStacktrace(); 812 | 813 | if ( source ) { 814 | details.source = source; 815 | output += ""; 816 | } 817 | 818 | output += "
      Expected:
      " + expected + "
      Result:
      " + actual + "
      Diff:
      " + QUnit.diff( expected, actual ) + "
      Source:
      " + escapeInnerText( source ) + "
      "; 819 | } 820 | 821 | runLoggingCallbacks( "log", QUnit, details ); 822 | 823 | config.current.assertions.push({ 824 | result: !!result, 825 | message: output 826 | }); 827 | }, 828 | 829 | pushFailure: function( message, source, actual ) { 830 | if ( !config.current ) { 831 | throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) ); 832 | } 833 | 834 | var output, 835 | details = { 836 | module: config.current.module, 837 | name: config.current.testName, 838 | result: false, 839 | message: message 840 | }; 841 | 842 | message = escapeInnerText( message ) || "error"; 843 | message = "" + message + ""; 844 | output = message; 845 | 846 | output += ""; 847 | 848 | if ( actual ) { 849 | output += ""; 850 | } 851 | 852 | if ( source ) { 853 | details.source = source; 854 | output += ""; 855 | } 856 | 857 | output += "
      Result:
      " + escapeInnerText( actual ) + "
      Source:
      " + escapeInnerText( source ) + "
      "; 858 | 859 | runLoggingCallbacks( "log", QUnit, details ); 860 | 861 | config.current.assertions.push({ 862 | result: false, 863 | message: output 864 | }); 865 | }, 866 | 867 | url: function( params ) { 868 | params = extend( extend( {}, QUnit.urlParams ), params ); 869 | var key, 870 | querystring = "?"; 871 | 872 | for ( key in params ) { 873 | if ( !hasOwn.call( params, key ) ) { 874 | continue; 875 | } 876 | querystring += encodeURIComponent( key ) + "=" + 877 | encodeURIComponent( params[ key ] ) + "&"; 878 | } 879 | return window.location.pathname + querystring.slice( 0, -1 ); 880 | }, 881 | 882 | extend: extend, 883 | id: id, 884 | addEvent: addEvent 885 | // load, equiv, jsDump, diff: Attached later 886 | }); 887 | 888 | /** 889 | * @deprecated: Created for backwards compatibility with test runner that set the hook function 890 | * into QUnit.{hook}, instead of invoking it and passing the hook function. 891 | * QUnit.constructor is set to the empty F() above so that we can add to it's prototype here. 892 | * Doing this allows us to tell if the following methods have been overwritten on the actual 893 | * QUnit object. 894 | */ 895 | extend( QUnit.constructor.prototype, { 896 | 897 | // Logging callbacks; all receive a single argument with the listed properties 898 | // run test/logs.html for any related changes 899 | begin: registerLoggingCallback( "begin" ), 900 | 901 | // done: { failed, passed, total, runtime } 902 | done: registerLoggingCallback( "done" ), 903 | 904 | // log: { result, actual, expected, message } 905 | log: registerLoggingCallback( "log" ), 906 | 907 | // testStart: { name } 908 | testStart: registerLoggingCallback( "testStart" ), 909 | 910 | // testDone: { name, failed, passed, total } 911 | testDone: registerLoggingCallback( "testDone" ), 912 | 913 | // moduleStart: { name } 914 | moduleStart: registerLoggingCallback( "moduleStart" ), 915 | 916 | // moduleDone: { name, failed, passed, total } 917 | moduleDone: registerLoggingCallback( "moduleDone" ) 918 | }); 919 | 920 | if ( typeof document === "undefined" || document.readyState === "complete" ) { 921 | config.autorun = true; 922 | } 923 | 924 | QUnit.load = function() { 925 | runLoggingCallbacks( "begin", QUnit, {} ); 926 | 927 | // Initialize the config, saving the execution queue 928 | var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, urlConfigCheckboxes, moduleFilter, 929 | numModules = 0, 930 | moduleFilterHtml = "", 931 | urlConfigHtml = "", 932 | oldconfig = extend( {}, config ); 933 | 934 | QUnit.init(); 935 | extend(config, oldconfig); 936 | 937 | config.blocking = false; 938 | 939 | len = config.urlConfig.length; 940 | 941 | for ( i = 0; i < len; i++ ) { 942 | val = config.urlConfig[i]; 943 | if ( typeof val === "string" ) { 944 | val = { 945 | id: val, 946 | label: val, 947 | tooltip: "[no tooltip available]" 948 | }; 949 | } 950 | config[ val.id ] = QUnit.urlParams[ val.id ]; 951 | urlConfigHtml += ""; 952 | } 953 | 954 | moduleFilterHtml += ""; 962 | 963 | // `userAgent` initialized at top of scope 964 | userAgent = id( "qunit-userAgent" ); 965 | if ( userAgent ) { 966 | userAgent.innerHTML = navigator.userAgent; 967 | } 968 | 969 | // `banner` initialized at top of scope 970 | banner = id( "qunit-header" ); 971 | if ( banner ) { 972 | banner.innerHTML = "" + banner.innerHTML + " "; 973 | } 974 | 975 | // `toolbar` initialized at top of scope 976 | toolbar = id( "qunit-testrunner-toolbar" ); 977 | if ( toolbar ) { 978 | // `filter` initialized at top of scope 979 | filter = document.createElement( "input" ); 980 | filter.type = "checkbox"; 981 | filter.id = "qunit-filter-pass"; 982 | 983 | addEvent( filter, "click", function() { 984 | var tmp, 985 | ol = document.getElementById( "qunit-tests" ); 986 | 987 | if ( filter.checked ) { 988 | ol.className = ol.className + " hidepass"; 989 | } else { 990 | tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " "; 991 | ol.className = tmp.replace( / hidepass /, " " ); 992 | } 993 | if ( defined.sessionStorage ) { 994 | if (filter.checked) { 995 | sessionStorage.setItem( "qunit-filter-passed-tests", "true" ); 996 | } else { 997 | sessionStorage.removeItem( "qunit-filter-passed-tests" ); 998 | } 999 | } 1000 | }); 1001 | 1002 | if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) { 1003 | filter.checked = true; 1004 | // `ol` initialized at top of scope 1005 | ol = document.getElementById( "qunit-tests" ); 1006 | ol.className = ol.className + " hidepass"; 1007 | } 1008 | toolbar.appendChild( filter ); 1009 | 1010 | // `label` initialized at top of scope 1011 | label = document.createElement( "label" ); 1012 | label.setAttribute( "for", "qunit-filter-pass" ); 1013 | label.setAttribute( "title", "Only show tests and assertons that fail. Stored in sessionStorage." ); 1014 | label.innerHTML = "Hide passed tests"; 1015 | toolbar.appendChild( label ); 1016 | 1017 | urlConfigCheckboxes = document.createElement( 'span' ); 1018 | urlConfigCheckboxes.innerHTML = urlConfigHtml; 1019 | addEvent( urlConfigCheckboxes, "change", function( event ) { 1020 | var params = {}; 1021 | params[ event.target.name ] = event.target.checked ? true : undefined; 1022 | window.location = QUnit.url( params ); 1023 | }); 1024 | toolbar.appendChild( urlConfigCheckboxes ); 1025 | 1026 | if (numModules > 1) { 1027 | moduleFilter = document.createElement( 'span' ); 1028 | moduleFilter.setAttribute( 'id', 'qunit-modulefilter-container' ); 1029 | moduleFilter.innerHTML = moduleFilterHtml; 1030 | addEvent( moduleFilter, "change", function() { 1031 | var selectBox = moduleFilter.getElementsByTagName("select")[0], 1032 | selectedModule = decodeURIComponent(selectBox.options[selectBox.selectedIndex].value); 1033 | 1034 | window.location = QUnit.url( { module: ( selectedModule === "" ) ? undefined : selectedModule } ); 1035 | }); 1036 | toolbar.appendChild(moduleFilter); 1037 | } 1038 | } 1039 | 1040 | // `main` initialized at top of scope 1041 | main = id( "qunit-fixture" ); 1042 | if ( main ) { 1043 | config.fixture = main.innerHTML; 1044 | } 1045 | 1046 | if ( config.autostart ) { 1047 | QUnit.start(); 1048 | } 1049 | }; 1050 | 1051 | addEvent( window, "load", QUnit.load ); 1052 | 1053 | // `onErrorFnPrev` initialized at top of scope 1054 | // Preserve other handlers 1055 | onErrorFnPrev = window.onerror; 1056 | 1057 | // Cover uncaught exceptions 1058 | // Returning true will surpress the default browser handler, 1059 | // returning false will let it run. 1060 | window.onerror = function ( error, filePath, linerNr ) { 1061 | var ret = false; 1062 | if ( onErrorFnPrev ) { 1063 | ret = onErrorFnPrev( error, filePath, linerNr ); 1064 | } 1065 | 1066 | // Treat return value as window.onerror itself does, 1067 | // Only do our handling if not surpressed. 1068 | if ( ret !== true ) { 1069 | if ( QUnit.config.current ) { 1070 | if ( QUnit.config.current.ignoreGlobalErrors ) { 1071 | return true; 1072 | } 1073 | QUnit.pushFailure( error, filePath + ":" + linerNr ); 1074 | } else { 1075 | QUnit.test( "global failure", extend( function() { 1076 | QUnit.pushFailure( error, filePath + ":" + linerNr ); 1077 | }, { validTest: validTest } ) ); 1078 | } 1079 | return false; 1080 | } 1081 | 1082 | return ret; 1083 | }; 1084 | 1085 | function done() { 1086 | config.autorun = true; 1087 | 1088 | // Log the last module results 1089 | if ( config.currentModule ) { 1090 | runLoggingCallbacks( "moduleDone", QUnit, { 1091 | name: config.currentModule, 1092 | failed: config.moduleStats.bad, 1093 | passed: config.moduleStats.all - config.moduleStats.bad, 1094 | total: config.moduleStats.all 1095 | }); 1096 | } 1097 | 1098 | var i, key, 1099 | banner = id( "qunit-banner" ), 1100 | tests = id( "qunit-tests" ), 1101 | runtime = +new Date() - config.started, 1102 | passed = config.stats.all - config.stats.bad, 1103 | html = [ 1104 | "Tests completed in ", 1105 | runtime, 1106 | " milliseconds.
      ", 1107 | "", 1108 | passed, 1109 | " tests of ", 1110 | config.stats.all, 1111 | " passed, ", 1112 | config.stats.bad, 1113 | " failed." 1114 | ].join( "" ); 1115 | 1116 | if ( banner ) { 1117 | banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" ); 1118 | } 1119 | 1120 | if ( tests ) { 1121 | id( "qunit-testresult" ).innerHTML = html; 1122 | } 1123 | 1124 | if ( config.altertitle && typeof document !== "undefined" && document.title ) { 1125 | // show ✖ for good, ✔ for bad suite result in title 1126 | // use escape sequences in case file gets loaded with non-utf-8-charset 1127 | document.title = [ 1128 | ( config.stats.bad ? "\u2716" : "\u2714" ), 1129 | document.title.replace( /^[\u2714\u2716] /i, "" ) 1130 | ].join( " " ); 1131 | } 1132 | 1133 | // clear own sessionStorage items if all tests passed 1134 | if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) { 1135 | // `key` & `i` initialized at top of scope 1136 | for ( i = 0; i < sessionStorage.length; i++ ) { 1137 | key = sessionStorage.key( i++ ); 1138 | if ( key.indexOf( "qunit-test-" ) === 0 ) { 1139 | sessionStorage.removeItem( key ); 1140 | } 1141 | } 1142 | } 1143 | 1144 | // scroll back to top to show results 1145 | if ( window.scrollTo ) { 1146 | window.scrollTo(0, 0); 1147 | } 1148 | 1149 | runLoggingCallbacks( "done", QUnit, { 1150 | failed: config.stats.bad, 1151 | passed: passed, 1152 | total: config.stats.all, 1153 | runtime: runtime 1154 | }); 1155 | } 1156 | 1157 | /** @return Boolean: true if this test should be ran */ 1158 | function validTest( test ) { 1159 | var include, 1160 | filter = config.filter && config.filter.toLowerCase(), 1161 | module = config.module && config.module.toLowerCase(), 1162 | fullName = (test.module + ": " + test.testName).toLowerCase(); 1163 | 1164 | // Internally-generated tests are always valid 1165 | if ( test.callback && test.callback.validTest === validTest ) { 1166 | delete test.callback.validTest; 1167 | return true; 1168 | } 1169 | 1170 | if ( config.testNumber ) { 1171 | return test.testNumber === config.testNumber; 1172 | } 1173 | 1174 | if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) { 1175 | return false; 1176 | } 1177 | 1178 | if ( !filter ) { 1179 | return true; 1180 | } 1181 | 1182 | include = filter.charAt( 0 ) !== "!"; 1183 | if ( !include ) { 1184 | filter = filter.slice( 1 ); 1185 | } 1186 | 1187 | // If the filter matches, we need to honour include 1188 | if ( fullName.indexOf( filter ) !== -1 ) { 1189 | return include; 1190 | } 1191 | 1192 | // Otherwise, do the opposite 1193 | return !include; 1194 | } 1195 | 1196 | // so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions) 1197 | // Later Safari and IE10 are supposed to support error.stack as well 1198 | // See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack 1199 | function extractStacktrace( e, offset ) { 1200 | offset = offset === undefined ? 3 : offset; 1201 | 1202 | var stack, include, i, regex; 1203 | 1204 | if ( e.stacktrace ) { 1205 | // Opera 1206 | return e.stacktrace.split( "\n" )[ offset + 3 ]; 1207 | } else if ( e.stack ) { 1208 | // Firefox, Chrome 1209 | stack = e.stack.split( "\n" ); 1210 | if (/^error$/i.test( stack[0] ) ) { 1211 | stack.shift(); 1212 | } 1213 | if ( fileName ) { 1214 | include = []; 1215 | for ( i = offset; i < stack.length; i++ ) { 1216 | if ( stack[ i ].indexOf( fileName ) != -1 ) { 1217 | break; 1218 | } 1219 | include.push( stack[ i ] ); 1220 | } 1221 | if ( include.length ) { 1222 | return include.join( "\n" ); 1223 | } 1224 | } 1225 | return stack[ offset ]; 1226 | } else if ( e.sourceURL ) { 1227 | // Safari, PhantomJS 1228 | // hopefully one day Safari provides actual stacktraces 1229 | // exclude useless self-reference for generated Error objects 1230 | if ( /qunit.js$/.test( e.sourceURL ) ) { 1231 | return; 1232 | } 1233 | // for actual exceptions, this is useful 1234 | return e.sourceURL + ":" + e.line; 1235 | } 1236 | } 1237 | function sourceFromStacktrace( offset ) { 1238 | try { 1239 | throw new Error(); 1240 | } catch ( e ) { 1241 | return extractStacktrace( e, offset ); 1242 | } 1243 | } 1244 | 1245 | function escapeInnerText( s ) { 1246 | if ( !s ) { 1247 | return ""; 1248 | } 1249 | s = s + ""; 1250 | return s.replace( /[\&<>]/g, function( s ) { 1251 | switch( s ) { 1252 | case "&": return "&"; 1253 | case "<": return "<"; 1254 | case ">": return ">"; 1255 | default: return s; 1256 | } 1257 | }); 1258 | } 1259 | 1260 | function synchronize( callback, last ) { 1261 | config.queue.push( callback ); 1262 | 1263 | if ( config.autorun && !config.blocking ) { 1264 | process( last ); 1265 | } 1266 | } 1267 | 1268 | function process( last ) { 1269 | function next() { 1270 | process( last ); 1271 | } 1272 | var start = new Date().getTime(); 1273 | config.depth = config.depth ? config.depth + 1 : 1; 1274 | 1275 | while ( config.queue.length && !config.blocking ) { 1276 | if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) { 1277 | config.queue.shift()(); 1278 | } else { 1279 | window.setTimeout( next, 13 ); 1280 | break; 1281 | } 1282 | } 1283 | config.depth--; 1284 | if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { 1285 | done(); 1286 | } 1287 | } 1288 | 1289 | function saveGlobal() { 1290 | config.pollution = []; 1291 | 1292 | if ( config.noglobals ) { 1293 | for ( var key in window ) { 1294 | // in Opera sometimes DOM element ids show up here, ignore them 1295 | if ( !hasOwn.call( window, key ) || /^qunit-test-output/.test( key ) ) { 1296 | continue; 1297 | } 1298 | config.pollution.push( key ); 1299 | } 1300 | } 1301 | } 1302 | 1303 | function checkPollution( name ) { 1304 | var newGlobals, 1305 | deletedGlobals, 1306 | old = config.pollution; 1307 | 1308 | saveGlobal(); 1309 | 1310 | newGlobals = diff( config.pollution, old ); 1311 | if ( newGlobals.length > 0 ) { 1312 | QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") ); 1313 | } 1314 | 1315 | deletedGlobals = diff( old, config.pollution ); 1316 | if ( deletedGlobals.length > 0 ) { 1317 | QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") ); 1318 | } 1319 | } 1320 | 1321 | // returns a new Array with the elements that are in a but not in b 1322 | function diff( a, b ) { 1323 | var i, j, 1324 | result = a.slice(); 1325 | 1326 | for ( i = 0; i < result.length; i++ ) { 1327 | for ( j = 0; j < b.length; j++ ) { 1328 | if ( result[i] === b[j] ) { 1329 | result.splice( i, 1 ); 1330 | i--; 1331 | break; 1332 | } 1333 | } 1334 | } 1335 | return result; 1336 | } 1337 | 1338 | function extend( a, b ) { 1339 | for ( var prop in b ) { 1340 | if ( b[ prop ] === undefined ) { 1341 | delete a[ prop ]; 1342 | 1343 | // Avoid "Member not found" error in IE8 caused by setting window.constructor 1344 | } else if ( prop !== "constructor" || a !== window ) { 1345 | a[ prop ] = b[ prop ]; 1346 | } 1347 | } 1348 | 1349 | return a; 1350 | } 1351 | 1352 | function addEvent( elem, type, fn ) { 1353 | if ( elem.addEventListener ) { 1354 | elem.addEventListener( type, fn, false ); 1355 | } else if ( elem.attachEvent ) { 1356 | elem.attachEvent( "on" + type, fn ); 1357 | } else { 1358 | fn(); 1359 | } 1360 | } 1361 | 1362 | function id( name ) { 1363 | return !!( typeof document !== "undefined" && document && document.getElementById ) && 1364 | document.getElementById( name ); 1365 | } 1366 | 1367 | function registerLoggingCallback( key ) { 1368 | return function( callback ) { 1369 | config[key].push( callback ); 1370 | }; 1371 | } 1372 | 1373 | // Supports deprecated method of completely overwriting logging callbacks 1374 | function runLoggingCallbacks( key, scope, args ) { 1375 | //debugger; 1376 | var i, callbacks; 1377 | if ( QUnit.hasOwnProperty( key ) ) { 1378 | QUnit[ key ].call(scope, args ); 1379 | } else { 1380 | callbacks = config[ key ]; 1381 | for ( i = 0; i < callbacks.length; i++ ) { 1382 | callbacks[ i ].call( scope, args ); 1383 | } 1384 | } 1385 | } 1386 | 1387 | // Test for equality any JavaScript type. 1388 | // Author: Philippe Rathé 1389 | QUnit.equiv = (function() { 1390 | 1391 | // Call the o related callback with the given arguments. 1392 | function bindCallbacks( o, callbacks, args ) { 1393 | var prop = QUnit.objectType( o ); 1394 | if ( prop ) { 1395 | if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) { 1396 | return callbacks[ prop ].apply( callbacks, args ); 1397 | } else { 1398 | return callbacks[ prop ]; // or undefined 1399 | } 1400 | } 1401 | } 1402 | 1403 | // the real equiv function 1404 | var innerEquiv, 1405 | // stack to decide between skip/abort functions 1406 | callers = [], 1407 | // stack to avoiding loops from circular referencing 1408 | parents = [], 1409 | 1410 | getProto = Object.getPrototypeOf || function ( obj ) { 1411 | return obj.__proto__; 1412 | }, 1413 | callbacks = (function () { 1414 | 1415 | // for string, boolean, number and null 1416 | function useStrictEquality( b, a ) { 1417 | if ( b instanceof a.constructor || a instanceof b.constructor ) { 1418 | // to catch short annotaion VS 'new' annotation of a 1419 | // declaration 1420 | // e.g. var i = 1; 1421 | // var j = new Number(1); 1422 | return a == b; 1423 | } else { 1424 | return a === b; 1425 | } 1426 | } 1427 | 1428 | return { 1429 | "string": useStrictEquality, 1430 | "boolean": useStrictEquality, 1431 | "number": useStrictEquality, 1432 | "null": useStrictEquality, 1433 | "undefined": useStrictEquality, 1434 | 1435 | "nan": function( b ) { 1436 | return isNaN( b ); 1437 | }, 1438 | 1439 | "date": function( b, a ) { 1440 | return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf(); 1441 | }, 1442 | 1443 | "regexp": function( b, a ) { 1444 | return QUnit.objectType( b ) === "regexp" && 1445 | // the regex itself 1446 | a.source === b.source && 1447 | // and its modifers 1448 | a.global === b.global && 1449 | // (gmi) ... 1450 | a.ignoreCase === b.ignoreCase && 1451 | a.multiline === b.multiline && 1452 | a.sticky === b.sticky; 1453 | }, 1454 | 1455 | // - skip when the property is a method of an instance (OOP) 1456 | // - abort otherwise, 1457 | // initial === would have catch identical references anyway 1458 | "function": function() { 1459 | var caller = callers[callers.length - 1]; 1460 | return caller !== Object && typeof caller !== "undefined"; 1461 | }, 1462 | 1463 | "array": function( b, a ) { 1464 | var i, j, len, loop; 1465 | 1466 | // b could be an object literal here 1467 | if ( QUnit.objectType( b ) !== "array" ) { 1468 | return false; 1469 | } 1470 | 1471 | len = a.length; 1472 | if ( len !== b.length ) { 1473 | // safe and faster 1474 | return false; 1475 | } 1476 | 1477 | // track reference to avoid circular references 1478 | parents.push( a ); 1479 | for ( i = 0; i < len; i++ ) { 1480 | loop = false; 1481 | for ( j = 0; j < parents.length; j++ ) { 1482 | if ( parents[j] === a[i] ) { 1483 | loop = true;// dont rewalk array 1484 | } 1485 | } 1486 | if ( !loop && !innerEquiv(a[i], b[i]) ) { 1487 | parents.pop(); 1488 | return false; 1489 | } 1490 | } 1491 | parents.pop(); 1492 | return true; 1493 | }, 1494 | 1495 | "object": function( b, a ) { 1496 | var i, j, loop, 1497 | // Default to true 1498 | eq = true, 1499 | aProperties = [], 1500 | bProperties = []; 1501 | 1502 | // comparing constructors is more strict than using 1503 | // instanceof 1504 | if ( a.constructor !== b.constructor ) { 1505 | // Allow objects with no prototype to be equivalent to 1506 | // objects with Object as their constructor. 1507 | if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) || 1508 | ( getProto(b) === null && getProto(a) === Object.prototype ) ) ) { 1509 | return false; 1510 | } 1511 | } 1512 | 1513 | // stack constructor before traversing properties 1514 | callers.push( a.constructor ); 1515 | // track reference to avoid circular references 1516 | parents.push( a ); 1517 | 1518 | for ( i in a ) { // be strict: don't ensures hasOwnProperty 1519 | // and go deep 1520 | loop = false; 1521 | for ( j = 0; j < parents.length; j++ ) { 1522 | if ( parents[j] === a[i] ) { 1523 | // don't go down the same path twice 1524 | loop = true; 1525 | } 1526 | } 1527 | aProperties.push(i); // collect a's properties 1528 | 1529 | if (!loop && !innerEquiv( a[i], b[i] ) ) { 1530 | eq = false; 1531 | break; 1532 | } 1533 | } 1534 | 1535 | callers.pop(); // unstack, we are done 1536 | parents.pop(); 1537 | 1538 | for ( i in b ) { 1539 | bProperties.push( i ); // collect b's properties 1540 | } 1541 | 1542 | // Ensures identical properties name 1543 | return eq && innerEquiv( aProperties.sort(), bProperties.sort() ); 1544 | } 1545 | }; 1546 | }()); 1547 | 1548 | innerEquiv = function() { // can take multiple arguments 1549 | var args = [].slice.apply( arguments ); 1550 | if ( args.length < 2 ) { 1551 | return true; // end transition 1552 | } 1553 | 1554 | return (function( a, b ) { 1555 | if ( a === b ) { 1556 | return true; // catch the most you can 1557 | } else if ( a === null || b === null || typeof a === "undefined" || 1558 | typeof b === "undefined" || 1559 | QUnit.objectType(a) !== QUnit.objectType(b) ) { 1560 | return false; // don't lose time with error prone cases 1561 | } else { 1562 | return bindCallbacks(a, callbacks, [ b, a ]); 1563 | } 1564 | 1565 | // apply transition with (1..n) arguments 1566 | }( args[0], args[1] ) && arguments.callee.apply( this, args.splice(1, args.length - 1 )) ); 1567 | }; 1568 | 1569 | return innerEquiv; 1570 | }()); 1571 | 1572 | /** 1573 | * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | 1574 | * http://flesler.blogspot.com Licensed under BSD 1575 | * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008 1576 | * 1577 | * @projectDescription Advanced and extensible data dumping for Javascript. 1578 | * @version 1.0.0 1579 | * @author Ariel Flesler 1580 | * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} 1581 | */ 1582 | QUnit.jsDump = (function() { 1583 | function quote( str ) { 1584 | return '"' + str.toString().replace( /"/g, '\\"' ) + '"'; 1585 | } 1586 | function literal( o ) { 1587 | return o + ""; 1588 | } 1589 | function join( pre, arr, post ) { 1590 | var s = jsDump.separator(), 1591 | base = jsDump.indent(), 1592 | inner = jsDump.indent(1); 1593 | if ( arr.join ) { 1594 | arr = arr.join( "," + s + inner ); 1595 | } 1596 | if ( !arr ) { 1597 | return pre + post; 1598 | } 1599 | return [ pre, inner + arr, base + post ].join(s); 1600 | } 1601 | function array( arr, stack ) { 1602 | var i = arr.length, ret = new Array(i); 1603 | this.up(); 1604 | while ( i-- ) { 1605 | ret[i] = this.parse( arr[i] , undefined , stack); 1606 | } 1607 | this.down(); 1608 | return join( "[", ret, "]" ); 1609 | } 1610 | 1611 | var reName = /^function (\w+)/, 1612 | jsDump = { 1613 | parse: function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance 1614 | stack = stack || [ ]; 1615 | var inStack, res, 1616 | parser = this.parsers[ type || this.typeOf(obj) ]; 1617 | 1618 | type = typeof parser; 1619 | inStack = inArray( obj, stack ); 1620 | 1621 | if ( inStack != -1 ) { 1622 | return "recursion(" + (inStack - stack.length) + ")"; 1623 | } 1624 | //else 1625 | if ( type == "function" ) { 1626 | stack.push( obj ); 1627 | res = parser.call( this, obj, stack ); 1628 | stack.pop(); 1629 | return res; 1630 | } 1631 | // else 1632 | return ( type == "string" ) ? parser : this.parsers.error; 1633 | }, 1634 | typeOf: function( obj ) { 1635 | var type; 1636 | if ( obj === null ) { 1637 | type = "null"; 1638 | } else if ( typeof obj === "undefined" ) { 1639 | type = "undefined"; 1640 | } else if ( QUnit.is( "regexp", obj) ) { 1641 | type = "regexp"; 1642 | } else if ( QUnit.is( "date", obj) ) { 1643 | type = "date"; 1644 | } else if ( QUnit.is( "function", obj) ) { 1645 | type = "function"; 1646 | } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) { 1647 | type = "window"; 1648 | } else if ( obj.nodeType === 9 ) { 1649 | type = "document"; 1650 | } else if ( obj.nodeType ) { 1651 | type = "node"; 1652 | } else if ( 1653 | // native arrays 1654 | toString.call( obj ) === "[object Array]" || 1655 | // NodeList objects 1656 | ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) ) 1657 | ) { 1658 | type = "array"; 1659 | } else { 1660 | type = typeof obj; 1661 | } 1662 | return type; 1663 | }, 1664 | separator: function() { 1665 | return this.multiline ? this.HTML ? "
      " : "\n" : this.HTML ? " " : " "; 1666 | }, 1667 | indent: function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing 1668 | if ( !this.multiline ) { 1669 | return ""; 1670 | } 1671 | var chr = this.indentChar; 1672 | if ( this.HTML ) { 1673 | chr = chr.replace( /\t/g, " " ).replace( / /g, " " ); 1674 | } 1675 | return new Array( this._depth_ + (extra||0) ).join(chr); 1676 | }, 1677 | up: function( a ) { 1678 | this._depth_ += a || 1; 1679 | }, 1680 | down: function( a ) { 1681 | this._depth_ -= a || 1; 1682 | }, 1683 | setParser: function( name, parser ) { 1684 | this.parsers[name] = parser; 1685 | }, 1686 | // The next 3 are exposed so you can use them 1687 | quote: quote, 1688 | literal: literal, 1689 | join: join, 1690 | // 1691 | _depth_: 1, 1692 | // This is the list of parsers, to modify them, use jsDump.setParser 1693 | parsers: { 1694 | window: "[Window]", 1695 | document: "[Document]", 1696 | error: "[ERROR]", //when no parser is found, shouldn"t happen 1697 | unknown: "[Unknown]", 1698 | "null": "null", 1699 | "undefined": "undefined", 1700 | "function": function( fn ) { 1701 | var ret = "function", 1702 | name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];//functions never have name in IE 1703 | 1704 | if ( name ) { 1705 | ret += " " + name; 1706 | } 1707 | ret += "( "; 1708 | 1709 | ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" ); 1710 | return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" ); 1711 | }, 1712 | array: array, 1713 | nodelist: array, 1714 | "arguments": array, 1715 | object: function( map, stack ) { 1716 | var ret = [ ], keys, key, val, i; 1717 | QUnit.jsDump.up(); 1718 | if ( Object.keys ) { 1719 | keys = Object.keys( map ); 1720 | } else { 1721 | keys = []; 1722 | for ( key in map ) { 1723 | keys.push( key ); 1724 | } 1725 | } 1726 | keys.sort(); 1727 | for ( i = 0; i < keys.length; i++ ) { 1728 | key = keys[ i ]; 1729 | val = map[ key ]; 1730 | ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) ); 1731 | } 1732 | QUnit.jsDump.down(); 1733 | return join( "{", ret, "}" ); 1734 | }, 1735 | node: function( node ) { 1736 | var a, val, 1737 | open = QUnit.jsDump.HTML ? "<" : "<", 1738 | close = QUnit.jsDump.HTML ? ">" : ">", 1739 | tag = node.nodeName.toLowerCase(), 1740 | ret = open + tag; 1741 | 1742 | for ( a in QUnit.jsDump.DOMAttrs ) { 1743 | val = node[ QUnit.jsDump.DOMAttrs[a] ]; 1744 | if ( val ) { 1745 | ret += " " + a + "=" + QUnit.jsDump.parse( val, "attribute" ); 1746 | } 1747 | } 1748 | return ret + close + open + "/" + tag + close; 1749 | }, 1750 | functionArgs: function( fn ) {//function calls it internally, it's the arguments part of the function 1751 | var args, 1752 | l = fn.length; 1753 | 1754 | if ( !l ) { 1755 | return ""; 1756 | } 1757 | 1758 | args = new Array(l); 1759 | while ( l-- ) { 1760 | args[l] = String.fromCharCode(97+l);//97 is 'a' 1761 | } 1762 | return " " + args.join( ", " ) + " "; 1763 | }, 1764 | key: quote, //object calls it internally, the key part of an item in a map 1765 | functionCode: "[code]", //function calls it internally, it's the content of the function 1766 | attribute: quote, //node calls it internally, it's an html attribute value 1767 | string: quote, 1768 | date: quote, 1769 | regexp: literal, //regex 1770 | number: literal, 1771 | "boolean": literal 1772 | }, 1773 | DOMAttrs: { 1774 | //attributes to dump from nodes, name=>realName 1775 | id: "id", 1776 | name: "name", 1777 | "class": "className" 1778 | }, 1779 | HTML: false,//if true, entities are escaped ( <, >, \t, space and \n ) 1780 | indentChar: " ",//indentation unit 1781 | multiline: true //if true, items in a collection, are separated by a \n, else just a space. 1782 | }; 1783 | 1784 | return jsDump; 1785 | }()); 1786 | 1787 | // from Sizzle.js 1788 | function getText( elems ) { 1789 | var i, elem, 1790 | ret = ""; 1791 | 1792 | for ( i = 0; elems[i]; i++ ) { 1793 | elem = elems[i]; 1794 | 1795 | // Get the text from text nodes and CDATA nodes 1796 | if ( elem.nodeType === 3 || elem.nodeType === 4 ) { 1797 | ret += elem.nodeValue; 1798 | 1799 | // Traverse everything else, except comment nodes 1800 | } else if ( elem.nodeType !== 8 ) { 1801 | ret += getText( elem.childNodes ); 1802 | } 1803 | } 1804 | 1805 | return ret; 1806 | } 1807 | 1808 | // from jquery.js 1809 | function inArray( elem, array ) { 1810 | if ( array.indexOf ) { 1811 | return array.indexOf( elem ); 1812 | } 1813 | 1814 | for ( var i = 0, length = array.length; i < length; i++ ) { 1815 | if ( array[ i ] === elem ) { 1816 | return i; 1817 | } 1818 | } 1819 | 1820 | return -1; 1821 | } 1822 | 1823 | /* 1824 | * Javascript Diff Algorithm 1825 | * By John Resig (http://ejohn.org/) 1826 | * Modified by Chu Alan "sprite" 1827 | * 1828 | * Released under the MIT license. 1829 | * 1830 | * More Info: 1831 | * http://ejohn.org/projects/javascript-diff-algorithm/ 1832 | * 1833 | * Usage: QUnit.diff(expected, actual) 1834 | * 1835 | * QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the quick brown fox jumped jumps over" 1836 | */ 1837 | QUnit.diff = (function() { 1838 | function diff( o, n ) { 1839 | var i, 1840 | ns = {}, 1841 | os = {}; 1842 | 1843 | for ( i = 0; i < n.length; i++ ) { 1844 | if ( ns[ n[i] ] == null ) { 1845 | ns[ n[i] ] = { 1846 | rows: [], 1847 | o: null 1848 | }; 1849 | } 1850 | ns[ n[i] ].rows.push( i ); 1851 | } 1852 | 1853 | for ( i = 0; i < o.length; i++ ) { 1854 | if ( os[ o[i] ] == null ) { 1855 | os[ o[i] ] = { 1856 | rows: [], 1857 | n: null 1858 | }; 1859 | } 1860 | os[ o[i] ].rows.push( i ); 1861 | } 1862 | 1863 | for ( i in ns ) { 1864 | if ( !hasOwn.call( ns, i ) ) { 1865 | continue; 1866 | } 1867 | if ( ns[i].rows.length == 1 && typeof os[i] != "undefined" && os[i].rows.length == 1 ) { 1868 | n[ ns[i].rows[0] ] = { 1869 | text: n[ ns[i].rows[0] ], 1870 | row: os[i].rows[0] 1871 | }; 1872 | o[ os[i].rows[0] ] = { 1873 | text: o[ os[i].rows[0] ], 1874 | row: ns[i].rows[0] 1875 | }; 1876 | } 1877 | } 1878 | 1879 | for ( i = 0; i < n.length - 1; i++ ) { 1880 | if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null && 1881 | n[ i + 1 ] == o[ n[i].row + 1 ] ) { 1882 | 1883 | n[ i + 1 ] = { 1884 | text: n[ i + 1 ], 1885 | row: n[i].row + 1 1886 | }; 1887 | o[ n[i].row + 1 ] = { 1888 | text: o[ n[i].row + 1 ], 1889 | row: i + 1 1890 | }; 1891 | } 1892 | } 1893 | 1894 | for ( i = n.length - 1; i > 0; i-- ) { 1895 | if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null && 1896 | n[ i - 1 ] == o[ n[i].row - 1 ]) { 1897 | 1898 | n[ i - 1 ] = { 1899 | text: n[ i - 1 ], 1900 | row: n[i].row - 1 1901 | }; 1902 | o[ n[i].row - 1 ] = { 1903 | text: o[ n[i].row - 1 ], 1904 | row: i - 1 1905 | }; 1906 | } 1907 | } 1908 | 1909 | return { 1910 | o: o, 1911 | n: n 1912 | }; 1913 | } 1914 | 1915 | return function( o, n ) { 1916 | o = o.replace( /\s+$/, "" ); 1917 | n = n.replace( /\s+$/, "" ); 1918 | 1919 | var i, pre, 1920 | str = "", 1921 | out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ), 1922 | oSpace = o.match(/\s+/g), 1923 | nSpace = n.match(/\s+/g); 1924 | 1925 | if ( oSpace == null ) { 1926 | oSpace = [ " " ]; 1927 | } 1928 | else { 1929 | oSpace.push( " " ); 1930 | } 1931 | 1932 | if ( nSpace == null ) { 1933 | nSpace = [ " " ]; 1934 | } 1935 | else { 1936 | nSpace.push( " " ); 1937 | } 1938 | 1939 | if ( out.n.length === 0 ) { 1940 | for ( i = 0; i < out.o.length; i++ ) { 1941 | str += "" + out.o[i] + oSpace[i] + ""; 1942 | } 1943 | } 1944 | else { 1945 | if ( out.n[0].text == null ) { 1946 | for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) { 1947 | str += "" + out.o[n] + oSpace[n] + ""; 1948 | } 1949 | } 1950 | 1951 | for ( i = 0; i < out.n.length; i++ ) { 1952 | if (out.n[i].text == null) { 1953 | str += "" + out.n[i] + nSpace[i] + ""; 1954 | } 1955 | else { 1956 | // `pre` initialized at top of scope 1957 | pre = ""; 1958 | 1959 | for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) { 1960 | pre += "" + out.o[n] + oSpace[n] + ""; 1961 | } 1962 | str += " " + out.n[i].text + nSpace[i] + pre; 1963 | } 1964 | } 1965 | } 1966 | 1967 | return str; 1968 | }; 1969 | }()); 1970 | 1971 | // for CommonJS enviroments, export everything 1972 | if ( typeof exports !== "undefined" ) { 1973 | extend(exports, QUnit); 1974 | } 1975 | 1976 | // get at whatever the global object is, like window in browsers 1977 | }( (function() {return this;}.call()) )); 1978 | -------------------------------------------------------------------------------- /tests/lib/History.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | qunit/History.md at v1.10.0 · jquery/qunit 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
      52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
      61 |
      62 | 63 | 64 | 65 | 66 | 67 |
      68 | 69 | 70 | 71 | 72 | 73 |
      74 | 75 | 76 | 77 |
      78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 |
      90 | 91 | 92 | 98 |
      99 | 100 | 101 | 102 | 103 | 104 | 128 | 129 | 130 | 131 | 132 |
      133 |
      134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 |
      142 |
      143 | 144 |
      145 |
      146 |
      147 | 148 | 149 | 150 |
        151 | 152 |
      • 153 |
        154 |
        155 | 156 | 157 | Watch 158 | 159 | 160 | 161 |
        162 | 163 |
        Notification status
        164 | 165 |
        166 |
          167 |
        • 168 | 169 | 174 | 175 | 176 | Watch 177 | 178 |
        • 179 |
        • 180 | 181 | 186 | 187 | 188 | Unwatch 189 | 190 |
        • 191 |
        • 192 | 193 | 198 | 199 | 200 | Stop ignoring 201 | 202 |
        • 203 |
        204 |
        205 |
        206 |
        207 |
        208 |
      • 209 | 210 |
      • 211 | 212 | Unstar 213 | 214 | Star 215 | 216 |
      • 217 | 218 |
      • 219 | Fork 220 |
      • 221 | 222 | 223 |
      224 | 225 |

      226 | public 227 | 228 | 229 | / 232 | qunit 233 |

      234 |
      235 | 236 | 237 | 238 | 251 | 252 |
      253 | 254 | 255 | 258 | 259 | 260 | 261 |
      262 | 263 | 264 |
      265 | 266 | 267 | tag: 268 | v1.10.0 269 | 270 | 271 |
      272 | 273 |
      274 |
      275 | Switch branches/tags 276 | 277 |
      278 | 279 |
      280 |
      281 | 282 |
      283 |
      284 | 292 |
      293 |
      294 | 295 |
      296 | 297 | 298 | 299 |
      300 | 301 | 302 | cli 303 | 304 |
      305 | 306 | 307 | 308 |
      309 | 310 | 311 | gh-pages 312 | 313 |
      314 | 315 | 316 | 317 |
      318 | 319 | 320 | master 321 | 322 |
      323 | 324 | 325 |
      Nothing to show
      326 |
      327 | 328 | 329 | 395 | 396 |
      397 |
      398 |
      399 | 400 |
      401 | 402 | 407 | 408 |
      409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 |
      417 |
      418 | 419 |
      420 | 421 | 422 | 423 | 424 | 425 | 426 |
      427 | 428 | 429 |
      430 | 431 | 432 | 435 | 436 | 437 | 438 | 439 |
      440 | 441 | 442 | 443 |
      444 | Release 1.10.0 445 |
      446 | 447 |
      448 |

      1 contributor

      449 | 450 |
      451 | 460 |
      461 | 462 | 463 |
      464 | 465 |
      466 |
      467 | 468 |
      469 |
      470 |
      471 |
      472 | 473 | file 474 | 463 lines (443 sloc) 475 | 36.028 kb 476 |
      477 | 486 | 487 |
      488 | 489 |
      490 |

      491 | 1.10.0 / 2012-08-30

      492 | 493 |
        494 |
      • Simplify licensing: Only MIT, no more MIT/GPL dual licensing.
      • 495 |
      • Scroll the window back to top after tests finished running. Fixes #304
      • 496 |
      • Simplify phantomjs runner to use module property in testDone callback
      • 497 |
      • Adds module and test name to the information that is returned in the callback provided to QUnit.log(Function). Fixes #296
      • 498 |
      • Make QUnit.expect() (without arguments) a getter. Fixes #226
      • 499 |
      • Compare the ES6 sticky (y) property for RegExp. Can't add to tests yet. Fixes #284 - deepEqual for RegExp should compare
      • 500 |
      • onerror: force display of global errors despite URL parameters. Fixes #288 - Global failures can be filtered out by test-limiting URL parameters
      • 501 |
      • Remove conditional codepath based on jQuery presence from reset().
      • 502 |
      • Add module filter to UI
      • 503 |
      • Keep a local reference to Date. Fixes #283.
      • 504 |
      • Update copyright to jQuery Foundation.
      • 505 |

      506 | 1.9.0 / 2012-07-11

      507 | 508 |
        509 |
      • added jsdoc for QUnit.assert functions
      • 510 |
      • Styling: radius to 5px and small pass/error border, remove inner shadow
      • 511 |
      • Move checkboxes into toolbar and give them labels and descriptions (as tooltip). Fixes #274 - Improve urlFilter API and UI
      • 512 |
      • Where we recieve no exception in throws() use a relevant message.
      • 513 |
      • Also make module filter case-insensitive. Follow-up to #252
      • 514 |
      • Banner: Link should ignore "testNumber" and "module". Fixes #270
      • 515 |
      • Rename assert.raises to assert.throws. Fixes #267
      • 516 |
      • Change package.json name property to 'qunitjs' to avoid conflicht with node-qunit; will publish next release to npm
      • 517 |

      518 | 1.8.0 / 2012-06-14

      519 | 520 |
        521 |
      • Improve window.onerror handling
      • 522 |
      • (issue #260) config.current should be reset at the right time.
      • 523 |
      • Filter: Implement 'module' url parameter. Fixes #252
      • 524 |
      • raises: ignore global exceptions stemming from test. Fixes #257 - Globally-executed errors sneak past raises in IE
      • 525 |

      526 | 1.7.0 / 2012-06-07

      527 | 528 |
        529 |
      • Add config.requireExpects. Fixes #207 - Add option to require all tests to call expect().
      • 530 |
      • Improve extractStacktrace() implementation. Fixes #254 - Include all relevant stack lines
      • 531 |
      • Make filters case-insensitive. Partial fix for #252
      • 532 |
      • is() expects lowercase types. Fixes #250 - Expected Date value is not displayed properly
      • 533 |
      • Fix phantomjs addon header and add readme. Fixes #239
      • 534 |
      • Add some hints to composite addon readme. Fixes #251
      • 535 |
      • 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.
      • 536 |
      • Use QUnit.push for raises implementation. Fixes #243
      • 537 |
      • CLI runner for phantomjs
      • 538 |
      • Fix jshint validation until they deal with /** */ comments properly
      • 539 |
      • Update validTest() : Simplify logic, clarify vars and add comments
      • 540 |
      • Refactor assertion helpers into QUnit.assert (backwards compatible)
      • 541 |
      • Add Rerun link to placeholders. Fixes #240
      • 542 |

      543 | 1.6.0 / 2012-05-04

      544 | 545 |
        546 |
      • Save stack for each test, use that for failed expect() results, points at the line where test() was called. Fixes #209
      • 547 |
      • Prefix test-output id and ignore that in noglobals check. Fixes #212
      • 548 |
      • Only check for an exports object to detect a CommonJS enviroment. Fixes #237 - Incompatibility with require.js
      • 549 |
      • Add testswarm integration as grunt task
      • 550 |
      • Added padding on URL config checkboxes.
      • 551 |
      • 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
      • 552 |
      • Cleanup reset() test and usage - run testDone callback first, to allow listeneres ignoring reset assertions
      • 553 |
      • Double clicking on composite test rows opens individual test page
      • 554 |
      • test-message for all message-bearing API reporting details
      • 555 |

      556 | 1.5.0 / 2012-04-04

      557 | 558 |
        559 |
      • Modify "Running..." to display test name. Fixes #220
      • 560 |
      • Fixed clearing of sessionStorage in Firefox 3.6.
      • 561 |
      • Fixes #217 by calling "block" with config.current.testEnvironment
      • 562 |
      • Add stats results to data. QUnit.jUnitReport function take one argument { xml:'<?xml ...', results:{failed:0, passed:0, total:0, time:0} }
      • 563 |
      • Add link to MDN about stack property
      • 564 |

      565 | 1.4.0 / 2012-03-10

      566 | 567 |
        568 |
      • Prefix test-related session-storage items to make removal more specific. Fixes #213 - Keep hide-passed state when clearing session storage
      • 569 |
      • Update grunt.js with seperate configs for qunit.js and grunt.js, also add tests but disable for now, not passing yet. Add grunt to devDependencies
      • 570 |
      • typo
      • 571 |
      • Cleanup grunt.js, no need for the banner
      • 572 |
      • Fix lint errors and some formatting issues. Use QUnit.pushFailure for noglobals and global error handler.
      • 573 |
      • Fix a missing expect in logs test
      • 574 |
      • Add grunt.js configuration and include some usage instructions in the readme
      • 575 |
      • Update package.json
      • 576 |
      • Partially revert af27eae841c3e1c01c46de72d676f1047e1ee375 - can't move reset around, so also don't wrap in try-catch, as the result of that is effectively swallowed. Can't output the result as the outputting is already done.
      • 577 |
      • Add QUnit.pushFailure to log error conditions like exceptions. Accepts stacktrace as second argument, allowing extraction with catched exceptions (useful even in Safari). Remove old fail() function that would just log to console, not useful anymore as regular test output is much more useful by now. Move up QUnit.reset() call to just make that another failed assertion. Used to not make a test fail. Fixes #210
      • 578 |
      • Update equals and same deprecations to use QUnit.push to provide correct source lines. Fixes #211
      • 579 |
      • Add a test file for narwhal integration. Has to use print instead of console.log. Fails when an assertion fails, something about setInterval...
      • 580 |
      • Apply notrycatch option to setup and teardown as well. Fixes #203. Reorder noglobals check to allow teardown to remove globals that were introduced intentionally. Fixes #204
      • 581 |
      • Extend exports object with QUnit properties at the end of the file to export everything.
      • 582 |
      • Output source line for ok() assertions. Fixes #202
      • 583 |
      • Make test fail if no assertions run. Fixes #178
      • 584 |
      • Sort object output alphabetically in order to improve diffs of objects where properties were set in a different order. Fixes #206
      • 585 |
      • Revert "Change fixture reset behavior", changing #194 and #195 to wontfix.
      • 586 |

      587 | 1.3.0 / 2012-02-26

      588 | 589 |
        590 |
      • Cleanup test markup
      • 591 |
      • Fix the jQuery branch of fixture reset. Would break when no fixture exists.
      • 592 |
      • Added initial version of a junitlogger addon.
      • 593 |
      • Escape document.title before inserting into markup. Extends fix for #127
      • 594 |
      • Catch assertions running outside of test() context, make sure source is provided even for ok(). Fixes #98
      • 595 |
      • Improve global object access, based on comments for 1a9120651d5464773256d8a1f2cf2eabe38ea5b3
      • 596 |
      • Clear all sessionStorage entries once all tests passed. Helps getting rid of items from renamed tests. Fixes #101
      • 597 |
      • Set fixed dimensions for #qunit-fixture. Fixes #114
      • 598 |
      • Extend nodejs test runner to check for stacktrace output, twice
      • 599 |
      • Extend nodejs test runner to check for stacktrace output
      • 600 |
      • Generate more base markup, but allow the user to exclude that completelty or choose their own. Fixes #127
      • 601 |
      • Add a simple test file to check basic nodejs integration works
      • 602 |
      • Check for global object to find setTimeout in node
      • 603 |
      • Fix CommonJS export by assigning QUnit to module.exports.
      • 604 |
      • Remove the testEnviromentArg to test(). Most obscure, never used anywhere. test() is still heavily overloaded with argument shifting, this makes it a little more sane. Fixes #172
      • 605 |
      • Serialize expected and actual values only when test fails. Speeds up output of valid tests, especially for lots of large objects. Fixes #183
      • 606 |
      • Fix sourceFromsTacktrace to get the right line in Firefox. Shift the 'error' line away in Chrome to get a match.
      • 607 |
      • Fix references to test/deepEqual.js
      • 608 |
      • In autorun mode, moduleDone is called without matching moduleStart. Fix issue #184
      • 609 |
      • Fixture test: allow anything falsy in test as getAttribute in oldIE will return empty string instead of null. We don't really care.
      • 610 |
      • Keep label and checkbox together ( http://i.imgur.com/5Wk3A.png )
      • 611 |
      • Add readme for themes
      • 612 |
      • Fix bad global in reset()
      • 613 |
      • Some cleanup in theme addons
      • 614 |
      • Update headers
      • 615 |
      • Update nv.html, add gabe theme based on https://github.com/jquery/qunit/pull/188 616 |
      • 617 |
      • Experiemental custom theme based on https://github.com/jquery/qunit/pull/62 by NV
      • 618 |
      • Replace deprecated same and equals aliases with placeholders that just throw errors, providing a hint at what to use instead. Rename test file to match that.
      • 619 |
      • Can't rely on outerHTML for Firefox < 11. Use cloneNode instead.
      • 620 |
      • Merge remote branch 'conzett/master'
      • 621 |
      • Cleanup whitespace
      • 622 |
      • Update sessionStorage support test to latest version from Modernizr, trying to setItem to avoid QUOTA_EXCEEDED_EXCEPTION
      • 623 |
      • Change fixture reset behavior
      • 624 |
      • Merge pull request #181 from simonz/development
      • 625 |
      • Escaping test names
      • 626 |
      • Show exception stack when test failed
      • 627 |

      628 | 1.2.0 / 2011-11-24

      629 | 630 |
        631 |
      • remove uses of equals(), as it's deprecated in favor of equal()
      • 632 |
      • Code review of "Allow objects with no prototype to be tested against object literals."
      • 633 |
      • Allow objects with no prototype to tested against object literals.
      • 634 |
      • Fix IE8 "Member not found" error
      • 635 |
      • Using node-qunit port, the start/stop function are not exposed so we need to prefix any call to them with 'QUnit'. Aka: start() -> QUnit.start()
      • 636 |
      • 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
      • 637 |
      • Fix globals in test.js, part 2
      • 638 |
      • Fix globals in test.js. ?tell wwalser to use ?noglobals everyonce in a while
      • 639 |
      • Extend readme regarding release process
      • 640 |

      641 | 1.1.0 / 2011-10-11

      642 | 643 |
        644 |
      • Fixes #134 - Add a window.onerror handler. Makes uncaught errors actually fail the testsuite, instead of going by unnoticed.
      • 645 |
      • Whitespace cleanup
      • 646 |
      • Merge remote branch 'trevorparscal/master'
      • 647 |
      • 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.
      • 648 |
      • Update readme with basic notes on releases
      • 649 |
      • More whitespace/parens cleanup
      • 650 |
      • Check if setTimeout is available before trying to delay running the next task. Fixes #160
      • 651 |
      • Whitespace/formatting fix, remove unnecessary parens
      • 652 |
      • Use alias for Object.prototype.toString
      • 653 |
      • Merge remote branch 'trevorparscal/master'
      • 654 |
      • Merge remote branch 'wwalser/recursionBug'
      • 655 |
      • Default 'expected' to null in asyncTest(), same as in test() itself.
      • 656 |
      • Whitespace cleanup
      • 657 |
      • Merge remote branch 'mmchaney/master'
      • 658 |
      • Merge remote branch 'Krinkle/master'
      • 659 |
      • Using === instead of ==
      • 660 |
      • Added more strict array type detection for dump output, and allowed NodeList objects to be output as arrays
      • 661 |
      • Fixes a bug where after an async test, assertions could move between test cases because of internal state (config.current) being incorrectly set
      • 662 |
      • Simplified check for assertion count and adjusted whitespace
      • 663 |
      • 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é!).
      • 664 |
      • Handle expect(0) as expected, i.e. expect(0); ok(true, foo); will cause a test to fail
      • 665 |

      666 | 1.0.0 / 2011-10-06

      667 | 668 |
        669 |
      • Make QUnit work with TestSwarm
      • 670 |
      • Run other addons tests as composite addon demo. Need to move that to /test folder once this setup actually works
      • 671 |
      • Add-on: New assertion-type: step()
      • 672 |
      • added parameter to start and stop allowing a user to increment/decrement the semaphore more than once per call
      • 673 |
      • Update readmes with .md extension for GitHub to render them as markdown
      • 674 |
      • Update close-enough addon to include readme and match (new) naming convetions
      • 675 |
      • Merge remote branch 'righi/close-enough-addon'
      • 676 |
      • Canvas addon: Update file referneces
      • 677 |
      • Update canvas addon: Rename files and add README
      • 678 |
      • Merge remote branch 'wwalser/composite'
      • 679 |
      • Fix #142 - Backslash characters in messages should not be escaped
      • 680 |
      • Add module name to testStart and testDone callbacks
      • 681 |
      • Removed extra columns in object literals. Closes #153
      • 682 |
      • Remove dead links in comments.
      • 683 |
      • Merge remote branch 'wwalser/multipleCallbacks'
      • 684 |
      • Fixed syntax error and CommonJS incompatibilities in package.json
      • 685 |
      • Allow multiple callbacks to be registered.
      • 686 |
      • Add placeholder for when Safari may end up providing useful error handling
      • 687 |
      • changed file names to match addon naming convention
      • 688 |
      • Whitespace
      • 689 |
      • Created the composite addon.
      • 690 |
      • Using array and object literals.
      • 691 |
      • Issue #140: Make toggle system configurable.
      • 692 |
      • Merge remote branch 'tweetdeck/master'
      • 693 |
      • Adds the 'close enough' addon to determine if numbers are acceptably close enough in value.
      • 694 |
      • Fix recursion support in jsDump, along with tests. Fixes #63 and #100
      • 695 |
      • Adding a QUnit.config.altertitle flag which will allow users to opt-out of the functionality introduced in 60147ca0164e3d810b8a9bf46981c3d9cc569efc
      • 696 |
      • Refactor window.load handler into QUnit.load, makes it possible to call it manually.
      • 697 |
      • More whitespace cleanup
      • 698 |
      • Merge remote branch 'erikvold/one-chk-in-title'
      • 699 |
      • Whitespace
      • 700 |
      • Merge remote branch 'wwalser/syncStopCalls'
      • 701 |
      • Introducing the first QUnit addon, based on https://github.com/jquery/qunit/pull/84 - adds QUnit.pixelEqual assertion method, along with example tests.
      • 702 |
      • Remove config.hidepassed setting in test.js, wasn't intended to land in master.
      • 703 |
      • Expose QUnit.config.hidepassed setting. Overrides sessionStorage and enables enabling the feature programmatically. Fixes #133
      • 704 |
      • Fix formatting (css whitespace) for tracebacks.
      • 705 |
      • Expose extend, id, and addEvent methods.
      • 706 |
      • minor comment typo correction
      • 707 |
      • Ignore Eclipse WTP .settings
      • 708 |
      • Set 'The jQuery Project' as author in package.json
      • 709 |
      • Fixes a bug where synchronous calls to stop would cause tests to end before start was called again
      • 710 |
      • Point to planning testing wiki in readme
      • 711 |
      • only add one checkmark to the document.title
      • 712 |
      • Escape the stacktrace output before setting it as innerHTML, since it tends to contain < and > characters.
      • 713 |
      • Cleanup whitespace
      • 714 |
      • Run module.teardown before checking for pollution. Fixes #109 - noglobals should run after module teardown
      • 715 |
      • Fix accidental global variable "not"
      • 716 |
      • Update document.title status to use more robust unicode escape sequences, works even when served with non-utf-8-charset.
      • 717 |
      • 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.
      • 718 |
      • Merge pull request #107 from sexyprout/master
      • 719 |
      • Set a generic font
      • 720 |
      • Add/update headers
      • 721 |
      • Drop support for deprecated #main in favor of #qunit-fixture. If this breaks your testsuite, replace id="main" with id="qunit-fixture". Fixes #103
      • 722 |
      • Remove the same key as the one being set. Partial fix for #101
      • 723 |
      • 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.
      • 724 |
      • Fix order of noglobals check to produce correct introduced/delete error messages
      • 725 |
      • Prepend module name to sessionStorage keys to avoid conflicts
      • 726 |
      • Store filter-tests only when checked
      • 727 |
      • Write to sessionStorage only bad tests
      • 728 |
      • Moved QUnit.url() defintion after QUnit properties are merged into the global scope. Fixes #93 - QUnit url/extend function breaking urls in jQuery ajax test component
      • 729 |
      • Add a "Rerun" link to each test to replce the dblclick (still supported, for now).
      • 730 |
      • Fixed the regex for parsing the name of a test when double clicking to filter.
      • 731 |
      • Merge remote branch 'scottgonzalez/url'
      • 732 |
      • Added checkboxes to show which flags are currently on and allow toggling them.
      • 733 |
      • Retain all querystring parameters when filtering a test via double click.
      • 734 |
      • 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.
      • 735 |
      • Make reordering optional (QUnit.config.reorder = false) and optimize "Hide passed tests" mode by also hiding "Running [testname]" entries.
      • 736 |
      • Added missing semicolons and wrapped undefined key in quotes.
      • 737 |
      • Optimize test hiding, add class on page load if stored in sessionStorage
      • 738 |
      • Optimize the hiding of passed tests.
      • 739 |
      • Position test results above test list, making it visible without ever having to scroll. Create a placeholder to avoid pushing down results later.
      • 740 |
      • Don't check for existing qunit-testresult element, it gets killed on init anyway.
      • 741 |
      • 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
      • 742 |
      • Always show quni-toolbar (if at all specified), persist checkbox via sessionStorage. Fixes #47
      • 743 |
      • Use non-html testname for calls to fail(). Fixes #77
      • 744 |
      • Overhaul of QUnit.callbacks. Consistent single argument with related properties, with additonal runtime property for QUnit.done
      • 745 |
      • Extended test/logs.html to capture more of the callbacks.
      • 746 |
      • Fixed moduleStart/Done callbacks. Added test/logs.html to test these callbacks. To be extended.
      • 747 |
      • Update copyright and license header. Fixes #61
      • 748 |
      • Formatting fix.
      • 749 |
      • Use a semaphore to synchronize stop() and start() calls. Fixes #76
      • 750 |
      • Merge branch 'master' of https://github.com/paulirish/qunit into paulirish-master
      • 751 |
      • Added two tests for previous QUnit.raises behaviour. For #69
      • 752 |
      • add optional 2. arg to QUnit.raises #69.
      • 753 |
      • fix references inside Complex Instances Nesting to what was originally intended.
      • 754 |
      • Qualify calls to ok() in raises() for compability with CLI enviroments.
      • 755 |
      • Fix done() handling, check for blocking, not block property
      • 756 |
      • Fix moduleStart/Done and done callbacks.
      • 757 |
      • Replacing sessionStorage test with the one from Modernizr/master (instead of current release). Here's hoping it'll work for some time.
      • 758 |
      • Updated test for availibility of sessionStorage, based on test from Modernizr. Fixes #64
      • 759 |
      • Defer test execution when previous run passed, persisted via sessionStorage. Fixes #49
      • 760 |
      • Refactored module handling and queuing to enable selective defer of test runs.
      • 761 |
      • Move assertions property from config to Test
      • 762 |
      • Move expected-tests property from config to Test
      • 763 |
      • Refactored test() method to delegate to a Test object to encapsulate all properties and methods of a single test, allowing further modifications.
      • 764 |
      • Adding output of sourcefile and linenumber of failed assertions (except ok()). Only limited cross-browser support for now. Fixes #60
      • 765 |
      • Drop 'hide missing tests' feature. Fixes #48
      • 766 |
      • Adding readme. Fixes #58
      • 767 |
      • Merge branch 'prettydiff'
      • 768 |
      • Improve jsDump output with formatted diffs.
      • 769 |
      • Cleanup whitespace
      • 770 |
      • Cleanup whitespace
      • 771 |
      • Added additional guards around browser specific code and cleaned up jsDump code
      • 772 |
      • Added guards around tests which are only for browsers
      • 773 |
      • cleaned up setTimeout undefined checking and double done on test finish
      • 774 |
      • fixing .gitignore
      • 775 |
      • making window setTimeout query more consistent
      • 776 |
      • Moved expect-code back to beginning of function, where it belongs. Fixes #52
      • 777 |
      • Bread crumb in header: Link to suite without filters, add link to current page based on the filter, if present. Fixes #50
      • 778 |
      • Make the toolbar element optional when checking for show/hide of test results. Fixes #46
      • 779 |
      • 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.
      • 780 |
      • Fix for QUnit.moduleDone, get rid of initial bogus log. Fixes #33
      • 781 |
      • Pass raw data (result, message, actual, expected) as third argument to QUnit.log. Fixes #32
      • 782 |
      • Dump full exception. Not pretty, but functional (see issue Pretty diff for pretty output). Fixes #31
      • 783 |
      • Don't let QUnit.reset() cause assertions to run. Manually applied from Scott Gonzalez branch. Fixes #34
      • 784 |
      • Added missing semicolons. Fixes #37
      • 785 |
      • Show okay/failed instead of undefined. Fixes #38
      • 786 |
      • Expose push as QUnit.push to build custom assertions. Fixes #39
      • 787 |
      • Respect filter pass selection when writing new results. Fixes #43
      • 788 |
      • Cleanup tests, removing asyncTest-undefined check and formatting
      • 789 |
      • Reset: Fall back to innerHTML when jQuery isn't available. Fixes #44
      • 790 |
      • Merge branch 'master' of github.com:jquery/qunit
      • 791 |
      • reset doesn't exist here - fixes #28.
      • 792 |
      • - 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)
      • 793 |
      • Adding .gitignore file
      • 794 |
      • 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.
      • 795 |
      • Always synchronize the done-step (it'll set the timeout when necessary), fixes timing race conditions.
      • 796 |
      • Insert location.href as an anchor around the header. Fixes issue #29
      • 797 |
      • - kill double ;; in escapeHtml. oops
      • 798 |
      • Removed html escaping from QUnit.diff, as input is already escaped, only leads to double escaping. Replaced newlines with single whitespace.
      • 799 |
      • Optimized and cleaned up CSS file
      • 800 |
      • 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
      • 801 |
      • Introducing #qunit-fixture element, deprecating the (never documented) #main element. Doesn't require inline styles and is now independent of jQuery.
      • 802 |
      • 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
      • 803 |
      • Remove jQuery-core specific resets (will be replaced within jQuery testsuite). Fixes issue #19 - QUnit.reset() removes global jQuery ajax event handlers
      • 804 |
      • Cleaning up rubble from the previous commit.
      • 805 |
      • Added raises assertion, reusing some of kennsnyder's code.
      • 806 |
      • Merged kensnyder's object detection code. Original message: Streamlined object detection and exposed QUnit.objectType as a function.
      • 807 |
      • Fixed some bad formatting.
      • 808 |
      • 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
      • 809 |
      • Improved output when expected != actual: Output both only then, and add a diff. Fixes issue #10 - Show diff if equal() or deepEqual() failed
      • 810 |
      • Expand failed tests on load. Fixes issue #8 - Failed tests expanded on load
      • 811 |
      • Set location.search for url-filtering instead of location.href. Fixes issue #7 - Modify location.search instead of location.href on test double-click
      • 812 |
      • Add QUnit.begin() callback. Fixes issue #6 - Add 'start' callback.
      • 813 |
      • add css style for result (".test-actual") in passed tests
      • 814 |
      • Fixed output escaping by using leeoniya's custom escaping along with innerHTML. Also paves the way for outputting diffs.
      • 815 |
      • Cleanup
      • 816 |
      • Revert "Revert part of bad merge, back to using createTextNode"
      • 817 |
      • Revert part of bad merge, back to using createTextNode
      • 818 |
      • Fixed doubleclick-handler and filtering to rerun only a single test.
      • 819 |
      • Add ability to css style a test's messages, expected and actual results. Merged from Leon Sorokin (leeoniya).
      • 820 |
      • Remove space between module name and colon
      • 821 |
      • - removed "module" wording from reports (unneeded and cluttery) - added and modified css to make module & test names styleable
      • 822 |
      • Logging support for Each test can extend the module testEnvironment
      • 823 |
      • Fixing whitespace
      • 824 |
      • Update tests to use equal() and deepEqual() rather than the deprecated equals() and same()
      • 825 |
      • Consistent argument names for deepEqual
      • 826 |
      • Skip DOM part of jsDump test if using a SSJS environment without a DOM
      • 827 |
      • 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.
      • 828 |
      • Add autostart option to config. Set via QUnit.config.autostart = false; start later via QUnit.start()
      • 829 |
      • Expose QUnit.config, but don't make config a global
      • 830 |
      • Expose QUnit.config as global to make external workarounds easier
      • 831 |
      • Merge branch 'asyncsetup'
      • 832 |
      • Allowing async setup and teardown. Fixes http://github.com/jquery/qunit/issues#issue/20 833 |
      • 834 |
      • Always output expected and actual result (no reason not to). Fixes http://github.com/jquery/qunit/issues#issue/21 835 |
      • 836 |
      • More changes to the detection of types in jsDump's typeOf.
      • 837 |
      • Change the typeOf checks in QUnit to be more accurate.
      • 838 |
      • 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
      • 839 |
      • Always use jsDump to output result objects into messages, making the output for passing assertions more useful
      • 840 |
      • Make it so that the display is updated, at least, once a second - also prevents scripts from executing for too long and causing problems.
      • 841 |
      • added tests and patch for qunit.equiv to avoid circular references in objects and arrays
      • 842 |
      • No reason to continue looping, we can stop at this point. Thanks to Chris Thatcher for the suggestion.
      • 843 |
      • Use createTextNode instead of innerHTML for showing test result since expected and actual might be something that looks like a tag.
      • 844 |
      • 'Test card' design added
      • 845 |
      • switched green to blue for top-level pass + reduced padding
      • 846 |
      • Bringing the QUnit API in line with the CommonJS API.
      • 847 |
      • Explicitly set list-style-position: inside on result LIs.
      • 848 |
      • Madness with border-radius.
      • 849 |
      • Corrected banner styles for new class names
      • 850 |
      • Added rounded corners and removed body rules for embedded tests
      • 851 |
      • Resolving merge conflicts.
      • 852 |
      • added colouring for value summary
      • 853 |
      • adding some extra text colours
      • 854 |
      • added styles for toolbar
      • 855 |
      • added new styles
      • 856 |
      • IE 6 and 7 weren't respecting the CSS rules for the banner, used a different technique instead.
      • 857 |
      • Went a bit further and made extra-sure that the target was specified correctly.
      • 858 |
      • Fixed problem where double-clicking an entry in IE caused an error to occur.
      • 859 |
      • Path for http://dev.jquery.com/ticket/5426 - fix the microformat test result
      • 860 |
      • Fixed test() to use 'expected' 2nd param
      • 861 |
      • Remove the named function expressions, to stop Safari 2 from freaking out. Fixes #5.
      • 862 |
      • Each test can extend the module testEnvironment
      • 863 |
      • Extra test for current test environment
      • 864 |
      • Make the current testEnvironment available to utility functions
      • 865 |
      • typeOf in QUnit.jsDump now uses QUnit.is
      • 866 |
      • hoozit in QUnit.equiv now uses QUnit.is
      • 867 |
      • Properly set label attributes.
      • 868 |
      • Some minor tweaks to RyanS' GETParams change.
      • 869 |
      • left a console.log in :(
      • 870 |
      • 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
      • 871 |
      • need to set config.currentModule to have correct names and working filters
      • 872 |
      • Support logging of testEnvironment
      • 873 |
      • async tests aren't possible on rhino
      • 874 |
      • Fixed a missing QUnit.reset().
      • 875 |
      • The QUnit. prefix was missing from the uses of the start() method.
      • 876 |
      • Merged lifecycle object into testEnvironment
      • 877 |
      • "replacing totally wrong diff algorithm with a working one" Patch from kassens (manually applied).
      • 878 |
      • fixing jslint errors in test.js
      • 879 |
      • Fixed: testDone() was always called with 0 failures in CommonJS mode
      • 880 |
      • Fixed: moduleDone() was invoked on first call to module()
      • 881 |
      • Added a new asyncTest method - removes the need for having to call start() at the beginning of an asynchronous test.
      • 882 |
      • Added support for expected numbers in the test method.
      • 883 |
      • Fixed broken dynamic loading of tests (can now dynamically load tests and done still works properly).
      • 884 |
      • Simplified the logic for calling 'done' and pushing off new tests - was causing too many inconsistencies otherwise.
      • 885 |
      • Simplified the markup for the QUnit test test suite.
      • 886 |
      • Realized that it's really easy to handle the case where stop() has been called and then an exception is thrown.
      • 887 |
      • Added in better logging support. Now handle moduleStart/moduleDone and testStart/testDone. Also make sure that done only fires once at the end.
      • 888 |
      • 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).
      • 889 |
      • Re-worked QUnit to handle dynamic loading of additional code (the 'done' code will be re-run after additional code is loaded).
      • 890 |
      • Removed the old SVN version stuff.
      • 891 |
      • Moved the QUnit source into a separate directory and updated the test suite/packages files.
      • 892 |
      • Added in CommonJS support for exporting the QUnit functionality.
      • 893 |
      • Missing quote from package.json.
      • 894 |
      • Fixed trailing comma in package.json.
      • 895 |
      • Added a CommonJS/Narwhal package.json file.
      • 896 |
      • Accidentally reverted the jsDump/equiv changes that had been made.
      • 897 |
      • Hide the filter toolbar if it's not needed. Also exposed the jsDump and equiv objects on QUnit.
      • 898 |
      • Retooled the QUnit CSS to be more generic.
      • 899 |
      • Renamed the QUnit files from testrunner/testsuite to QUnit.
      • 900 |
      • Expose QUnit.equiv and QUnit.jsDump in QUnit.
      • 901 |
      • Moved the QUnit test directory into the QUnit directory.
      • 902 |
      • Reworked the QUnit CSS (moved jQuery-specific stuff out, made all the other selectors more specific).
      • 903 |
      • Removed the #main reset for non-jQuery code (QUnit.reset can be overwritten with your own reset code).
      • 904 |
      • Moved the QUnit toolbar inline.
      • 905 |
      • Switched to using a qunit- prefix for special elements (banner, userAgent, and tests).
      • 906 |
      • Missed a case in QUnit where an element was assumed to exist.
      • 907 |
      • QUnit's isSet and isObj are no longer needed - you should use same instead.
      • 908 |
      • Make sure that QUnit's equiv entity escaping is enabled by default (otherwise the output gets kind of crazy).
      • 909 |
      • 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).
      • 910 |
      • Removed some legacy and jQuery-specific test methods.
      • 911 |
      • Added callbacks for tests and modules. It's now possible to reproduce the full display of the testrunner without using the regular rendering.
      • 912 |
      • QUnit no longer depends upon rendering the results (it can work simply by using the logging callbacks).
      • 913 |
      • Made QUnit no longer require jQuery (it is now a standalone, framework independent, test runner).
      • 914 |
      • Reverted the noglobals changed from QUnit - causing chaos in the jQuery test suite.
      • 915 |
      • 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
      • 916 |
      • qunit: don't child selectors when IE should behave nicely, too
      • 917 |
      • qunit: improvment 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
      • 918 |
      • qunit: added missing semicolons
      • 919 |
      • qunit: fixed a semicolon, that should have been a comma
      • 920 |
      • QUnit: implemented error handling for Opera as proposed by #3628
      • 921 |
      • qunit: fix for http://dev.jquery.com/ticket/3215 changing wording of testresults, to something more positive (x of y passed, z failed)
      • 922 |
      • 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 923 |
      • 924 |
      • qunit: wrap name of test in span when a module is used for better styling
      • 925 |
      • qunit: auto-prepend default mark (#header, #banner, #userAgent, #tests) when not present
      • 926 |
      • Landing some changes to add logging to QUnit (so that it's easier to hook in to when a test finishes).
      • 927 |
      • Added checkbox for hiding missing tests (tests that fail with the text 'missing test - untested code is broken code')
      • 928 |
      • qunit: eol-style:native and mime-type
      • 929 |
      • HTML being injected for the test result wasn't valid HTML.
      • 930 |
      • qunit: setting mimetype for testsuite.css
      • 931 |
      • qunit: update to Ariel's noglobals patch to support async tests as well
      • 932 |
      • Landing Ariel's change - checks for global variable leakage.
      • 933 |
      • qunit: run module-teardown in its own synchronize block to synchronize with async tests (ugh)
      • 934 |
      • qunit: same: equiv - completely refactored in the testrunner.
      • 935 |
      • 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)
      • 936 |
      • qunit: code refactoring and cleanup
      • 937 |
      • QUnit: update equiv to latest version, handling multiple arguments and NaN, see http://philrathe.com/articles/equiv 938 |
      • 939 |
      • QUnit: cleanup, deprecating compare, compare2 and serialArray: usage now throws an error with a helpful message
      • 940 |
      • QUnit: optional timeout argument for stop, while making tests undetermined, useful for debugging
      • 941 |
      • QUnit: added toolbar with "hide passed tests" checkbox to help focus on failed tests
      • 942 |
      • QUnit: minor output formatting
      • 943 |
      • QUnit: adding same-assertion for a recursive comparsion of primite values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests
      • 944 |
      • QUnit: adding same-assertion for a recursive comparsion of primite values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests
      • 945 |
      • QUnit: adding same-assertion for a recursive comparsion of primite values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests
      • 946 |
      • qunit: use window.load to initialize tests, allowing other code to run on document-ready before starting to run tests
      • 947 |
      • qunit: allow either setup or teardown, instead of both or nothing
      • 948 |
      • 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)
      • 949 |
      • qunit: added support for module level setup/teardown callbacks
      • 950 |
      • qunit: modified example for equals to avoid confusion with parameter ordering
      • 951 |
      • 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 952 |
      • 953 |
      • qunit: replaced $ alias with jQuery (merged from jquery/test/data/testrunner.js)
      • 954 |
      • qunit: fixed inline documentation for equals
      • 955 |
      • qunit testrunner - catch and log possible error during reset()
      • 956 |
      • QUnit: Switched out Date and Rev for Id.
      • 957 |
      • qunit: when errors are thrown in a test, the message is successfully show on all browsers.
      • 958 |
      • qunit: added license header
      • 959 |
      • qunit: moved jquery testrunner to top-level project, see http://docs.jquery.com/QUnit 960 |
      • 961 |
      • Share project 'qunit' into 'https://jqueryjs.googlecode.com/svn'
      • 962 |
      963 |
      964 | 965 |
      966 |
      967 | 968 | 969 | 978 | 979 |
      980 |
      981 |
      982 | 983 | 986 | 987 | 988 |
      989 |
      990 |
      991 |
      992 | 993 | 994 |
      995 | 996 | 997 | 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1338 | 1339 |
      1340 |

      Markdown Cheat Sheet

      1341 | 1342 |
      1343 | 1344 |
      1345 |
      1346 |

      Format Text

      1347 |

      Headers

      1348 |
      1349 | # This is an <h1> tag
      1350 | ## This is an <h2> tag
      1351 | ###### This is an <h6> tag
      1352 |

      Text styles

      1353 |
      1354 | *This text will be italic*
      1355 | _This will also be italic_
      1356 | **This text will be bold**
      1357 | __This will also be bold__
      1358 | 
      1359 | *You **can** combine them*
      1360 | 
      1361 |
      1362 |
      1363 |

      Lists

      1364 |

      Unordered

      1365 |
      1366 | * Item 1
      1367 | * Item 2
      1368 |   * Item 2a
      1369 |   * Item 2b
      1370 |

      Ordered

      1371 |
      1372 | 1. Item 1
      1373 | 2. Item 2
      1374 | 3. Item 3
      1375 |    * Item 3a
      1376 |    * Item 3b
      1377 |
      1378 |
      1379 |

      Miscellaneous

      1380 |

      Images

      1381 |
      1382 | ![GitHub Logo](/images/logo.png)
      1383 | Format: ![Alt Text](url)
      1384 | 
      1385 |

      Links

      1386 |
      1387 | http://github.com - automatic!
      1388 | [GitHub](http://github.com)
      1389 |

      Blockquotes

      1390 |
      1391 | As Kanye West said:
      1392 | 
      1393 | > We're living the future so
      1394 | > the present is our past.
      1395 | 
      1396 |
      1397 |
      1398 |
      1399 | 1400 |

      Code Examples in Markdown

      1401 |
      1402 |

      Syntax highlighting with GFM

      1403 |
      1404 | ```javascript
      1405 | function fancyAlert(arg) {
      1406 |   if(arg) {
      1407 |     $.facebox({div:'#foo'})
      1408 |   }
      1409 | }
      1410 | ```
      1411 |
      1412 |
      1413 |

      Or, indent your code 4 spaces

      1414 |
      1415 | Here is a Python code example
      1416 | without syntax highlighting:
      1417 | 
      1418 |     def foo:
      1419 |       if not bar:
      1420 |         return true
      1421 |
      1422 |
      1423 |

      Inline code for comments

      1424 |
      1425 | I think you should use an
      1426 | `<addr>` element here instead.
      1427 |
      1428 |
      1429 | 1430 |
      1431 |
      1432 | 1433 | 1434 |
      1435 | 1436 | Something went wrong with that request. Please try again. 1437 | 1438 |
      1439 | 1440 | 1441 | 1442 | 1443 | 1444 | 1445 | 1446 | 1447 | --------------------------------------------------------------------------------