| 1 |
/*! |
| 2 |
* QUnit 2.24.3 |
| 3 |
* https://qunitjs.com/ |
| 4 |
* |
| 5 |
* Copyright OpenJS Foundation and other contributors |
| 6 |
* Released under the MIT license |
| 7 |
* https://jquery.org/license |
| 8 |
*/ |
| 9 |
(function () { |
| 10 |
'use strict'; |
| 11 |
|
| 12 |
function _arrayLikeToArray(r, a) { |
| 13 |
(null == a || a > r.length) && (a = r.length); |
| 14 |
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; |
| 15 |
return n; |
| 16 |
} |
| 17 |
function _arrayWithHoles(r) { |
| 18 |
if (Array.isArray(r)) return r; |
| 19 |
} |
| 20 |
function _arrayWithoutHoles(r) { |
| 21 |
if (Array.isArray(r)) return _arrayLikeToArray(r); |
| 22 |
} |
| 23 |
function _classCallCheck(a, n) { |
| 24 |
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); |
| 25 |
} |
| 26 |
function _defineProperties(e, r) { |
| 27 |
for (var t = 0; t < r.length; t++) { |
| 28 |
var o = r[t]; |
| 29 |
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); |
| 30 |
} |
| 31 |
} |
| 32 |
function _createClass(e, r, t) { |
| 33 |
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { |
| 34 |
writable: !1 |
| 35 |
}), e; |
| 36 |
} |
| 37 |
function _iterableToArray(r) { |
| 38 |
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); |
| 39 |
} |
| 40 |
function _iterableToArrayLimit(r, l) { |
| 41 |
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; |
| 42 |
if (null != t) { |
| 43 |
var e, |
| 44 |
n, |
| 45 |
i, |
| 46 |
u, |
| 47 |
a = [], |
| 48 |
f = !0, |
| 49 |
o = !1; |
| 50 |
try { |
| 51 |
if (i = (t = t.call(r)).next, 0 === l) { |
| 52 |
if (Object(t) !== t) return; |
| 53 |
f = !1; |
| 54 |
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); |
| 55 |
} catch (r) { |
| 56 |
o = !0, n = r; |
| 57 |
} finally { |
| 58 |
try { |
| 59 |
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; |
| 60 |
} finally { |
| 61 |
if (o) throw n; |
| 62 |
} |
| 63 |
} |
| 64 |
return a; |
| 65 |
} |
| 66 |
} |
| 67 |
function _nonIterableRest() { |
| 68 |
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
| 69 |
} |
| 70 |
function _nonIterableSpread() { |
| 71 |
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
| 72 |
} |
| 73 |
function _slicedToArray(r, e) { |
| 74 |
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); |
| 75 |
} |
| 76 |
function _toConsumableArray(r) { |
| 77 |
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); |
| 78 |
} |
| 79 |
function _toPrimitive(t, r) { |
| 80 |
if ("object" != typeof t || !t) return t; |
| 81 |
var e = t[Symbol.toPrimitive]; |
| 82 |
if (void 0 !== e) { |
| 83 |
var i = e.call(t, r || "default"); |
| 84 |
if ("object" != typeof i) return i; |
| 85 |
throw new TypeError("@@toPrimitive must return a primitive value."); |
| 86 |
} |
| 87 |
return ("string" === r ? String : Number)(t); |
| 88 |
} |
| 89 |
function _toPropertyKey(t) { |
| 90 |
var i = _toPrimitive(t, "string"); |
| 91 |
return "symbol" == typeof i ? i : i + ""; |
| 92 |
} |
| 93 |
function _typeof(o) { |
| 94 |
"@babel/helpers - typeof"; |
| 95 |
|
| 96 |
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { |
| 97 |
return typeof o; |
| 98 |
} : function (o) { |
| 99 |
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; |
| 100 |
}, _typeof(o); |
| 101 |
} |
| 102 |
function _unsupportedIterableToArray(r, a) { |
| 103 |
if (r) { |
| 104 |
if ("string" == typeof r) return _arrayLikeToArray(r, a); |
| 105 |
var t = {}.toString.call(r).slice(8, -1); |
| 106 |
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
// We don't use global-this-polyfill [1], because it modifies |
| 111 |
// the globals scope by default. QUnit must not affect the host context |
| 112 |
// as developers may test their project may be such a polyfill, and/or |
| 113 |
// they may intentionally test their project with and without certain |
| 114 |
// polyfills and we must not affect that. It also uses an obscure |
| 115 |
// mechanism that seems to sometimes causes a runtime error in older |
| 116 |
// browsers (specifically Safari and IE versions that support |
| 117 |
// Object.defineProperty but then report _T_ as undefined). |
| 118 |
// [1] https://github.com/ungap/global-this/blob/v0.4.4/esm/index.js |
| 119 |
// |
| 120 |
// Another way is `Function('return this')()`, but doing so relies |
| 121 |
// on eval which will cause a CSP error on some servers. |
| 122 |
// |
| 123 |
// Instead, simply check the four options that already exist |
| 124 |
// in all supported environments. |
| 125 |
function getGlobalThis() { |
| 126 |
if (typeof globalThis !== 'undefined') { |
| 127 |
// For SpiderMonkey, modern browsers, and recent Node.js |
| 128 |
// eslint-disable-next-line no-undef |
| 129 |
return globalThis; |
| 130 |
} |
| 131 |
if (typeof self !== 'undefined') { |
| 132 |
// For web workers |
| 133 |
// eslint-disable-next-line no-undef |
| 134 |
return self; |
| 135 |
} |
| 136 |
if (typeof window$1 !== 'undefined') { |
| 137 |
// For document context in browsers |
| 138 |
return window$1; |
| 139 |
} |
| 140 |
if (typeof global !== 'undefined') { |
| 141 |
// For Node.js |
| 142 |
// eslint-disable-next-line no-undef |
| 143 |
return global; |
| 144 |
} |
| 145 |
throw new Error('Unable to locate global object'); |
| 146 |
} |
| 147 |
|
| 148 |
// This avoids a simple `export const` assignment as that would lead Rollup |
| 149 |
// to change getGlobalThis and use the same (generated) variable name there. |
| 150 |
var g = getGlobalThis(); |
| 151 |
|
| 152 |
// These optional globals are undefined in one or more environments: |
| 153 |
// modern browser, old browser, Node.js, SpiderMonkey. |
| 154 |
// Calling code must check these for truthy-ness before use. |
| 155 |
var console$1 = g.console; |
| 156 |
var setTimeout$1 = g.setTimeout; |
| 157 |
var clearTimeout = g.clearTimeout; |
| 158 |
var process$1 = g.process; |
| 159 |
var window$1 = g.window; |
| 160 |
var document = window$1 && window$1.document; |
| 161 |
var navigator = window$1 && window$1.navigator; |
| 162 |
var localSessionStorage = function () { |
| 163 |
var x = 'qunit-test-string'; |
| 164 |
try { |
| 165 |
g.sessionStorage.setItem(x, x); |
| 166 |
g.sessionStorage.removeItem(x); |
| 167 |
return g.sessionStorage; |
| 168 |
} catch (e) { |
| 169 |
return undefined; |
| 170 |
} |
| 171 |
}(); |
| 172 |
|
| 173 |
// Basic fallback for ES6 Map |
| 174 |
// Support: IE 9-10, Safari 7, PhantomJS; Map is undefined |
| 175 |
// Support: iOS 8; `new Map(iterable)` is not supported |
| 176 |
// |
| 177 |
// Fallback for ES7 Map#keys |
| 178 |
// Support: IE 11; Map#keys is undefined |
| 179 |
var StringMap = typeof g.Map === 'function' && typeof g.Map.prototype.keys === 'function' && typeof g.Symbol === 'function' && _typeof(g.Symbol.iterator) === 'symbol' ? g.Map : function StringMap(input) { |
| 180 |
var _this = this; |
| 181 |
var store = Object.create(null); |
| 182 |
var hasOwn = Object.prototype.hasOwnProperty; |
| 183 |
this.has = function (strKey) { |
| 184 |
return hasOwn.call(store, strKey); |
| 185 |
}; |
| 186 |
this.get = function (strKey) { |
| 187 |
return store[strKey]; |
| 188 |
}; |
| 189 |
this.set = function (strKey, val) { |
| 190 |
if (!hasOwn.call(store, strKey)) { |
| 191 |
this.size++; |
| 192 |
} |
| 193 |
store[strKey] = val; |
| 194 |
return this; |
| 195 |
}; |
| 196 |
this.delete = function (strKey) { |
| 197 |
if (hasOwn.call(store, strKey)) { |
| 198 |
delete store[strKey]; |
| 199 |
this.size--; |
| 200 |
} |
| 201 |
}; |
| 202 |
this.forEach = function (callback) { |
| 203 |
for (var strKey in store) { |
| 204 |
callback(store[strKey], strKey); |
| 205 |
} |
| 206 |
}; |
| 207 |
this.keys = function () { |
| 208 |
return Object.keys(store); |
| 209 |
}; |
| 210 |
this.clear = function () { |
| 211 |
store = Object.create(null); |
| 212 |
this.size = 0; |
| 213 |
}; |
| 214 |
this.size = 0; |
| 215 |
if (input) { |
| 216 |
input.forEach(function (val, strKey) { |
| 217 |
_this.set(strKey, val); |
| 218 |
}); |
| 219 |
} |
| 220 |
}; |
| 221 |
|
| 222 |
// Basic fallback for ES6 Set |
| 223 |
// Support: IE 11, `new Set(iterable)` parameter not yet implemented |
| 224 |
// Test for Set#values() which came after Set(iterable). |
| 225 |
var StringSet = typeof g.Set === 'function' && typeof g.Set.prototype.values === 'function' ? g.Set : function (input) { |
| 226 |
var set = Object.create(null); |
| 227 |
if (Array.isArray(input)) { |
| 228 |
input.forEach(function (item) { |
| 229 |
set[item] = true; |
| 230 |
}); |
| 231 |
} |
| 232 |
return { |
| 233 |
add: function add(value) { |
| 234 |
set[value] = true; |
| 235 |
}, |
| 236 |
has: function has(value) { |
| 237 |
return value in set; |
| 238 |
}, |
| 239 |
get size() { |
| 240 |
return Object.keys(set).length; |
| 241 |
} |
| 242 |
}; |
| 243 |
}; |
| 244 |
|
| 245 |
var toString = Object.prototype.toString; |
| 246 |
var hasOwn$1 = Object.prototype.hasOwnProperty; |
| 247 |
var performance = { |
| 248 |
// eslint-disable-next-line compat/compat -- Checked |
| 249 |
now: window$1 && window$1.performance && window$1.performance.now ? window$1.performance.now.bind(window$1.performance) : Date.now |
| 250 |
}; |
| 251 |
|
| 252 |
// Returns a new Array with the elements that are in a but not in b |
| 253 |
function diff$1(a, b) { |
| 254 |
return a.filter(function (a) { |
| 255 |
return b.indexOf(a) === -1; |
| 256 |
}); |
| 257 |
} |
| 258 |
|
| 259 |
/** |
| 260 |
* Determines whether an element exists in a given array or not. |
| 261 |
* |
| 262 |
* @method inArray |
| 263 |
* @param {any} elem |
| 264 |
* @param {Array} array |
| 265 |
* @return {boolean} |
| 266 |
*/ |
| 267 |
var inArray = Array.prototype.includes ? function (elem, array) { |
| 268 |
return array.includes(elem); |
| 269 |
} : function (elem, array) { |
| 270 |
return array.indexOf(elem) !== -1; |
| 271 |
}; |
| 272 |
|
| 273 |
/** |
| 274 |
* Recursively clone an object into a plain array or object, taking only the |
| 275 |
* own enumerable properties. |
| 276 |
* |
| 277 |
* @param {any} obj |
| 278 |
* @param {bool} [allowArray=true] |
| 279 |
* @return {Object|Array} |
| 280 |
*/ |
| 281 |
function objectValues(obj) { |
| 282 |
var allowArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; |
| 283 |
var vals = allowArray && is('array', obj) ? [] : {}; |
| 284 |
for (var key in obj) { |
| 285 |
if (hasOwn$1.call(obj, key)) { |
| 286 |
var val = obj[key]; |
| 287 |
vals[key] = val === Object(val) ? objectValues(val, allowArray) : val; |
| 288 |
} |
| 289 |
} |
| 290 |
return vals; |
| 291 |
} |
| 292 |
|
| 293 |
/** |
| 294 |
* Recursively clone an object into a plain object, taking only the |
| 295 |
* subset of own enumerable properties that exist a given model. |
| 296 |
* |
| 297 |
* @param {any} obj |
| 298 |
* @param {any} model |
| 299 |
* @return {Object} |
| 300 |
*/ |
| 301 |
function objectValuesSubset(obj, model) { |
| 302 |
// Return primitive values unchanged to avoid false positives or confusing |
| 303 |
// results from assert.propContains(). |
| 304 |
// E.g. an actual null or false wrongly equaling an empty object, |
| 305 |
// or an actual string being reported as object not matching a partial object. |
| 306 |
if (obj !== Object(obj)) { |
| 307 |
return obj; |
| 308 |
} |
| 309 |
|
| 310 |
// Unlike objectValues(), subset arrays to a plain objects as well. |
| 311 |
// This enables subsetting [20, 30] with {1: 30}. |
| 312 |
var subset = {}; |
| 313 |
for (var key in model) { |
| 314 |
if (hasOwn$1.call(model, key) && hasOwn$1.call(obj, key)) { |
| 315 |
subset[key] = objectValuesSubset(obj[key], model[key]); |
| 316 |
} |
| 317 |
} |
| 318 |
return subset; |
| 319 |
} |
| 320 |
function extend(a, b, undefOnly) { |
| 321 |
for (var prop in b) { |
| 322 |
if (hasOwn$1.call(b, prop)) { |
| 323 |
if (b[prop] === undefined) { |
| 324 |
delete a[prop]; |
| 325 |
} else if (!(undefOnly && typeof a[prop] !== 'undefined')) { |
| 326 |
a[prop] = b[prop]; |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
return a; |
| 331 |
} |
| 332 |
function objectType(obj) { |
| 333 |
if (typeof obj === 'undefined') { |
| 334 |
return 'undefined'; |
| 335 |
} |
| 336 |
|
| 337 |
// Consider: typeof null === object |
| 338 |
if (obj === null) { |
| 339 |
return 'null'; |
| 340 |
} |
| 341 |
var match = toString.call(obj).match(/^\[object\s(.*)\]$/); |
| 342 |
var type = match && match[1]; |
| 343 |
switch (type) { |
| 344 |
case 'Number': |
| 345 |
if (isNaN(obj)) { |
| 346 |
return 'nan'; |
| 347 |
} |
| 348 |
return 'number'; |
| 349 |
case 'String': |
| 350 |
case 'Boolean': |
| 351 |
case 'Array': |
| 352 |
case 'Set': |
| 353 |
case 'Map': |
| 354 |
case 'Date': |
| 355 |
case 'RegExp': |
| 356 |
case 'Function': |
| 357 |
case 'Symbol': |
| 358 |
return type.toLowerCase(); |
| 359 |
default: |
| 360 |
return _typeof(obj); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
// Safe object type checking |
| 365 |
function is(type, obj) { |
| 366 |
return objectType(obj) === type; |
| 367 |
} |
| 368 |
|
| 369 |
// Based on Java's String.hashCode, a simple but not |
| 370 |
// rigorously collision resistant hashing function |
| 371 |
function generateHash(module, testName) { |
| 372 |
var str = module + '\x1C' + testName; |
| 373 |
var hash = 0; |
| 374 |
for (var i = 0; i < str.length; i++) { |
| 375 |
hash = (hash << 5) - hash + str.charCodeAt(i); |
| 376 |
hash |= 0; |
| 377 |
} |
| 378 |
|
| 379 |
// Convert the possibly negative integer hash code into an 8 character hex string, which isn't |
| 380 |
// strictly necessary but increases user understanding that the id is a SHA-like hash |
| 381 |
var hex = (0x100000000 + hash).toString(16); |
| 382 |
if (hex.length < 8) { |
| 383 |
hex = '0000000' + hex; |
| 384 |
} |
| 385 |
return hex.slice(-8); |
| 386 |
} |
| 387 |
|
| 388 |
/** |
| 389 |
* Converts an error into a simple string for comparisons. |
| 390 |
* |
| 391 |
* @param {Error|any} error |
| 392 |
* @return {string} |
| 393 |
*/ |
| 394 |
function errorString(error) { |
| 395 |
// Use String() instead of toString() to handle non-object values like undefined or null. |
| 396 |
var resultErrorString = String(error); |
| 397 |
|
| 398 |
// If the error wasn't a subclass of Error but something like |
| 399 |
// an object literal with name and message properties... |
| 400 |
if (resultErrorString.slice(0, 7) === '[object') { |
| 401 |
// Based on https://es5.github.io/#x15.11.4.4 |
| 402 |
return (error.name || 'Error') + (error.message ? ": ".concat(error.message) : ''); |
| 403 |
} else { |
| 404 |
return resultErrorString; |
| 405 |
} |
| 406 |
} |
| 407 |
function escapeText(str) { |
| 408 |
if (!str) { |
| 409 |
return ''; |
| 410 |
} |
| 411 |
|
| 412 |
// Both single quotes and double quotes (for attributes) |
| 413 |
return ('' + str).replace(/['"<>&]/g, function (s) { |
| 414 |
switch (s) { |
| 415 |
case "'": |
| 416 |
return '''; |
| 417 |
case '"': |
| 418 |
return '"'; |
| 419 |
case '<': |
| 420 |
return '<'; |
| 421 |
case '>': |
| 422 |
return '>'; |
| 423 |
case '&': |
| 424 |
return '&'; |
| 425 |
} |
| 426 |
}); |
| 427 |
} |
| 428 |
|
| 429 |
var BOXABLE_TYPES = new StringSet(['boolean', 'number', 'string']); |
| 430 |
|
| 431 |
// Memory for previously seen containers (object, array, map, set). |
| 432 |
// Used for recursion detection, and to avoid repeated comparison. |
| 433 |
// |
| 434 |
// Elements are { a: val, b: val }. |
| 435 |
var memory = []; |
| 436 |
function useStrictEquality(a, b) { |
| 437 |
return a === b; |
| 438 |
} |
| 439 |
function useObjectValueEquality(a, b) { |
| 440 |
return a === b || a.valueOf() === b.valueOf(); |
| 441 |
} |
| 442 |
function compareConstructors(a, b) { |
| 443 |
// Comparing constructors is more strict than using `instanceof` |
| 444 |
return getConstructor(a) === getConstructor(b); |
| 445 |
} |
| 446 |
function getConstructor(obj) { |
| 447 |
var proto = Object.getPrototypeOf(obj); |
| 448 |
|
| 449 |
// If the obj prototype descends from a null constructor, treat it |
| 450 |
// as a null prototype. |
| 451 |
// Ref https://github.com/qunitjs/qunit/issues/851 |
| 452 |
// |
| 453 |
// Allow objects with no prototype, from Object.create(null), to be equivalent to |
| 454 |
// plain objects that have Object as their constructor. |
| 455 |
return !proto || proto.constructor === null ? Object : obj.constructor; |
| 456 |
} |
| 457 |
function getRegExpFlags(regexp) { |
| 458 |
return 'flags' in regexp ? regexp.flags : regexp.toString().match(/[gimuy]*$/)[0]; |
| 459 |
} |
| 460 |
|
| 461 |
// Specialised comparisons after entryTypeCallbacks.object, based on `objectType()` |
| 462 |
var objTypeCallbacks = { |
| 463 |
undefined: useStrictEquality, |
| 464 |
null: useStrictEquality, |
| 465 |
// Handle boxed boolean |
| 466 |
boolean: useObjectValueEquality, |
| 467 |
number: function number(a, b) { |
| 468 |
// Handle NaN and boxed number |
| 469 |
return a === b || a.valueOf() === b.valueOf() || isNaN(a.valueOf()) && isNaN(b.valueOf()); |
| 470 |
}, |
| 471 |
// Handle boxed string |
| 472 |
string: useObjectValueEquality, |
| 473 |
symbol: useStrictEquality, |
| 474 |
date: useObjectValueEquality, |
| 475 |
nan: function nan() { |
| 476 |
return true; |
| 477 |
}, |
| 478 |
regexp: function regexp(a, b) { |
| 479 |
return a.source === b.source && |
| 480 |
// Include flags in the comparison |
| 481 |
getRegExpFlags(a) === getRegExpFlags(b); |
| 482 |
}, |
| 483 |
// identical reference only |
| 484 |
function: useStrictEquality, |
| 485 |
array: function array(a, b) { |
| 486 |
if (a.length !== b.length) { |
| 487 |
// Safe and faster |
| 488 |
return false; |
| 489 |
} |
| 490 |
for (var i = 0; i < a.length; i++) { |
| 491 |
if (!typeEquiv(a[i], b[i])) { |
| 492 |
return false; |
| 493 |
} |
| 494 |
} |
| 495 |
return true; |
| 496 |
}, |
| 497 |
// Define sets a and b to be equivalent if for each element aVal in a, there |
| 498 |
// is some element bVal in b such that aVal and bVal are equivalent. Element |
| 499 |
// repetitions are not counted, so these are equivalent: |
| 500 |
// a = new Set( [ X={}, Y=[], Y ] ); |
| 501 |
// b = new Set( [ Y, X, X ] ); |
| 502 |
set: function set(a, b) { |
| 503 |
if (a.size !== b.size) { |
| 504 |
// This optimization has certain quirks because of the lack of |
| 505 |
// repetition counting. For instance, adding the same |
| 506 |
// (reference-identical) element to two equivalent sets can |
| 507 |
// make them non-equivalent. |
| 508 |
return false; |
| 509 |
} |
| 510 |
var outerEq = true; |
| 511 |
a.forEach(function (aVal) { |
| 512 |
// Short-circuit if the result is already known. (Using for...of |
| 513 |
// with a break clause would be cleaner here, but it would cause |
| 514 |
// a syntax error on older JavaScript implementations even if |
| 515 |
// Set is unused) |
| 516 |
if (!outerEq) { |
| 517 |
return; |
| 518 |
} |
| 519 |
var innerEq = false; |
| 520 |
b.forEach(function (bVal) { |
| 521 |
// Likewise, short-circuit if the result is already known |
| 522 |
if (innerEq) { |
| 523 |
return; |
| 524 |
} |
| 525 |
|
| 526 |
// Swap out the global memory, as nested typeEquiv() would clobber it |
| 527 |
var originalMemory = memory; |
| 528 |
memory = []; |
| 529 |
if (typeEquiv(bVal, aVal)) { |
| 530 |
innerEq = true; |
| 531 |
} |
| 532 |
// Restore |
| 533 |
memory = originalMemory; |
| 534 |
}); |
| 535 |
if (!innerEq) { |
| 536 |
outerEq = false; |
| 537 |
} |
| 538 |
}); |
| 539 |
return outerEq; |
| 540 |
}, |
| 541 |
// Define maps a and b to be equivalent if for each key-value pair (aKey, aVal) |
| 542 |
// in a, there is some key-value pair (bKey, bVal) in b such that |
| 543 |
// [ aKey, aVal ] and [ bKey, bVal ] are equivalent. Key repetitions are not |
| 544 |
// counted, so these are equivalent: |
| 545 |
// a = new Map( [ [ {}, 1 ], [ {}, 1 ], [ [], 1 ] ] ); |
| 546 |
// b = new Map( [ [ {}, 1 ], [ [], 1 ], [ [], 1 ] ] ); |
| 547 |
map: function map(a, b) { |
| 548 |
if (a.size !== b.size) { |
| 549 |
// This optimization has certain quirks because of the lack of |
| 550 |
// repetition counting. For instance, adding the same |
| 551 |
// (reference-identical) key-value pair to two equivalent maps |
| 552 |
// can make them non-equivalent. |
| 553 |
return false; |
| 554 |
} |
| 555 |
var outerEq = true; |
| 556 |
a.forEach(function (aVal, aKey) { |
| 557 |
// Short-circuit if the result is already known. (Using for...of |
| 558 |
// with a break clause would be cleaner here, but it would cause |
| 559 |
// a syntax error on older JavaScript implementations even if |
| 560 |
// Map is unused) |
| 561 |
if (!outerEq) { |
| 562 |
return; |
| 563 |
} |
| 564 |
var innerEq = false; |
| 565 |
b.forEach(function (bVal, bKey) { |
| 566 |
// Likewise, short-circuit if the result is already known |
| 567 |
if (innerEq) { |
| 568 |
return; |
| 569 |
} |
| 570 |
|
| 571 |
// Swap out the global memory, as nested typeEquiv() would clobber it |
| 572 |
var originalMemory = memory; |
| 573 |
memory = []; |
| 574 |
if (objTypeCallbacks.array([bVal, bKey], [aVal, aKey])) { |
| 575 |
innerEq = true; |
| 576 |
} |
| 577 |
// Restore |
| 578 |
memory = originalMemory; |
| 579 |
}); |
| 580 |
if (!innerEq) { |
| 581 |
outerEq = false; |
| 582 |
} |
| 583 |
}); |
| 584 |
return outerEq; |
| 585 |
} |
| 586 |
}; |
| 587 |
|
| 588 |
// Entry points from typeEquiv, based on `typeof` |
| 589 |
var entryTypeCallbacks = { |
| 590 |
undefined: useStrictEquality, |
| 591 |
null: useStrictEquality, |
| 592 |
boolean: useStrictEquality, |
| 593 |
number: function number(a, b) { |
| 594 |
// Handle NaN |
| 595 |
return a === b || isNaN(a) && isNaN(b); |
| 596 |
}, |
| 597 |
string: useStrictEquality, |
| 598 |
symbol: useStrictEquality, |
| 599 |
function: useStrictEquality, |
| 600 |
object: function object(a, b) { |
| 601 |
// Handle memory (skip recursion) |
| 602 |
if (memory.some(function (pair) { |
| 603 |
return pair.a === a && pair.b === b; |
| 604 |
})) { |
| 605 |
return true; |
| 606 |
} |
| 607 |
memory.push({ |
| 608 |
a: a, |
| 609 |
b: b |
| 610 |
}); |
| 611 |
var aObjType = objectType(a); |
| 612 |
var bObjType = objectType(b); |
| 613 |
if (aObjType !== 'object' || bObjType !== 'object') { |
| 614 |
// Handle literal `null` |
| 615 |
// Handle: Array, Map/Set, Date, Regxp/Function, boxed primitives |
| 616 |
return aObjType === bObjType && objTypeCallbacks[aObjType](a, b); |
| 617 |
} |
| 618 |
|
| 619 |
// NOTE: Literal null must not make it here as it would throw |
| 620 |
if (compareConstructors(a, b) === false) { |
| 621 |
return false; |
| 622 |
} |
| 623 |
var aProperties = []; |
| 624 |
var bProperties = []; |
| 625 |
|
| 626 |
// Be strict and go deep, no filtering with hasOwnProperty. |
| 627 |
for (var i in a) { |
| 628 |
// Collect a's properties |
| 629 |
aProperties.push(i); |
| 630 |
|
| 631 |
// Skip OOP methods that look the same |
| 632 |
if (a.constructor !== Object && typeof a.constructor !== 'undefined' && typeof a[i] === 'function' && typeof b[i] === 'function' && a[i].toString() === b[i].toString()) { |
| 633 |
continue; |
| 634 |
} |
| 635 |
if (!typeEquiv(a[i], b[i])) { |
| 636 |
return false; |
| 637 |
} |
| 638 |
} |
| 639 |
for (var _i in b) { |
| 640 |
// Collect b's properties |
| 641 |
bProperties.push(_i); |
| 642 |
} |
| 643 |
return objTypeCallbacks.array(aProperties.sort(), bProperties.sort()); |
| 644 |
} |
| 645 |
}; |
| 646 |
function typeEquiv(a, b) { |
| 647 |
// Optimization: Only perform type-specific comparison when pairs are not strictly equal. |
| 648 |
if (a === b) { |
| 649 |
return true; |
| 650 |
} |
| 651 |
var aType = _typeof(a); |
| 652 |
var bType = _typeof(b); |
| 653 |
if (aType !== bType) { |
| 654 |
// Support comparing primitive to boxed primitives |
| 655 |
// Try again after possibly unwrapping one |
| 656 |
return (aType === 'object' && BOXABLE_TYPES.has(objectType(a)) ? a.valueOf() : a) === (bType === 'object' && BOXABLE_TYPES.has(objectType(b)) ? b.valueOf() : b); |
| 657 |
} |
| 658 |
return entryTypeCallbacks[aType](a, b); |
| 659 |
} |
| 660 |
function innerEquiv(a, b) { |
| 661 |
var res = typeEquiv(a, b); |
| 662 |
// Release any retained objects and reset recursion detection for next call |
| 663 |
memory = []; |
| 664 |
return res; |
| 665 |
} |
| 666 |
|
| 667 |
/** |
| 668 |
* Test any two types of JavaScript values for equality. |
| 669 |
* |
| 670 |
* @author Philippe Rathé <[email protected]> |
| 671 |
* @author David Chan <[email protected]> |
| 672 |
*/ |
| 673 |
function equiv(a, b) { |
| 674 |
if (arguments.length === 2) { |
| 675 |
return a === b || innerEquiv(a, b); |
| 676 |
} |
| 677 |
|
| 678 |
// Given 0 or 1 arguments, just return true (nothing to compare). |
| 679 |
// Given (A,B,C,D) compare C,D then B,C then A,B. |
| 680 |
var i = arguments.length - 1; |
| 681 |
while (i > 0) { |
| 682 |
if (!innerEquiv(arguments[i - 1], arguments[i])) { |
| 683 |
return false; |
| 684 |
} |
| 685 |
i--; |
| 686 |
} |
| 687 |
return true; |
| 688 |
} |
| 689 |
|
| 690 |
/** |
| 691 |
* Config object: Maintain internal state |
| 692 |
* Later exposed as QUnit.config |
| 693 |
* `config` initialized at top of scope |
| 694 |
*/ |
| 695 |
var config = { |
| 696 |
// HTML Reporter: Modify document.title when suite is done |
| 697 |
altertitle: true, |
| 698 |
// TODO: Move here from /src/core.js in QUnit 3. |
| 699 |
// autostart: true, |
| 700 |
|
| 701 |
// HTML Reporter: collapse every test except the first failing test |
| 702 |
// If false, all failing tests will be expanded |
| 703 |
collapse: true, |
| 704 |
countStepsAsOne: false, |
| 705 |
// TODO: Make explicit in QUnit 3. |
| 706 |
// current: undefined, |
| 707 |
|
| 708 |
// whether or not to fail when there are zero tests |
| 709 |
// defaults to `true` |
| 710 |
failOnZeroTests: true, |
| 711 |
// Select by pattern or case-insensitive substring match against "moduleName: testName" |
| 712 |
filter: undefined, |
| 713 |
// TODO: Make explicit in QUnit 3. |
| 714 |
// fixture: undefined, |
| 715 |
|
| 716 |
// Depth up-to which object will be dumped |
| 717 |
maxDepth: 5, |
| 718 |
// Select case-insensitive match of the module name |
| 719 |
module: undefined, |
| 720 |
// HTML Reporter: Select module/test by array of internal IDs |
| 721 |
moduleId: undefined, |
| 722 |
// By default, run previously failed tests first |
| 723 |
// very useful in combination with "Hide passed tests" checked |
| 724 |
reorder: true, |
| 725 |
reporters: {}, |
| 726 |
// When enabled, all tests must call expect() |
| 727 |
requireExpects: false, |
| 728 |
// By default, scroll to top of the page when suite is done |
| 729 |
scrolltop: true, |
| 730 |
// TODO: Make explicit in QUnit 3. |
| 731 |
// seed: undefined, |
| 732 |
|
| 733 |
// The storage module to use for reordering tests |
| 734 |
storage: localSessionStorage, |
| 735 |
testId: undefined, |
| 736 |
// The updateRate controls how often QUnit will yield the main thread |
| 737 |
// between tests. This is mainly for the benefit of the HTML Reporter, |
| 738 |
// so that the browser can visually paint DOM changes with test results. |
| 739 |
// This also helps avoid causing browsers to prompt a warning about |
| 740 |
// long-running scripts. |
| 741 |
// TODO: Move here from /src/core.js in QUnit 3. |
| 742 |
// updateRate: 1000, |
| 743 |
|
| 744 |
// HTML Reporter: List of URL parameters that are given visual controls |
| 745 |
urlConfig: [], |
| 746 |
// Internal: The first unnamed module |
| 747 |
// |
| 748 |
// By being defined as the intial value for currentModule, it is the |
| 749 |
// receptacle and implied parent for any global tests. It is as if we |
| 750 |
// called `QUnit.module( "" );` before any other tests were defined. |
| 751 |
// |
| 752 |
// If we reach begin() and no tests were put in it, we dequeue it as if it |
| 753 |
// never existed, and in that case never expose it to the events and |
| 754 |
// callbacks API. |
| 755 |
// |
| 756 |
// When global tests are defined, then this unnamed module will execute |
| 757 |
// as any other module, including moduleStart/moduleDone events etc. |
| 758 |
// |
| 759 |
// Since this module isn't explicitly created by the user, they have no |
| 760 |
// access to add hooks for it. The hooks object is defined to comply |
| 761 |
// with internal expectations of test.js, but they will be empty. |
| 762 |
// To apply hooks, place tests explicitly in a QUnit.module(), and use |
| 763 |
// its hooks accordingly. |
| 764 |
// |
| 765 |
// For global hooks that apply to all tests and all modules, use QUnit.hooks. |
| 766 |
// |
| 767 |
// NOTE: This is *not* a "global module". It is not an ancestor of all modules |
| 768 |
// and tests. It is merely the parent for any tests defined globally, |
| 769 |
// before the first QUnit.module(). As such, the events for this unnamed |
| 770 |
// module will fire as normal, right after its last test, and *not* at |
| 771 |
// the end of the test run. |
| 772 |
// |
| 773 |
// NOTE: This also should probably also not become a global module, unless |
| 774 |
// we keep it out of the public API. For example, it would likely not |
| 775 |
// improve the user interface and plugin behaviour if all modules became |
| 776 |
// wrapped between the start and end events of this module, and thus |
| 777 |
// needlessly add indentation, indirection, or other visible noise. |
| 778 |
// Unit tests for the callbacks API would detect that as a regression. |
| 779 |
currentModule: { |
| 780 |
name: '', |
| 781 |
tests: [], |
| 782 |
childModules: [], |
| 783 |
testsRun: 0, |
| 784 |
testsIgnored: 0, |
| 785 |
hooks: { |
| 786 |
before: [], |
| 787 |
beforeEach: [], |
| 788 |
afterEach: [], |
| 789 |
after: [] |
| 790 |
} |
| 791 |
}, |
| 792 |
// Internal: Exposed to make resets easier |
| 793 |
// Ref https://github.com/qunitjs/qunit/pull/1598 |
| 794 |
globalHooks: {}, |
| 795 |
// Internal: ProcessingQueue singleton, created in /src/core.js |
| 796 |
pq: null, |
| 797 |
// Internal: Created in /src/core.js |
| 798 |
// TODO: Move definitions here in QUnit 3.0. |
| 799 |
// started: 0, |
| 800 |
|
| 801 |
// Internal state |
| 802 |
_event_listeners: Object.create(null), |
| 803 |
_event_memory: {}, |
| 804 |
_deprecated_timeout_shown: false, |
| 805 |
_deprecated_countEachStep_shown: false, |
| 806 |
blocking: true, |
| 807 |
callbacks: {}, |
| 808 |
modules: [], |
| 809 |
queue: [], |
| 810 |
stats: { |
| 811 |
all: 0, |
| 812 |
bad: 0, |
| 813 |
testCount: 0 |
| 814 |
} |
| 815 |
}; |
| 816 |
function readFlatPreconfigBoolean(val, dest) { |
| 817 |
if (typeof val === 'boolean' || typeof val === 'string' && val !== '') { |
| 818 |
config[dest] = val === true || val === 'true'; |
| 819 |
} |
| 820 |
} |
| 821 |
function readFlatPreconfigNumber(val, dest) { |
| 822 |
if (typeof val === 'number' || typeof val === 'string' && /^[0-9]+$/.test(val)) { |
| 823 |
config[dest] = +val; |
| 824 |
} |
| 825 |
} |
| 826 |
function readFlatPreconfigString(val, dest) { |
| 827 |
if (typeof val === 'string' && val !== '') { |
| 828 |
config[dest] = val; |
| 829 |
} |
| 830 |
} |
| 831 |
function readFlatPreconfigStringOrBoolean(val, dest) { |
| 832 |
if (typeof val === 'boolean' || typeof val === 'string' && val !== '') { |
| 833 |
config[dest] = val; |
| 834 |
} |
| 835 |
} |
| 836 |
function readFlatPreconfigStringArray(val, dest) { |
| 837 |
if (typeof val === 'string' && val !== '') { |
| 838 |
config[dest] = [val]; |
| 839 |
} |
| 840 |
} |
| 841 |
function readFlatPreconfig(obj) { |
| 842 |
readFlatPreconfigBoolean(obj.qunit_config_altertitle, 'altertitle'); |
| 843 |
readFlatPreconfigBoolean(obj.qunit_config_autostart, 'autostart'); |
| 844 |
readFlatPreconfigBoolean(obj.qunit_config_collapse, 'collapse'); |
| 845 |
readFlatPreconfigBoolean(obj.qunit_config_failonzerotests, 'failOnZeroTests'); |
| 846 |
readFlatPreconfigString(obj.qunit_config_filter, 'filter'); |
| 847 |
readFlatPreconfigString(obj.qunit_config_fixture, 'fixture'); |
| 848 |
readFlatPreconfigBoolean(obj.qunit_config_hidepassed, 'hidepassed'); |
| 849 |
readFlatPreconfigNumber(obj.qunit_config_maxdepth, 'maxDepth'); |
| 850 |
readFlatPreconfigString(obj.qunit_config_module, 'module'); |
| 851 |
readFlatPreconfigStringArray(obj.qunit_config_moduleid, 'moduleId'); |
| 852 |
readFlatPreconfigBoolean(obj.qunit_config_noglobals, 'noglobals'); |
| 853 |
readFlatPreconfigBoolean(obj.qunit_config_notrycatch, 'notrycatch'); |
| 854 |
readFlatPreconfigBoolean(obj.qunit_config_reorder, 'reorder'); |
| 855 |
readFlatPreconfigBoolean(obj.qunit_config_requireexpects, 'requireExpects'); |
| 856 |
readFlatPreconfigBoolean(obj.qunit_config_scrolltop, 'scrolltop'); |
| 857 |
readFlatPreconfigStringOrBoolean(obj.qunit_config_seed, 'seed'); |
| 858 |
readFlatPreconfigStringArray(obj.qunit_config_testid, 'testId'); |
| 859 |
readFlatPreconfigNumber(obj.qunit_config_testtimeout, 'testTimeout'); |
| 860 |
var reporterKeys = { |
| 861 |
qunit_config_reporters_console: 'console', |
| 862 |
qunit_config_reporters_tap: 'tap' |
| 863 |
}; |
| 864 |
for (var key in reporterKeys) { |
| 865 |
var val = obj[key]; |
| 866 |
// Based on readFlatPreconfigBoolean |
| 867 |
if (typeof val === 'boolean' || typeof val === 'string' && val !== '') { |
| 868 |
var dest = reporterKeys[key]; |
| 869 |
config.reporters[dest] = val === true || val === 'true' || val === '1'; |
| 870 |
} |
| 871 |
} |
| 872 |
} |
| 873 |
if (process$1 && 'env' in process$1) { |
| 874 |
readFlatPreconfig(process$1.env); |
| 875 |
} |
| 876 |
readFlatPreconfig(g); |
| 877 |
|
| 878 |
// Apply a predefined QUnit.config object |
| 879 |
// |
| 880 |
// Ignore QUnit.config if it is a QUnit distribution instead of preconfig. |
| 881 |
// That means QUnit was loaded twice! (Use the same approach as export.js) |
| 882 |
var preConfig = g && g.QUnit && !g.QUnit.version && g.QUnit.config; |
| 883 |
if (preConfig) { |
| 884 |
extend(config, preConfig); |
| 885 |
} |
| 886 |
|
| 887 |
// Push a loose unnamed module to the modules collection |
| 888 |
config.modules.push(config.currentModule); |
| 889 |
if (config.seed === 'true' || config.seed === true) { |
| 890 |
// Generate a random seed |
| 891 |
// Length of `Math.random()` fraction, in base 36, may vary from 6-14. |
| 892 |
// Pad and take slice to a consistent 10-digit value. |
| 893 |
config.seed = (Math.random().toString(36) + '0000000000').slice(2, 12); |
| 894 |
} |
| 895 |
|
| 896 |
var dump = (function () { |
| 897 |
function quote(str) { |
| 898 |
return '"' + str.toString().replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"'; |
| 899 |
} |
| 900 |
function literal(o) { |
| 901 |
return o + ''; |
| 902 |
} |
| 903 |
function join(pre, arr, post) { |
| 904 |
var s = dump.separator(); |
| 905 |
var inner = dump.indent(1); |
| 906 |
if (arr.join) { |
| 907 |
arr = arr.join(',' + s + inner); |
| 908 |
} |
| 909 |
if (!arr) { |
| 910 |
return pre + post; |
| 911 |
} |
| 912 |
var base = dump.indent(); |
| 913 |
return [pre, inner + arr, base + post].join(s); |
| 914 |
} |
| 915 |
function array(arr, stack) { |
| 916 |
if (dump.maxDepth && dump.depth > dump.maxDepth) { |
| 917 |
return '[object Array]'; |
| 918 |
} |
| 919 |
this.up(); |
| 920 |
var i = arr.length; |
| 921 |
var ret = new Array(i); |
| 922 |
while (i--) { |
| 923 |
ret[i] = this.parse(arr[i], undefined, stack); |
| 924 |
} |
| 925 |
this.down(); |
| 926 |
return join('[', ret, ']'); |
| 927 |
} |
| 928 |
function isArray(obj) { |
| 929 |
return ( |
| 930 |
// Native Arrays |
| 931 |
toString.call(obj) === '[object Array]' || |
| 932 |
// NodeList objects |
| 933 |
typeof obj.length === 'number' && obj.item !== undefined && (obj.length ? obj.item(0) === obj[0] : obj.item(0) === null && obj[0] === undefined) |
| 934 |
); |
| 935 |
} |
| 936 |
var reName = /^function (\w+)/; |
| 937 |
var dump = { |
| 938 |
// The objType is used mostly internally, you can fix a (custom) type in advance |
| 939 |
parse: function parse(obj, objType, stack) { |
| 940 |
stack = stack || []; |
| 941 |
var objIndex = stack.indexOf(obj); |
| 942 |
if (objIndex !== -1) { |
| 943 |
return "recursion(".concat(objIndex - stack.length, ")"); |
| 944 |
} |
| 945 |
objType = objType || this.typeOf(obj); |
| 946 |
var parser = this.parsers[objType]; |
| 947 |
var parserType = _typeof(parser); |
| 948 |
if (parserType === 'function') { |
| 949 |
stack.push(obj); |
| 950 |
var res = parser.call(this, obj, stack); |
| 951 |
stack.pop(); |
| 952 |
return res; |
| 953 |
} |
| 954 |
if (parserType === 'string') { |
| 955 |
return parser; |
| 956 |
} |
| 957 |
return '[ERROR: Missing QUnit.dump formatter for type ' + objType + ']'; |
| 958 |
}, |
| 959 |
typeOf: function typeOf(obj) { |
| 960 |
var type; |
| 961 |
if (obj === null) { |
| 962 |
type = 'null'; |
| 963 |
} else if (typeof obj === 'undefined') { |
| 964 |
type = 'undefined'; |
| 965 |
} else if (is('regexp', obj)) { |
| 966 |
type = 'regexp'; |
| 967 |
} else if (is('date', obj)) { |
| 968 |
type = 'date'; |
| 969 |
} else if (is('function', obj)) { |
| 970 |
type = 'function'; |
| 971 |
} else if (obj.setInterval !== undefined && obj.document !== undefined && obj.nodeType === undefined) { |
| 972 |
type = 'window'; |
| 973 |
} else if (obj.nodeType === 9) { |
| 974 |
type = 'document'; |
| 975 |
} else if (obj.nodeType) { |
| 976 |
type = 'node'; |
| 977 |
} else if (isArray(obj)) { |
| 978 |
type = 'array'; |
| 979 |
} else if (obj.constructor === Error.prototype.constructor) { |
| 980 |
type = 'error'; |
| 981 |
} else { |
| 982 |
type = _typeof(obj); |
| 983 |
} |
| 984 |
return type; |
| 985 |
}, |
| 986 |
separator: function separator() { |
| 987 |
if (this.multiline) { |
| 988 |
return this.HTML ? '<br />' : '\n'; |
| 989 |
} else { |
| 990 |
return this.HTML ? ' ' : ' '; |
| 991 |
} |
| 992 |
}, |
| 993 |
// Extra can be a number, shortcut for increasing-calling-decreasing |
| 994 |
indent: function indent(extra) { |
| 995 |
if (!this.multiline) { |
| 996 |
return ''; |
| 997 |
} |
| 998 |
var chr = this.indentChar; |
| 999 |
if (this.HTML) { |
| 1000 |
chr = chr.replace(/\t/g, ' ').replace(/ /g, ' '); |
| 1001 |
} |
| 1002 |
return new Array(this.depth + (extra || 0)).join(chr); |
| 1003 |
}, |
| 1004 |
up: function up(a) { |
| 1005 |
this.depth += a || 1; |
| 1006 |
}, |
| 1007 |
down: function down(a) { |
| 1008 |
this.depth -= a || 1; |
| 1009 |
}, |
| 1010 |
setParser: function setParser(name, parser) { |
| 1011 |
this.parsers[name] = parser; |
| 1012 |
}, |
| 1013 |
// The next 3 are exposed so you can use them |
| 1014 |
quote: quote, |
| 1015 |
literal: literal, |
| 1016 |
join: join, |
| 1017 |
depth: 1, |
| 1018 |
maxDepth: config.maxDepth, |
| 1019 |
// This is the list of parsers, to modify them, use dump.setParser |
| 1020 |
parsers: { |
| 1021 |
window: '[Window]', |
| 1022 |
document: '[Document]', |
| 1023 |
error: function error(_error) { |
| 1024 |
return 'Error("' + _error.message + '")'; |
| 1025 |
}, |
| 1026 |
// This has been unused since QUnit 1.0.0. |
| 1027 |
// @todo Deprecate and remove. |
| 1028 |
unknown: '[Unknown]', |
| 1029 |
null: 'null', |
| 1030 |
undefined: 'undefined', |
| 1031 |
function: function _function(fn) { |
| 1032 |
var ret = 'function'; |
| 1033 |
|
| 1034 |
// Functions never have name in IE |
| 1035 |
var name = 'name' in fn ? fn.name : (reName.exec(fn) || [])[1]; |
| 1036 |
if (name) { |
| 1037 |
ret += ' ' + name; |
| 1038 |
} |
| 1039 |
ret += '('; |
| 1040 |
ret = [ret, dump.parse(fn, 'functionArgs'), '){'].join(''); |
| 1041 |
return join(ret, dump.parse(fn, 'functionCode'), '}'); |
| 1042 |
}, |
| 1043 |
array: array, |
| 1044 |
nodelist: array, |
| 1045 |
arguments: array, |
| 1046 |
object: function object(map, stack) { |
| 1047 |
var ret = []; |
| 1048 |
if (dump.maxDepth && dump.depth > dump.maxDepth) { |
| 1049 |
return '[object Object]'; |
| 1050 |
} |
| 1051 |
dump.up(); |
| 1052 |
var keys = []; |
| 1053 |
for (var key in map) { |
| 1054 |
keys.push(key); |
| 1055 |
} |
| 1056 |
|
| 1057 |
// Some properties are not always enumerable on Error objects. |
| 1058 |
var nonEnumerableProperties = ['message', 'name']; |
| 1059 |
for (var i in nonEnumerableProperties) { |
| 1060 |
var _key = nonEnumerableProperties[i]; |
| 1061 |
if (_key in map && !inArray(_key, keys)) { |
| 1062 |
keys.push(_key); |
| 1063 |
} |
| 1064 |
} |
| 1065 |
keys.sort(); |
| 1066 |
for (var _i = 0; _i < keys.length; _i++) { |
| 1067 |
var _key2 = keys[_i]; |
| 1068 |
var val = map[_key2]; |
| 1069 |
ret.push(dump.parse(_key2, 'key') + ': ' + dump.parse(val, undefined, stack)); |
| 1070 |
} |
| 1071 |
dump.down(); |
| 1072 |
return join('{', ret, '}'); |
| 1073 |
}, |
| 1074 |
node: function node(_node) { |
| 1075 |
var open = dump.HTML ? '<' : '<'; |
| 1076 |
var close = dump.HTML ? '>' : '>'; |
| 1077 |
var tag = _node.nodeName.toLowerCase(); |
| 1078 |
var ret = open + tag; |
| 1079 |
var attrs = _node.attributes; |
| 1080 |
if (attrs) { |
| 1081 |
for (var i = 0; i < attrs.length; i++) { |
| 1082 |
var val = attrs[i].nodeValue; |
| 1083 |
|
| 1084 |
// IE6 includes all attributes in .attributes, even ones not explicitly |
| 1085 |
// set. Those have values like undefined, null, 0, false, "" or |
| 1086 |
// "inherit". |
| 1087 |
if (val && val !== 'inherit') { |
| 1088 |
ret += ' ' + attrs[i].nodeName + '=' + dump.parse(val, 'attribute'); |
| 1089 |
} |
| 1090 |
} |
| 1091 |
} |
| 1092 |
ret += close; |
| 1093 |
|
| 1094 |
// Show content of TextNode or CDATASection |
| 1095 |
if (_node.nodeType === 3 || _node.nodeType === 4) { |
| 1096 |
ret += _node.nodeValue; |
| 1097 |
} |
| 1098 |
return ret + open + '/' + tag + close; |
| 1099 |
}, |
| 1100 |
// Function calls it internally, it's the arguments part of the function |
| 1101 |
functionArgs: function functionArgs(fn) { |
| 1102 |
var l = fn.length; |
| 1103 |
if (!l) { |
| 1104 |
return ''; |
| 1105 |
} |
| 1106 |
var args = new Array(l); |
| 1107 |
while (l--) { |
| 1108 |
// 97 is 'a' |
| 1109 |
args[l] = String.fromCharCode(97 + l); |
| 1110 |
} |
| 1111 |
return ' ' + args.join(', ') + ' '; |
| 1112 |
}, |
| 1113 |
// Object calls it internally, the key part of an item in a map |
| 1114 |
key: quote, |
| 1115 |
// Function calls it internally, it's the content of the function |
| 1116 |
functionCode: '[code]', |
| 1117 |
// Node calls it internally, it's a html attribute value |
| 1118 |
attribute: quote, |
| 1119 |
string: quote, |
| 1120 |
date: quote, |
| 1121 |
regexp: literal, |
| 1122 |
number: literal, |
| 1123 |
boolean: literal, |
| 1124 |
symbol: function symbol(sym) { |
| 1125 |
return sym.toString(); |
| 1126 |
} |
| 1127 |
}, |
| 1128 |
// If true, entities are escaped ( <, >, \t, space and \n ) |
| 1129 |
HTML: false, |
| 1130 |
// Indentation unit |
| 1131 |
indentChar: ' ', |
| 1132 |
// If true, items in a collection, are separated by a \n, else just a space. |
| 1133 |
multiline: true |
| 1134 |
}; |
| 1135 |
return dump; |
| 1136 |
})(); |
| 1137 |
|
| 1138 |
// Support: IE 9 |
| 1139 |
// Detect if the console object exists and no-op otherwise. |
| 1140 |
// This allows support for IE 9, which doesn't have a console |
| 1141 |
// object if the developer tools are not open. |
| 1142 |
|
| 1143 |
// Support: IE 9 |
| 1144 |
// Function#bind is supported, but no console.log.bind(). |
| 1145 |
|
| 1146 |
// Support: SpiderMonkey (mozjs 68+) |
| 1147 |
// The console object has a log method, but no warn method. |
| 1148 |
|
| 1149 |
var Logger = { |
| 1150 |
warn: console$1 ? Function.prototype.bind.call(console$1.warn || console$1.log, console$1) : function () {} |
| 1151 |
}; |
| 1152 |
|
| 1153 |
var SuiteReport = /*#__PURE__*/function () { |
| 1154 |
function SuiteReport(name, parentSuite) { |
| 1155 |
_classCallCheck(this, SuiteReport); |
| 1156 |
this.name = name; |
| 1157 |
this.fullName = parentSuite ? parentSuite.fullName.concat(name) : []; |
| 1158 |
|
| 1159 |
// When an "error" event is emitted from onUncaughtException(), the |
| 1160 |
// "runEnd" event should report the status as failed. The "runEnd" event data |
| 1161 |
// is tracked through this property (via the "runSuite" instance). |
| 1162 |
this.globalFailureCount = 0; |
| 1163 |
this.tests = []; |
| 1164 |
this.childSuites = []; |
| 1165 |
if (parentSuite) { |
| 1166 |
parentSuite.pushChildSuite(this); |
| 1167 |
} |
| 1168 |
} |
| 1169 |
return _createClass(SuiteReport, [{ |
| 1170 |
key: "start", |
| 1171 |
value: function start(recordTime) { |
| 1172 |
if (recordTime) { |
| 1173 |
this._startTime = performance.now(); |
| 1174 |
} |
| 1175 |
return { |
| 1176 |
name: this.name, |
| 1177 |
fullName: this.fullName.slice(), |
| 1178 |
tests: this.tests.map(function (test) { |
| 1179 |
return test.start(); |
| 1180 |
}), |
| 1181 |
childSuites: this.childSuites.map(function (suite) { |
| 1182 |
return suite.start(); |
| 1183 |
}), |
| 1184 |
testCounts: { |
| 1185 |
total: this.getTestCounts().total |
| 1186 |
} |
| 1187 |
}; |
| 1188 |
} |
| 1189 |
}, { |
| 1190 |
key: "end", |
| 1191 |
value: function end(recordTime) { |
| 1192 |
if (recordTime) { |
| 1193 |
this._endTime = performance.now(); |
| 1194 |
} |
| 1195 |
return { |
| 1196 |
name: this.name, |
| 1197 |
fullName: this.fullName.slice(), |
| 1198 |
tests: this.tests.map(function (test) { |
| 1199 |
return test.end(); |
| 1200 |
}), |
| 1201 |
childSuites: this.childSuites.map(function (suite) { |
| 1202 |
return suite.end(); |
| 1203 |
}), |
| 1204 |
testCounts: this.getTestCounts(), |
| 1205 |
runtime: this.getRuntime(), |
| 1206 |
status: this.getStatus() |
| 1207 |
}; |
| 1208 |
} |
| 1209 |
}, { |
| 1210 |
key: "pushChildSuite", |
| 1211 |
value: function pushChildSuite(suite) { |
| 1212 |
this.childSuites.push(suite); |
| 1213 |
} |
| 1214 |
}, { |
| 1215 |
key: "pushTest", |
| 1216 |
value: function pushTest(test) { |
| 1217 |
this.tests.push(test); |
| 1218 |
} |
| 1219 |
}, { |
| 1220 |
key: "getRuntime", |
| 1221 |
value: function getRuntime() { |
| 1222 |
return Math.round(this._endTime - this._startTime); |
| 1223 |
} |
| 1224 |
}, { |
| 1225 |
key: "getTestCounts", |
| 1226 |
value: function getTestCounts() { |
| 1227 |
var counts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { |
| 1228 |
passed: 0, |
| 1229 |
failed: 0, |
| 1230 |
skipped: 0, |
| 1231 |
todo: 0, |
| 1232 |
total: 0 |
| 1233 |
}; |
| 1234 |
counts.failed += this.globalFailureCount; |
| 1235 |
counts.total += this.globalFailureCount; |
| 1236 |
counts = this.tests.reduce(function (counts, test) { |
| 1237 |
if (test.valid) { |
| 1238 |
counts[test.getStatus()]++; |
| 1239 |
counts.total++; |
| 1240 |
} |
| 1241 |
return counts; |
| 1242 |
}, counts); |
| 1243 |
return this.childSuites.reduce(function (counts, suite) { |
| 1244 |
return suite.getTestCounts(counts); |
| 1245 |
}, counts); |
| 1246 |
} |
| 1247 |
}, { |
| 1248 |
key: "getStatus", |
| 1249 |
value: function getStatus() { |
| 1250 |
var _this$getTestCounts = this.getTestCounts(), |
| 1251 |
total = _this$getTestCounts.total, |
| 1252 |
failed = _this$getTestCounts.failed, |
| 1253 |
skipped = _this$getTestCounts.skipped, |
| 1254 |
todo = _this$getTestCounts.todo; |
| 1255 |
if (failed) { |
| 1256 |
return 'failed'; |
| 1257 |
} else { |
| 1258 |
if (skipped === total) { |
| 1259 |
return 'skipped'; |
| 1260 |
} else if (todo === total) { |
| 1261 |
return 'todo'; |
| 1262 |
} else { |
| 1263 |
return 'passed'; |
| 1264 |
} |
| 1265 |
} |
| 1266 |
} |
| 1267 |
}]); |
| 1268 |
}(); |
| 1269 |
|
| 1270 |
var moduleStack = []; |
| 1271 |
var runSuite = new SuiteReport(); |
| 1272 |
function isParentModuleInQueue() { |
| 1273 |
var modulesInQueue = config.modules.filter(function (module) { |
| 1274 |
return !module.ignored; |
| 1275 |
}).map(function (module) { |
| 1276 |
return module.moduleId; |
| 1277 |
}); |
| 1278 |
return moduleStack.some(function (module) { |
| 1279 |
return modulesInQueue.includes(module.moduleId); |
| 1280 |
}); |
| 1281 |
} |
| 1282 |
function createModule(name, testEnvironment, modifiers) { |
| 1283 |
var parentModule = moduleStack.length ? moduleStack.slice(-1)[0] : null; |
| 1284 |
var moduleName = parentModule !== null ? [parentModule.name, name].join(' > ') : name; |
| 1285 |
var parentSuite = parentModule ? parentModule.suiteReport : runSuite; |
| 1286 |
var skip = parentModule !== null && parentModule.skip || modifiers.skip; |
| 1287 |
var todo = parentModule !== null && parentModule.todo || modifiers.todo; |
| 1288 |
var env = {}; |
| 1289 |
if (parentModule) { |
| 1290 |
extend(env, parentModule.testEnvironment); |
| 1291 |
} |
| 1292 |
extend(env, testEnvironment); |
| 1293 |
var module = { |
| 1294 |
name: moduleName, |
| 1295 |
parentModule: parentModule, |
| 1296 |
hooks: { |
| 1297 |
before: [], |
| 1298 |
beforeEach: [], |
| 1299 |
afterEach: [], |
| 1300 |
after: [] |
| 1301 |
}, |
| 1302 |
testEnvironment: env, |
| 1303 |
tests: [], |
| 1304 |
moduleId: generateHash(moduleName), |
| 1305 |
testsRun: 0, |
| 1306 |
testsIgnored: 0, |
| 1307 |
childModules: [], |
| 1308 |
suiteReport: new SuiteReport(name, parentSuite), |
| 1309 |
// Initialised by test.js when the module start executing, |
| 1310 |
// i.e. before the first test in this module (or a child). |
| 1311 |
stats: null, |
| 1312 |
// Pass along `skip` and `todo` properties from parent module, in case |
| 1313 |
// there is one, to childs. And use own otherwise. |
| 1314 |
// This property will be used to mark own tests and tests of child suites |
| 1315 |
// as either `skipped` or `todo`. |
| 1316 |
skip: skip, |
| 1317 |
todo: skip ? false : todo, |
| 1318 |
ignored: modifiers.ignored || false |
| 1319 |
}; |
| 1320 |
if (parentModule) { |
| 1321 |
parentModule.childModules.push(module); |
| 1322 |
} |
| 1323 |
config.modules.push(module); |
| 1324 |
return module; |
| 1325 |
} |
| 1326 |
function setHookFromEnvironment(hooks, environment, name) { |
| 1327 |
var potentialHook = environment[name]; |
| 1328 |
if (typeof potentialHook === 'function') { |
| 1329 |
hooks[name].push(potentialHook); |
| 1330 |
} |
| 1331 |
delete environment[name]; |
| 1332 |
} |
| 1333 |
function makeSetHook(module, hookName) { |
| 1334 |
return function setHook(callback) { |
| 1335 |
if (config.currentModule !== module) { |
| 1336 |
Logger.warn('The `' + hookName + '` hook was called inside the wrong module (`' + config.currentModule.name + '`). ' + 'Instead, use hooks provided by the callback to the containing module (`' + module.name + '`). ' + 'This will become an error in QUnit 3.0.'); |
| 1337 |
} |
| 1338 |
module.hooks[hookName].push(callback); |
| 1339 |
}; |
| 1340 |
} |
| 1341 |
function processModule(name, options, scope) { |
| 1342 |
var modifiers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; |
| 1343 |
if (typeof options === 'function') { |
| 1344 |
scope = options; |
| 1345 |
options = undefined; |
| 1346 |
} |
| 1347 |
var module = createModule(name, options, modifiers); |
| 1348 |
|
| 1349 |
// Transfer any initial hooks from the options object to the 'hooks' object |
| 1350 |
var testEnvironment = module.testEnvironment; |
| 1351 |
var hooks = module.hooks; |
| 1352 |
setHookFromEnvironment(hooks, testEnvironment, 'before'); |
| 1353 |
setHookFromEnvironment(hooks, testEnvironment, 'beforeEach'); |
| 1354 |
setHookFromEnvironment(hooks, testEnvironment, 'afterEach'); |
| 1355 |
setHookFromEnvironment(hooks, testEnvironment, 'after'); |
| 1356 |
var moduleFns = { |
| 1357 |
before: makeSetHook(module, 'before'), |
| 1358 |
beforeEach: makeSetHook(module, 'beforeEach'), |
| 1359 |
afterEach: makeSetHook(module, 'afterEach'), |
| 1360 |
after: makeSetHook(module, 'after') |
| 1361 |
}; |
| 1362 |
var prevModule = config.currentModule; |
| 1363 |
config.currentModule = module; |
| 1364 |
if (typeof scope === 'function') { |
| 1365 |
moduleStack.push(module); |
| 1366 |
try { |
| 1367 |
var cbReturnValue = scope.call(module.testEnvironment, moduleFns); |
| 1368 |
if (cbReturnValue && typeof cbReturnValue.then === 'function') { |
| 1369 |
Logger.warn('Returning a promise from a module callback is not supported. ' + 'Instead, use hooks for async behavior. ' + 'This will become an error in QUnit 3.0.'); |
| 1370 |
} |
| 1371 |
} finally { |
| 1372 |
// If the module closure threw an uncaught error during the load phase, |
| 1373 |
// we let this bubble up to global error handlers. But, not until after |
| 1374 |
// we teardown internal state to ensure correct module nesting. |
| 1375 |
// Ref https://github.com/qunitjs/qunit/issues/1478. |
| 1376 |
moduleStack.pop(); |
| 1377 |
config.currentModule = module.parentModule || prevModule; |
| 1378 |
} |
| 1379 |
} |
| 1380 |
} |
| 1381 |
|
| 1382 |
/** |
| 1383 |
* Clear the SuiteReport tree of all tests and leave only current module as child suite |
| 1384 |
* |
| 1385 |
* This should be called before defining the first module.only() or test.only() |
| 1386 |
* because otherwise: |
| 1387 |
* - `runEnd.testCounts` is too high. |
| 1388 |
* - UI (HtmlReporter) and TAP (TapReporter) display totals too high. |
| 1389 |
* - Test runners like QTap might timeout because the TAP plan |
| 1390 |
* would be printed as "1..9" even if only 2 tests are run, |
| 1391 |
* which means tap-finished will wait for 3-9. |
| 1392 |
*/ |
| 1393 |
function clearSuiteReports(currentModule) { |
| 1394 |
var childSuite = null; |
| 1395 |
var suiteReport = currentModule.suiteReport; |
| 1396 |
while (suiteReport) { |
| 1397 |
suiteReport.tests.length = 0; |
| 1398 |
var i = suiteReport.childSuites.indexOf(childSuite); |
| 1399 |
if (i === -1) { |
| 1400 |
suiteReport.childSuites.length = 0; |
| 1401 |
} else { |
| 1402 |
// Reduce in-place to just currentModule.suiteReport or its intermediary |
| 1403 |
suiteReport.childSuites.splice(0, i); |
| 1404 |
suiteReport.childSuites.splice(1); |
| 1405 |
} |
| 1406 |
if (suiteReport === runSuite) { |
| 1407 |
suiteReport = null; |
| 1408 |
} else { |
| 1409 |
childSuite = suiteReport; |
| 1410 |
currentModule = currentModule.parentModule; |
| 1411 |
suiteReport = currentModule && currentModule.suiteReport || runSuite; |
| 1412 |
} |
| 1413 |
} |
| 1414 |
} |
| 1415 |
var focused$1 = false; // indicates that the "only" filter was used |
| 1416 |
|
| 1417 |
function module$1(name, options, scope) { |
| 1418 |
var ignored = focused$1 && !isParentModuleInQueue(); |
| 1419 |
processModule(name, options, scope, { |
| 1420 |
ignored: ignored |
| 1421 |
}); |
| 1422 |
} |
| 1423 |
module$1.only = function () { |
| 1424 |
if (!focused$1) { |
| 1425 |
// Upon the first module.only() call, |
| 1426 |
// delete any and all previously registered modules and tests. |
| 1427 |
config.modules.length = 0; |
| 1428 |
config.queue.length = 0; |
| 1429 |
clearSuiteReports(config.currentModule); |
| 1430 |
|
| 1431 |
// Ignore any tests declared after this block within the same |
| 1432 |
// module parent. https://github.com/qunitjs/qunit/issues/1645 |
| 1433 |
config.currentModule.ignored = true; |
| 1434 |
} |
| 1435 |
focused$1 = true; |
| 1436 |
processModule.apply(void 0, arguments); |
| 1437 |
}; |
| 1438 |
module$1.skip = function (name, options, scope) { |
| 1439 |
if (focused$1) { |
| 1440 |
return; |
| 1441 |
} |
| 1442 |
processModule(name, options, scope, { |
| 1443 |
skip: true |
| 1444 |
}); |
| 1445 |
}; |
| 1446 |
module$1.if = function (name, condition, options, scope) { |
| 1447 |
if (focused$1) { |
| 1448 |
return; |
| 1449 |
} |
| 1450 |
processModule(name, options, scope, { |
| 1451 |
skip: !condition |
| 1452 |
}); |
| 1453 |
}; |
| 1454 |
module$1.todo = function (name, options, scope) { |
| 1455 |
if (focused$1) { |
| 1456 |
return; |
| 1457 |
} |
| 1458 |
processModule(name, options, scope, { |
| 1459 |
todo: true |
| 1460 |
}); |
| 1461 |
}; |
| 1462 |
|
| 1463 |
// Stacktrace cleaner to focus on the path from error source to test suite. |
| 1464 |
// |
| 1465 |
// This should reduce a raw stack trace like this: |
| 1466 |
// |
| 1467 |
// > foo.broken()@/example/foo.js |
| 1468 |
// > Bar@/example/bar.js |
| 1469 |
// > @/test/bar.test.js |
| 1470 |
// > @/lib/qunit.js:500:12 |
| 1471 |
// > @/lib/qunit.js:100:28 |
| 1472 |
// > @/lib/qunit.js:200:56 |
| 1473 |
// > setTimeout@ |
| 1474 |
// > @/dist/vendor.js |
| 1475 |
// |
| 1476 |
// and shorten it to show up until the end of the user's bar.test.js code. |
| 1477 |
// |
| 1478 |
// > foo.broken()@/example/foo.js |
| 1479 |
// > Bar@/example/bar.js |
| 1480 |
// > @/test/bar.test.js |
| 1481 |
// |
| 1482 |
// QUnit will obtain one example trace (once per process/pageload suffices), |
| 1483 |
// strip off any :<line> and :<line>:<column>, and use that as match needle, |
| 1484 |
// to the first QUnit-internal frames, and then stop at that point. |
| 1485 |
// Any later frames, including those that are outside QUnit again, will be ommitted |
| 1486 |
// as being uninteresting to the test, since QUnit will have either started or |
| 1487 |
// resumed the test. This we also clean away browser built-ins, or other |
| 1488 |
// vendor/bundler that may be higher up the stack. |
| 1489 |
// |
| 1490 |
// Stripping :<line>:<column> is not for prettyness, it is essential for the |
| 1491 |
// match needle to work, since this sample trace will by definitin not be the |
| 1492 |
// same line as e.g. the QUnit.test() call we're trying to identify. |
| 1493 |
// |
| 1494 |
// See also: |
| 1495 |
// - https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack |
| 1496 |
|
| 1497 |
function qunitFileName() { |
| 1498 |
var error = new Error(); |
| 1499 |
if (!error.stack) { |
| 1500 |
// Copy of sourceFromStacktrace() to avoid circular dependency |
| 1501 |
// Support: IE 9-11 |
| 1502 |
try { |
| 1503 |
throw error; |
| 1504 |
} catch (err) { |
| 1505 |
error = err; |
| 1506 |
} |
| 1507 |
} |
| 1508 |
return (error.stack || '' |
| 1509 |
// Copy of extractStacktrace() to avoid circular dependency |
| 1510 |
// Support: V8/Chrome |
| 1511 |
).replace(/^error$\n/im, '').split('\n')[0] |
| 1512 |
// Global replace, because a frame like localhost:4000/lib/qunit.js:1234:50, |
| 1513 |
// would otherwise (harmlessly, but uselessly) remove only the port (first match). |
| 1514 |
// https://github.com/qunitjs/qunit/issues/1769 |
| 1515 |
.replace(/(:\d+)+\)?/g, '') |
| 1516 |
// Remove anything prior to the last slash (Unix/Windows) from the last frame, |
| 1517 |
// leaving only "qunit.js". |
| 1518 |
.replace(/.+[/\\]/, ''); |
| 1519 |
} |
| 1520 |
var fileName = qunitFileName(); |
| 1521 |
|
| 1522 |
/** |
| 1523 |
* Responsibilities: |
| 1524 |
* - For internal errors from QUnit itself, remove the first qunit.js frames. |
| 1525 |
* - For errors in Node.js, format any remaining qunit.js and node:internal |
| 1526 |
* frames as internal (i.e. grey out). |
| 1527 |
* |
| 1528 |
* @param {string} stack Error#stack |
| 1529 |
* @param {Function} formatInternal Format a string in an "internal" color |
| 1530 |
* @param {string|null} [eToString] Error#toString() to help remove |
| 1531 |
* noise from Node.js/V8 stack traces. |
| 1532 |
*/ |
| 1533 |
function annotateStacktrace(stack, formatInternal) { |
| 1534 |
var eToString = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; |
| 1535 |
var frames = stack.split('\n'); |
| 1536 |
var annotated = []; |
| 1537 |
if (eToString && eToString.indexOf(frames[0]) !== -1) { |
| 1538 |
// In Firefox and Safari e.stack starts with frame 0, but in V8 (Chrome/Node.js), |
| 1539 |
// e.stack starts first stringified message. Preserve this separately, |
| 1540 |
// so that, below, we can distinguish between internal frames on top |
| 1541 |
// (to remove) vs later internal frames (to format differently). |
| 1542 |
annotated.push(frames.shift()); |
| 1543 |
} |
| 1544 |
var initialInternal = true; |
| 1545 |
for (var i = 0; i < frames.length; i++) { |
| 1546 |
var frame = frames[i]; |
| 1547 |
var isInternal = fileName && frame.indexOf(fileName) !== -1 || |
| 1548 |
// Support Node 16+: ESM-style |
| 1549 |
// "at wrap (node:internal/modules/cjs/loader:1)" |
| 1550 |
frame.indexOf('node:internal/') !== -1 || |
| 1551 |
// Support Node 12-14 (CJS-style) |
| 1552 |
// "at load (internal/modules/cjs/loader.js:7)" |
| 1553 |
frame.match(/^\s+at .+\(internal[^)]*\)$/) || |
| 1554 |
// Support Node 10 |
| 1555 |
// "at listOnTimeout (timers.js:263)" |
| 1556 |
// Avoid matching "(C:)" on Windows |
| 1557 |
// Avoid matching "(http:)" |
| 1558 |
frame.match(/^\s+at .+\([a-z]+\.js[:\d]*\)$/); |
| 1559 |
if (!isInternal) { |
| 1560 |
initialInternal = false; |
| 1561 |
} |
| 1562 |
// Remove initial internal frames entirely. |
| 1563 |
if (!initialInternal) { |
| 1564 |
annotated.push(isInternal ? formatInternal(frame) : frame); |
| 1565 |
} |
| 1566 |
} |
| 1567 |
return annotated.join('\n'); |
| 1568 |
} |
| 1569 |
function extractStacktrace(e, offset) { |
| 1570 |
offset = offset === undefined ? 4 : offset; |
| 1571 |
|
| 1572 |
// Support: IE9, e.stack is not supported, we will return undefined |
| 1573 |
if (e && e.stack) { |
| 1574 |
var stack = e.stack.split('\n'); |
| 1575 |
// In Firefox and Safari, e.stack starts immediately with the first frame. |
| 1576 |
// |
| 1577 |
// In V8 (Chrome/Node.js), the stack starts first with a stringified error message, |
| 1578 |
// and the real stack starting on line 2. |
| 1579 |
if (/^error$/i.test(stack[0])) { |
| 1580 |
stack.shift(); |
| 1581 |
} |
| 1582 |
if (fileName) { |
| 1583 |
var include = []; |
| 1584 |
for (var i = offset; i < stack.length; i++) { |
| 1585 |
if (stack[i].indexOf(fileName) !== -1) { |
| 1586 |
break; |
| 1587 |
} |
| 1588 |
include.push(stack[i]); |
| 1589 |
} |
| 1590 |
if (include.length) { |
| 1591 |
return include.join('\n'); |
| 1592 |
} |
| 1593 |
} |
| 1594 |
return stack[offset]; |
| 1595 |
} |
| 1596 |
} |
| 1597 |
function sourceFromStacktrace(offset) { |
| 1598 |
var error = new Error(); |
| 1599 |
|
| 1600 |
// Support: IE 9-11, iOS 7 |
| 1601 |
// Not all browsers generate the `stack` property for `new Error()` |
| 1602 |
// See also https://github.com/qunitjs/qunit/issues/636 |
| 1603 |
if (!error.stack) { |
| 1604 |
try { |
| 1605 |
throw error; |
| 1606 |
} catch (err) { |
| 1607 |
error = err; |
| 1608 |
} |
| 1609 |
} |
| 1610 |
return extractStacktrace(error, offset); |
| 1611 |
} |
| 1612 |
|
| 1613 |
var Assert = /*#__PURE__*/function () { |
| 1614 |
function Assert(testContext) { |
| 1615 |
_classCallCheck(this, Assert); |
| 1616 |
this.test = testContext; |
| 1617 |
} |
| 1618 |
return _createClass(Assert, [{ |
| 1619 |
key: "timeout", |
| 1620 |
value: function timeout(duration) { |
| 1621 |
if (typeof duration !== 'number') { |
| 1622 |
throw new Error('You must pass a number as the duration to assert.timeout'); |
| 1623 |
} |
| 1624 |
this.test.timeout = duration; |
| 1625 |
|
| 1626 |
// If a timeout has been set, clear it and reset with the new duration |
| 1627 |
if (config.timeout) { |
| 1628 |
clearTimeout(config.timeout); |
| 1629 |
config.timeout = null; |
| 1630 |
if (config.timeoutHandler && this.test.timeout > 0) { |
| 1631 |
this.test.internalResetTimeout(this.test.timeout); |
| 1632 |
} |
| 1633 |
} |
| 1634 |
} |
| 1635 |
|
| 1636 |
// Documents a "step", which is a string value, in a test as a passing assertion |
| 1637 |
}, { |
| 1638 |
key: "step", |
| 1639 |
value: function step(message) { |
| 1640 |
var assertionMessage = message; |
| 1641 |
var result = !!message; |
| 1642 |
this.test.steps.push(message); |
| 1643 |
if (typeof message === 'undefined' || message === '') { |
| 1644 |
assertionMessage = 'You must provide a message to assert.step'; |
| 1645 |
} else if (typeof message !== 'string') { |
| 1646 |
assertionMessage = 'You must provide a string value to assert.step'; |
| 1647 |
result = false; |
| 1648 |
} |
| 1649 |
this.pushResult({ |
| 1650 |
result: result, |
| 1651 |
message: assertionMessage |
| 1652 |
}); |
| 1653 |
} |
| 1654 |
|
| 1655 |
// Verifies the steps in a test match a given array of string values |
| 1656 |
}, { |
| 1657 |
key: "verifySteps", |
| 1658 |
value: function verifySteps(steps, message) { |
| 1659 |
// Since the steps array is just string values, we can clone with slice |
| 1660 |
var actualStepsClone = this.test.steps.slice(); |
| 1661 |
this.deepEqual(actualStepsClone, steps, message); |
| 1662 |
this.test.stepsCount += this.test.steps.length; |
| 1663 |
this.test.steps.length = 0; |
| 1664 |
} |
| 1665 |
}, { |
| 1666 |
key: "expect", |
| 1667 |
value: function expect(asserts) { |
| 1668 |
if (arguments.length === 1) { |
| 1669 |
this.test.expected = asserts; |
| 1670 |
} else { |
| 1671 |
return this.test.expected; |
| 1672 |
} |
| 1673 |
} |
| 1674 |
|
| 1675 |
// Create a new async pause and return a new function that can release the pause. |
| 1676 |
}, { |
| 1677 |
key: "async", |
| 1678 |
value: function async(count) { |
| 1679 |
if (count === undefined) { |
| 1680 |
count = 1; |
| 1681 |
} else if (typeof count !== 'number') { |
| 1682 |
throw new TypeError('async takes number as an input'); |
| 1683 |
} |
| 1684 |
var requiredCalls = count; |
| 1685 |
return this.test.internalStop(requiredCalls); |
| 1686 |
} |
| 1687 |
}, { |
| 1688 |
key: "closeTo", |
| 1689 |
value: function closeTo(actual, expected, delta, message) { |
| 1690 |
if (typeof delta !== 'number') { |
| 1691 |
throw new TypeError('closeTo() requires a delta argument'); |
| 1692 |
} |
| 1693 |
this.pushResult({ |
| 1694 |
result: Math.abs(actual - expected) <= delta, |
| 1695 |
actual: actual, |
| 1696 |
expected: expected, |
| 1697 |
message: message || "value should be within ".concat(delta, " inclusive") |
| 1698 |
}); |
| 1699 |
} |
| 1700 |
|
| 1701 |
// Alias of pushResult. |
| 1702 |
}, { |
| 1703 |
key: "push", |
| 1704 |
value: function push(result, actual, expected, message, negative) { |
| 1705 |
var currentAssert = this instanceof Assert ? this : config.current.assert; |
| 1706 |
return currentAssert.pushResult({ |
| 1707 |
result: result, |
| 1708 |
actual: actual, |
| 1709 |
expected: expected, |
| 1710 |
message: message, |
| 1711 |
negative: negative |
| 1712 |
}); |
| 1713 |
} |
| 1714 |
|
| 1715 |
// Public API to internal test.pushResult() |
| 1716 |
}, { |
| 1717 |
key: "pushResult", |
| 1718 |
value: function pushResult(resultInfo) { |
| 1719 |
// Destructure of resultInfo = { result, actual, expected, message, negative } |
| 1720 |
var assert = this; |
| 1721 |
var currentTest = assert instanceof Assert && assert.test || config.current; |
| 1722 |
|
| 1723 |
// Backwards compatibility fix. |
| 1724 |
// Allows the direct use of global exported assertions and QUnit.assert.* |
| 1725 |
// Although, it's use is not recommended as it can leak assertions |
| 1726 |
// to other tests from async tests, because we only get a reference to the current test, |
| 1727 |
// not exactly the test where assertion were intended to be called. |
| 1728 |
if (!currentTest) { |
| 1729 |
throw new Error('assertion outside test context, in ' + sourceFromStacktrace(2)); |
| 1730 |
} |
| 1731 |
if (!(assert instanceof Assert)) { |
| 1732 |
assert = currentTest.assert; |
| 1733 |
} |
| 1734 |
return assert.test.pushResult(resultInfo); |
| 1735 |
} |
| 1736 |
}, { |
| 1737 |
key: "ok", |
| 1738 |
value: function ok(result, message) { |
| 1739 |
if (!message) { |
| 1740 |
message = result ? 'okay' : "failed, expected argument to be truthy, was: ".concat(dump.parse(result)); |
| 1741 |
} |
| 1742 |
this.pushResult({ |
| 1743 |
result: !!result, |
| 1744 |
actual: result, |
| 1745 |
expected: true, |
| 1746 |
message: message |
| 1747 |
}); |
| 1748 |
} |
| 1749 |
}, { |
| 1750 |
key: "notOk", |
| 1751 |
value: function notOk(result, message) { |
| 1752 |
if (!message) { |
| 1753 |
message = !result ? 'okay' : "failed, expected argument to be falsy, was: ".concat(dump.parse(result)); |
| 1754 |
} |
| 1755 |
this.pushResult({ |
| 1756 |
result: !result, |
| 1757 |
actual: result, |
| 1758 |
expected: false, |
| 1759 |
message: message |
| 1760 |
}); |
| 1761 |
} |
| 1762 |
}, { |
| 1763 |
key: "true", |
| 1764 |
value: function _true(result, message) { |
| 1765 |
this.pushResult({ |
| 1766 |
result: result === true, |
| 1767 |
actual: result, |
| 1768 |
expected: true, |
| 1769 |
message: message |
| 1770 |
}); |
| 1771 |
} |
| 1772 |
}, { |
| 1773 |
key: "false", |
| 1774 |
value: function _false(result, message) { |
| 1775 |
this.pushResult({ |
| 1776 |
result: result === false, |
| 1777 |
actual: result, |
| 1778 |
expected: false, |
| 1779 |
message: message |
| 1780 |
}); |
| 1781 |
} |
| 1782 |
}, { |
| 1783 |
key: "equal", |
| 1784 |
value: function equal(actual, expected, message) { |
| 1785 |
this.pushResult({ |
| 1786 |
// eslint-disable-next-line eqeqeq |
| 1787 |
result: expected == actual, |
| 1788 |
actual: actual, |
| 1789 |
expected: expected, |
| 1790 |
message: message |
| 1791 |
}); |
| 1792 |
} |
| 1793 |
}, { |
| 1794 |
key: "notEqual", |
| 1795 |
value: function notEqual(actual, expected, message) { |
| 1796 |
this.pushResult({ |
| 1797 |
// eslint-disable-next-line eqeqeq |
| 1798 |
result: expected != actual, |
| 1799 |
actual: actual, |
| 1800 |
expected: expected, |
| 1801 |
message: message, |
| 1802 |
negative: true |
| 1803 |
}); |
| 1804 |
} |
| 1805 |
}, { |
| 1806 |
key: "propEqual", |
| 1807 |
value: function propEqual(actual, expected, message) { |
| 1808 |
actual = objectValues(actual); |
| 1809 |
expected = objectValues(expected); |
| 1810 |
this.pushResult({ |
| 1811 |
result: equiv(actual, expected), |
| 1812 |
actual: actual, |
| 1813 |
expected: expected, |
| 1814 |
message: message |
| 1815 |
}); |
| 1816 |
} |
| 1817 |
}, { |
| 1818 |
key: "notPropEqual", |
| 1819 |
value: function notPropEqual(actual, expected, message) { |
| 1820 |
actual = objectValues(actual); |
| 1821 |
expected = objectValues(expected); |
| 1822 |
this.pushResult({ |
| 1823 |
result: !equiv(actual, expected), |
| 1824 |
actual: actual, |
| 1825 |
expected: expected, |
| 1826 |
message: message, |
| 1827 |
negative: true |
| 1828 |
}); |
| 1829 |
} |
| 1830 |
}, { |
| 1831 |
key: "propContains", |
| 1832 |
value: function propContains(actual, expected, message) { |
| 1833 |
actual = objectValuesSubset(actual, expected); |
| 1834 |
|
| 1835 |
// The expected parameter is usually a plain object, but clone it for |
| 1836 |
// consistency with propEqual(), and to make it easy to explain that |
| 1837 |
// inheritence is not considered (on either side), and to support |
| 1838 |
// recursively checking subsets of nested objects. |
| 1839 |
expected = objectValues(expected, false); |
| 1840 |
this.pushResult({ |
| 1841 |
result: equiv(actual, expected), |
| 1842 |
actual: actual, |
| 1843 |
expected: expected, |
| 1844 |
message: message |
| 1845 |
}); |
| 1846 |
} |
| 1847 |
}, { |
| 1848 |
key: "notPropContains", |
| 1849 |
value: function notPropContains(actual, expected, message) { |
| 1850 |
actual = objectValuesSubset(actual, expected); |
| 1851 |
expected = objectValues(expected); |
| 1852 |
this.pushResult({ |
| 1853 |
result: !equiv(actual, expected), |
| 1854 |
actual: actual, |
| 1855 |
expected: expected, |
| 1856 |
message: message, |
| 1857 |
negative: true |
| 1858 |
}); |
| 1859 |
} |
| 1860 |
}, { |
| 1861 |
key: "deepEqual", |
| 1862 |
value: function deepEqual(actual, expected, message) { |
| 1863 |
this.pushResult({ |
| 1864 |
result: equiv(actual, expected), |
| 1865 |
actual: actual, |
| 1866 |
expected: expected, |
| 1867 |
message: message |
| 1868 |
}); |
| 1869 |
} |
| 1870 |
}, { |
| 1871 |
key: "notDeepEqual", |
| 1872 |
value: function notDeepEqual(actual, expected, message) { |
| 1873 |
this.pushResult({ |
| 1874 |
result: !equiv(actual, expected), |
| 1875 |
actual: actual, |
| 1876 |
expected: expected, |
| 1877 |
message: message, |
| 1878 |
negative: true |
| 1879 |
}); |
| 1880 |
} |
| 1881 |
}, { |
| 1882 |
key: "strictEqual", |
| 1883 |
value: function strictEqual(actual, expected, message) { |
| 1884 |
this.pushResult({ |
| 1885 |
result: expected === actual, |
| 1886 |
actual: actual, |
| 1887 |
expected: expected, |
| 1888 |
message: message |
| 1889 |
}); |
| 1890 |
} |
| 1891 |
}, { |
| 1892 |
key: "notStrictEqual", |
| 1893 |
value: function notStrictEqual(actual, expected, message) { |
| 1894 |
this.pushResult({ |
| 1895 |
result: expected !== actual, |
| 1896 |
actual: actual, |
| 1897 |
expected: expected, |
| 1898 |
message: message, |
| 1899 |
negative: true |
| 1900 |
}); |
| 1901 |
} |
| 1902 |
}, { |
| 1903 |
key: 'throws', |
| 1904 |
value: function throws(block, expected, message) { |
| 1905 |
var _validateExpectedExce = validateExpectedExceptionArgs(expected, message, 'throws'); |
| 1906 |
var _validateExpectedExce2 = _slicedToArray(_validateExpectedExce, 2); |
| 1907 |
expected = _validateExpectedExce2[0]; |
| 1908 |
message = _validateExpectedExce2[1]; |
| 1909 |
var currentTest = this instanceof Assert && this.test || config.current; |
| 1910 |
if (typeof block !== 'function') { |
| 1911 |
currentTest.assert.pushResult({ |
| 1912 |
result: false, |
| 1913 |
actual: block, |
| 1914 |
message: 'The value provided to `assert.throws` in ' + '"' + currentTest.testName + '" was not a function.' |
| 1915 |
}); |
| 1916 |
return; |
| 1917 |
} |
| 1918 |
var actual; |
| 1919 |
var result = false; |
| 1920 |
currentTest.ignoreGlobalErrors = true; |
| 1921 |
try { |
| 1922 |
block.call(currentTest.testEnvironment); |
| 1923 |
} catch (e) { |
| 1924 |
actual = e; |
| 1925 |
} |
| 1926 |
currentTest.ignoreGlobalErrors = false; |
| 1927 |
if (actual) { |
| 1928 |
var _validateException = validateException(actual, expected, message); |
| 1929 |
var _validateException2 = _slicedToArray(_validateException, 3); |
| 1930 |
result = _validateException2[0]; |
| 1931 |
expected = _validateException2[1]; |
| 1932 |
message = _validateException2[2]; |
| 1933 |
} |
| 1934 |
currentTest.assert.pushResult({ |
| 1935 |
result: result, |
| 1936 |
// undefined if it didn't throw |
| 1937 |
actual: actual && errorString(actual), |
| 1938 |
expected: expected, |
| 1939 |
message: message |
| 1940 |
}); |
| 1941 |
} |
| 1942 |
}, { |
| 1943 |
key: "rejects", |
| 1944 |
value: function rejects(promise, expected, message) { |
| 1945 |
var _validateExpectedExce3 = validateExpectedExceptionArgs(expected, message, 'rejects'); |
| 1946 |
var _validateExpectedExce4 = _slicedToArray(_validateExpectedExce3, 2); |
| 1947 |
expected = _validateExpectedExce4[0]; |
| 1948 |
message = _validateExpectedExce4[1]; |
| 1949 |
var currentTest = this instanceof Assert && this.test || config.current; |
| 1950 |
var then = promise && promise.then; |
| 1951 |
if (typeof then !== 'function') { |
| 1952 |
currentTest.assert.pushResult({ |
| 1953 |
result: false, |
| 1954 |
message: 'The value provided to `assert.rejects` in ' + '"' + currentTest.testName + '" was not a promise.', |
| 1955 |
actual: promise |
| 1956 |
}); |
| 1957 |
return; |
| 1958 |
} |
| 1959 |
var done = this.async(); |
| 1960 |
return then.call(promise, function handleFulfillment() { |
| 1961 |
currentTest.assert.pushResult({ |
| 1962 |
result: false, |
| 1963 |
message: 'The promise returned by the `assert.rejects` callback in ' + '"' + currentTest.testName + '" did not reject.', |
| 1964 |
actual: promise |
| 1965 |
}); |
| 1966 |
done(); |
| 1967 |
}, function handleRejection(actual) { |
| 1968 |
var result; |
| 1969 |
var _validateException3 = validateException(actual, expected, message); |
| 1970 |
var _validateException4 = _slicedToArray(_validateException3, 3); |
| 1971 |
result = _validateException4[0]; |
| 1972 |
expected = _validateException4[1]; |
| 1973 |
message = _validateException4[2]; |
| 1974 |
currentTest.assert.pushResult({ |
| 1975 |
result: result, |
| 1976 |
// leave rejection value of undefined as-is |
| 1977 |
actual: actual && errorString(actual), |
| 1978 |
expected: expected, |
| 1979 |
message: message |
| 1980 |
}); |
| 1981 |
done(); |
| 1982 |
}); |
| 1983 |
} |
| 1984 |
}]); |
| 1985 |
}(); |
| 1986 |
function validateExpectedExceptionArgs(expected, message, assertionMethod) { |
| 1987 |
var expectedType = objectType(expected); |
| 1988 |
|
| 1989 |
// 'expected' is optional unless doing string comparison |
| 1990 |
if (expectedType === 'string') { |
| 1991 |
if (message === undefined) { |
| 1992 |
message = expected; |
| 1993 |
expected = undefined; |
| 1994 |
return [expected, message]; |
| 1995 |
} else { |
| 1996 |
throw new Error('assert.' + assertionMethod + ' does not accept a string value for the expected argument.\n' + 'Use a non-string object value (e.g. RegExp or validator function) ' + 'instead if necessary.'); |
| 1997 |
} |
| 1998 |
} |
| 1999 |
var valid = !expected || |
| 2000 |
// TODO: be more explicit here |
| 2001 |
expectedType === 'regexp' || expectedType === 'function' || expectedType === 'object'; |
| 2002 |
if (!valid) { |
| 2003 |
throw new Error('Invalid expected value type (' + expectedType + ') ' + 'provided to assert.' + assertionMethod + '.'); |
| 2004 |
} |
| 2005 |
return [expected, message]; |
| 2006 |
} |
| 2007 |
function validateException(actual, expected, message) { |
| 2008 |
var result = false; |
| 2009 |
var expectedType = objectType(expected); |
| 2010 |
|
| 2011 |
// These branches should be exhaustive, based on validation done in validateExpectedException |
| 2012 |
|
| 2013 |
// We don't want to validate |
| 2014 |
if (!expected) { |
| 2015 |
result = true; |
| 2016 |
|
| 2017 |
// Expected is a regexp |
| 2018 |
} else if (expectedType === 'regexp') { |
| 2019 |
result = expected.test(errorString(actual)); |
| 2020 |
|
| 2021 |
// Log the string form of the regexp |
| 2022 |
expected = String(expected); |
| 2023 |
|
| 2024 |
// Expected is a constructor, maybe an Error constructor. |
| 2025 |
// Note the extra check on its prototype - this is an implicit |
| 2026 |
// requirement of "instanceof", else it will throw a TypeError. |
| 2027 |
} else if (expectedType === 'function' && expected.prototype !== undefined && actual instanceof expected) { |
| 2028 |
result = true; |
| 2029 |
|
| 2030 |
// Expected is an Error object |
| 2031 |
} else if (expectedType === 'object') { |
| 2032 |
result = actual instanceof expected.constructor && actual.name === expected.name && actual.message === expected.message; |
| 2033 |
|
| 2034 |
// Log the string form of the Error object |
| 2035 |
expected = errorString(expected); |
| 2036 |
|
| 2037 |
// Expected is a validation function which returns true if validation passed |
| 2038 |
} else if (expectedType === 'function') { |
| 2039 |
// protect against accidental semantics which could hard error in the test |
| 2040 |
try { |
| 2041 |
result = expected.call({}, actual) === true; |
| 2042 |
expected = null; |
| 2043 |
} catch (e) { |
| 2044 |
// assign the "expected" to a nice error string to communicate the local failure to the user |
| 2045 |
expected = errorString(e); |
| 2046 |
} |
| 2047 |
} |
| 2048 |
return [result, expected, message]; |
| 2049 |
} |
| 2050 |
|
| 2051 |
// Provide an alternative to assert.throws(), for environments that consider throws a reserved word |
| 2052 |
// Known to us are: Closure Compiler, Narwhal |
| 2053 |
// eslint-disable-next-line dot-notation |
| 2054 |
Assert.prototype.raises = Assert.prototype['throws']; |
| 2055 |
|
| 2056 |
var SUPPORTED_EVENTS = ['error', 'runStart', 'suiteStart', 'testStart', 'assertion', 'testEnd', 'suiteEnd', 'runEnd']; |
| 2057 |
var MEMORY_EVENTS = ['error', 'runEnd']; |
| 2058 |
|
| 2059 |
/** |
| 2060 |
* Emits an event with the specified data to all currently registered listeners. |
| 2061 |
* Callbacks will fire in the order in which they are registered (FIFO). This |
| 2062 |
* function is not exposed publicly; it is used by QUnit internals to emit |
| 2063 |
* logging events. |
| 2064 |
* |
| 2065 |
* @private |
| 2066 |
* @method emit |
| 2067 |
* @param {string} eventName |
| 2068 |
* @param {Object} data |
| 2069 |
* @return {void} |
| 2070 |
*/ |
| 2071 |
function emit(eventName, data) { |
| 2072 |
if (typeof eventName !== 'string') { |
| 2073 |
throw new TypeError('eventName must be a string when emitting an event'); |
| 2074 |
} |
| 2075 |
|
| 2076 |
// Clone the callbacks in case one of them registers a new callback |
| 2077 |
var originalCallbacks = config._event_listeners[eventName]; |
| 2078 |
var callbacks = originalCallbacks ? _toConsumableArray(originalCallbacks) : []; |
| 2079 |
for (var i = 0; i < callbacks.length; i++) { |
| 2080 |
callbacks[i](data); |
| 2081 |
} |
| 2082 |
if (inArray(eventName, MEMORY_EVENTS)) { |
| 2083 |
config._event_memory[eventName] = data; |
| 2084 |
} |
| 2085 |
} |
| 2086 |
|
| 2087 |
/** |
| 2088 |
* Registers a callback as a listener to the specified event. |
| 2089 |
* |
| 2090 |
* @public |
| 2091 |
* @method on |
| 2092 |
* @param {string} eventName |
| 2093 |
* @param {Function} callback |
| 2094 |
* @return {void} |
| 2095 |
*/ |
| 2096 |
function on(eventName, callback) { |
| 2097 |
if (typeof eventName !== 'string') { |
| 2098 |
throw new TypeError('eventName must be a string when registering a listener'); |
| 2099 |
} else if (!inArray(eventName, SUPPORTED_EVENTS)) { |
| 2100 |
var events = SUPPORTED_EVENTS.join(', '); |
| 2101 |
throw new Error("\"".concat(eventName, "\" is not a valid event; must be one of: ").concat(events, ".")); |
| 2102 |
} else if (typeof callback !== 'function') { |
| 2103 |
throw new TypeError('callback must be a function when registering a listener'); |
| 2104 |
} |
| 2105 |
var listeners = config._event_listeners[eventName] || (config._event_listeners[eventName] = []); |
| 2106 |
|
| 2107 |
// Don't register the same callback more than once |
| 2108 |
if (!inArray(callback, listeners)) { |
| 2109 |
listeners.push(callback); |
| 2110 |
if (config._event_memory[eventName] !== undefined) { |
| 2111 |
callback(config._event_memory[eventName]); |
| 2112 |
} |
| 2113 |
} |
| 2114 |
} |
| 2115 |
|
| 2116 |
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; |
| 2117 |
|
| 2118 |
function commonjsRequire (path) { |
| 2119 |
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.'); |
| 2120 |
} |
| 2121 |
|
| 2122 |
var promisePolyfill = {exports: {}}; |
| 2123 |
|
| 2124 |
(function () { |
| 2125 |
|
| 2126 |
/** @suppress {undefinedVars} */ |
| 2127 |
var globalNS = function () { |
| 2128 |
// the only reliable means to get the global object is |
| 2129 |
// `Function('return this')()` |
| 2130 |
// However, this causes CSP violations in Chrome apps. |
| 2131 |
if (typeof globalThis !== 'undefined') { |
| 2132 |
return globalThis; |
| 2133 |
} |
| 2134 |
if (typeof self !== 'undefined') { |
| 2135 |
return self; |
| 2136 |
} |
| 2137 |
if (typeof window !== 'undefined') { |
| 2138 |
return window; |
| 2139 |
} |
| 2140 |
if (typeof commonjsGlobal !== 'undefined') { |
| 2141 |
return commonjsGlobal; |
| 2142 |
} |
| 2143 |
throw new Error('unable to locate global object'); |
| 2144 |
}(); |
| 2145 |
|
| 2146 |
// Expose the polyfill if Promise is undefined or set to a |
| 2147 |
// non-function value. The latter can be due to a named HTMLElement |
| 2148 |
// being exposed by browsers for legacy reasons. |
| 2149 |
// https://github.com/taylorhakes/promise-polyfill/issues/114 |
| 2150 |
if (typeof globalNS['Promise'] === 'function') { |
| 2151 |
promisePolyfill.exports = globalNS['Promise']; |
| 2152 |
return; |
| 2153 |
} |
| 2154 |
|
| 2155 |
/** |
| 2156 |
* @this {Promise} |
| 2157 |
*/ |
| 2158 |
function finallyConstructor(callback) { |
| 2159 |
var constructor = this.constructor; |
| 2160 |
return this.then(function (value) { |
| 2161 |
// @ts-ignore |
| 2162 |
return constructor.resolve(callback()).then(function () { |
| 2163 |
return value; |
| 2164 |
}); |
| 2165 |
}, function (reason) { |
| 2166 |
// @ts-ignore |
| 2167 |
return constructor.resolve(callback()).then(function () { |
| 2168 |
// @ts-ignore |
| 2169 |
return constructor.reject(reason); |
| 2170 |
}); |
| 2171 |
}); |
| 2172 |
} |
| 2173 |
function allSettled(arr) { |
| 2174 |
var P = this; |
| 2175 |
return new P(function (resolve, reject) { |
| 2176 |
if (!(arr && typeof arr.length !== 'undefined')) { |
| 2177 |
return reject(new TypeError(_typeof(arr) + ' ' + arr + ' is not iterable(cannot read property Symbol(Symbol.iterator))')); |
| 2178 |
} |
| 2179 |
var args = Array.prototype.slice.call(arr); |
| 2180 |
if (args.length === 0) return resolve([]); |
| 2181 |
var remaining = args.length; |
| 2182 |
function res(i, val) { |
| 2183 |
if (val && (_typeof(val) === 'object' || typeof val === 'function')) { |
| 2184 |
var then = val.then; |
| 2185 |
if (typeof then === 'function') { |
| 2186 |
then.call(val, function (val) { |
| 2187 |
res(i, val); |
| 2188 |
}, function (e) { |
| 2189 |
args[i] = { |
| 2190 |
status: 'rejected', |
| 2191 |
reason: e |
| 2192 |
}; |
| 2193 |
if (--remaining === 0) { |
| 2194 |
resolve(args); |
| 2195 |
} |
| 2196 |
}); |
| 2197 |
return; |
| 2198 |
} |
| 2199 |
} |
| 2200 |
args[i] = { |
| 2201 |
status: 'fulfilled', |
| 2202 |
value: val |
| 2203 |
}; |
| 2204 |
if (--remaining === 0) { |
| 2205 |
resolve(args); |
| 2206 |
} |
| 2207 |
} |
| 2208 |
for (var i = 0; i < args.length; i++) { |
| 2209 |
res(i, args[i]); |
| 2210 |
} |
| 2211 |
}); |
| 2212 |
} |
| 2213 |
|
| 2214 |
// Store setTimeout reference so promise-polyfill will be unaffected by |
| 2215 |
// other code modifying setTimeout (like sinon.useFakeTimers()) |
| 2216 |
var setTimeoutFunc = setTimeout; |
| 2217 |
function isArray(x) { |
| 2218 |
return Boolean(x && typeof x.length !== 'undefined'); |
| 2219 |
} |
| 2220 |
function noop() {} |
| 2221 |
|
| 2222 |
// Polyfill for Function.prototype.bind |
| 2223 |
function bind(fn, thisArg) { |
| 2224 |
return function () { |
| 2225 |
fn.apply(thisArg, arguments); |
| 2226 |
}; |
| 2227 |
} |
| 2228 |
|
| 2229 |
/** |
| 2230 |
* @constructor |
| 2231 |
* @param {Function} fn |
| 2232 |
*/ |
| 2233 |
function Promise(fn) { |
| 2234 |
if (!(this instanceof Promise)) throw new TypeError('Promises must be constructed via new'); |
| 2235 |
if (typeof fn !== 'function') throw new TypeError('not a function'); |
| 2236 |
/** @type {!number} */ |
| 2237 |
this._state = 0; |
| 2238 |
/** @type {!boolean} */ |
| 2239 |
this._handled = false; |
| 2240 |
/** @type {Promise|undefined} */ |
| 2241 |
this._value = undefined; |
| 2242 |
/** @type {!Array<!Function>} */ |
| 2243 |
this._deferreds = []; |
| 2244 |
doResolve(fn, this); |
| 2245 |
} |
| 2246 |
function handle(self, deferred) { |
| 2247 |
while (self._state === 3) { |
| 2248 |
self = self._value; |
| 2249 |
} |
| 2250 |
if (self._state === 0) { |
| 2251 |
self._deferreds.push(deferred); |
| 2252 |
return; |
| 2253 |
} |
| 2254 |
self._handled = true; |
| 2255 |
Promise._immediateFn(function () { |
| 2256 |
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected; |
| 2257 |
if (cb === null) { |
| 2258 |
(self._state === 1 ? resolve : reject)(deferred.promise, self._value); |
| 2259 |
return; |
| 2260 |
} |
| 2261 |
var ret; |
| 2262 |
try { |
| 2263 |
ret = cb(self._value); |
| 2264 |
} catch (e) { |
| 2265 |
reject(deferred.promise, e); |
| 2266 |
return; |
| 2267 |
} |
| 2268 |
resolve(deferred.promise, ret); |
| 2269 |
}); |
| 2270 |
} |
| 2271 |
function resolve(self, newValue) { |
| 2272 |
try { |
| 2273 |
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure |
| 2274 |
if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.'); |
| 2275 |
if (newValue && (_typeof(newValue) === 'object' || typeof newValue === 'function')) { |
| 2276 |
var then = newValue.then; |
| 2277 |
if (newValue instanceof Promise) { |
| 2278 |
self._state = 3; |
| 2279 |
self._value = newValue; |
| 2280 |
finale(self); |
| 2281 |
return; |
| 2282 |
} else if (typeof then === 'function') { |
| 2283 |
doResolve(bind(then, newValue), self); |
| 2284 |
return; |
| 2285 |
} |
| 2286 |
} |
| 2287 |
self._state = 1; |
| 2288 |
self._value = newValue; |
| 2289 |
finale(self); |
| 2290 |
} catch (e) { |
| 2291 |
reject(self, e); |
| 2292 |
} |
| 2293 |
} |
| 2294 |
function reject(self, newValue) { |
| 2295 |
self._state = 2; |
| 2296 |
self._value = newValue; |
| 2297 |
finale(self); |
| 2298 |
} |
| 2299 |
function finale(self) { |
| 2300 |
if (self._state === 2 && self._deferreds.length === 0) { |
| 2301 |
Promise._immediateFn(function () { |
| 2302 |
if (!self._handled) { |
| 2303 |
Promise._unhandledRejectionFn(self._value); |
| 2304 |
} |
| 2305 |
}); |
| 2306 |
} |
| 2307 |
for (var i = 0, len = self._deferreds.length; i < len; i++) { |
| 2308 |
handle(self, self._deferreds[i]); |
| 2309 |
} |
| 2310 |
self._deferreds = null; |
| 2311 |
} |
| 2312 |
|
| 2313 |
/** |
| 2314 |
* @constructor |
| 2315 |
*/ |
| 2316 |
function Handler(onFulfilled, onRejected, promise) { |
| 2317 |
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null; |
| 2318 |
this.onRejected = typeof onRejected === 'function' ? onRejected : null; |
| 2319 |
this.promise = promise; |
| 2320 |
} |
| 2321 |
|
| 2322 |
/** |
| 2323 |
* Take a potentially misbehaving resolver function and make sure |
| 2324 |
* onFulfilled and onRejected are only called once. |
| 2325 |
* |
| 2326 |
* Makes no guarantees about asynchrony. |
| 2327 |
*/ |
| 2328 |
function doResolve(fn, self) { |
| 2329 |
var done = false; |
| 2330 |
try { |
| 2331 |
fn(function (value) { |
| 2332 |
if (done) return; |
| 2333 |
done = true; |
| 2334 |
resolve(self, value); |
| 2335 |
}, function (reason) { |
| 2336 |
if (done) return; |
| 2337 |
done = true; |
| 2338 |
reject(self, reason); |
| 2339 |
}); |
| 2340 |
} catch (ex) { |
| 2341 |
if (done) return; |
| 2342 |
done = true; |
| 2343 |
reject(self, ex); |
| 2344 |
} |
| 2345 |
} |
| 2346 |
Promise.prototype['catch'] = function (onRejected) { |
| 2347 |
return this.then(null, onRejected); |
| 2348 |
}; |
| 2349 |
Promise.prototype.then = function (onFulfilled, onRejected) { |
| 2350 |
// @ts-ignore |
| 2351 |
var prom = new this.constructor(noop); |
| 2352 |
handle(this, new Handler(onFulfilled, onRejected, prom)); |
| 2353 |
return prom; |
| 2354 |
}; |
| 2355 |
Promise.prototype['finally'] = finallyConstructor; |
| 2356 |
Promise.all = function (arr) { |
| 2357 |
return new Promise(function (resolve, reject) { |
| 2358 |
if (!isArray(arr)) { |
| 2359 |
return reject(new TypeError('Promise.all accepts an array')); |
| 2360 |
} |
| 2361 |
var args = Array.prototype.slice.call(arr); |
| 2362 |
if (args.length === 0) return resolve([]); |
| 2363 |
var remaining = args.length; |
| 2364 |
function res(i, val) { |
| 2365 |
try { |
| 2366 |
if (val && (_typeof(val) === 'object' || typeof val === 'function')) { |
| 2367 |
var then = val.then; |
| 2368 |
if (typeof then === 'function') { |
| 2369 |
then.call(val, function (val) { |
| 2370 |
res(i, val); |
| 2371 |
}, reject); |
| 2372 |
return; |
| 2373 |
} |
| 2374 |
} |
| 2375 |
args[i] = val; |
| 2376 |
if (--remaining === 0) { |
| 2377 |
resolve(args); |
| 2378 |
} |
| 2379 |
} catch (ex) { |
| 2380 |
reject(ex); |
| 2381 |
} |
| 2382 |
} |
| 2383 |
for (var i = 0; i < args.length; i++) { |
| 2384 |
res(i, args[i]); |
| 2385 |
} |
| 2386 |
}); |
| 2387 |
}; |
| 2388 |
Promise.allSettled = allSettled; |
| 2389 |
Promise.resolve = function (value) { |
| 2390 |
if (value && _typeof(value) === 'object' && value.constructor === Promise) { |
| 2391 |
return value; |
| 2392 |
} |
| 2393 |
return new Promise(function (resolve) { |
| 2394 |
resolve(value); |
| 2395 |
}); |
| 2396 |
}; |
| 2397 |
Promise.reject = function (value) { |
| 2398 |
return new Promise(function (resolve, reject) { |
| 2399 |
reject(value); |
| 2400 |
}); |
| 2401 |
}; |
| 2402 |
Promise.race = function (arr) { |
| 2403 |
return new Promise(function (resolve, reject) { |
| 2404 |
if (!isArray(arr)) { |
| 2405 |
return reject(new TypeError('Promise.race accepts an array')); |
| 2406 |
} |
| 2407 |
for (var i = 0, len = arr.length; i < len; i++) { |
| 2408 |
Promise.resolve(arr[i]).then(resolve, reject); |
| 2409 |
} |
| 2410 |
}); |
| 2411 |
}; |
| 2412 |
|
| 2413 |
// Use polyfill for setImmediate for performance gains |
| 2414 |
// @ts-ignore |
| 2415 |
if (typeof setImmediate === 'function') { |
| 2416 |
// @ts-ignore |
| 2417 |
var setImmediateFunc = setImmediate; |
| 2418 |
Promise._immediateFn = function (fn) { |
| 2419 |
setImmediateFunc(fn); |
| 2420 |
}; |
| 2421 |
} else { |
| 2422 |
Promise._immediateFn = function (fn) { |
| 2423 |
setTimeoutFunc(fn, 0); |
| 2424 |
}; |
| 2425 |
} |
| 2426 |
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) { |
| 2427 |
if (typeof console !== 'undefined' && console) { |
| 2428 |
console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console |
| 2429 |
} |
| 2430 |
}; |
| 2431 |
promisePolyfill.exports = Promise; |
| 2432 |
})(); |
| 2433 |
var _Promise = promisePolyfill.exports; |
| 2434 |
|
| 2435 |
// Register logging callbacks |
| 2436 |
function registerLoggingCallbacks(obj) { |
| 2437 |
var callbackNames = ['begin', 'done', 'log', 'testStart', 'testDone', 'moduleStart', 'moduleDone']; |
| 2438 |
function registerLoggingCallback(key) { |
| 2439 |
return function loggingCallback(callback) { |
| 2440 |
if (typeof callback !== 'function') { |
| 2441 |
throw new Error('Callback parameter must be a function'); |
| 2442 |
} |
| 2443 |
config.callbacks[key].push(callback); |
| 2444 |
}; |
| 2445 |
} |
| 2446 |
for (var i = 0; i < callbackNames.length; i++) { |
| 2447 |
var key = callbackNames[i]; |
| 2448 |
|
| 2449 |
// Initialize key collection of logging callback |
| 2450 |
if (typeof config.callbacks[key] === 'undefined') { |
| 2451 |
config.callbacks[key] = []; |
| 2452 |
} |
| 2453 |
obj[key] = registerLoggingCallback(key); |
| 2454 |
} |
| 2455 |
} |
| 2456 |
function runLoggingCallbacks(key, args) { |
| 2457 |
var callbacks = config.callbacks[key]; |
| 2458 |
|
| 2459 |
// Handling 'log' callbacks separately. Unlike the other callbacks, |
| 2460 |
// the log callback is not controlled by the processing queue, |
| 2461 |
// but rather used by asserts. Hence to promisfy the 'log' callback |
| 2462 |
// would mean promisfying each step of a test |
| 2463 |
if (key === 'log') { |
| 2464 |
callbacks.map(function (callback) { |
| 2465 |
return callback(args); |
| 2466 |
}); |
| 2467 |
return; |
| 2468 |
} |
| 2469 |
|
| 2470 |
// ensure that each callback is executed serially |
| 2471 |
var promiseChain = _Promise.resolve(); |
| 2472 |
callbacks.forEach(function (callback) { |
| 2473 |
promiseChain = promiseChain.then(function () { |
| 2474 |
return _Promise.resolve(callback(args)); |
| 2475 |
}); |
| 2476 |
}); |
| 2477 |
return promiseChain; |
| 2478 |
} |
| 2479 |
|
| 2480 |
var TestReport = /*#__PURE__*/function () { |
| 2481 |
function TestReport(name, suite, options) { |
| 2482 |
_classCallCheck(this, TestReport); |
| 2483 |
this.name = name; |
| 2484 |
this.suiteName = suite.name; |
| 2485 |
this.fullName = suite.fullName.concat(name); |
| 2486 |
this.runtime = 0; |
| 2487 |
this.assertions = []; |
| 2488 |
this.skipped = !!options.skip; |
| 2489 |
this.todo = !!options.todo; |
| 2490 |
this.valid = options.valid; |
| 2491 |
this._startTime = 0; |
| 2492 |
this._endTime = 0; |
| 2493 |
suite.pushTest(this); |
| 2494 |
} |
| 2495 |
return _createClass(TestReport, [{ |
| 2496 |
key: "start", |
| 2497 |
value: function start(recordTime) { |
| 2498 |
if (recordTime) { |
| 2499 |
this._startTime = performance.now(); |
| 2500 |
} |
| 2501 |
return { |
| 2502 |
name: this.name, |
| 2503 |
suiteName: this.suiteName, |
| 2504 |
fullName: this.fullName.slice() |
| 2505 |
}; |
| 2506 |
} |
| 2507 |
}, { |
| 2508 |
key: "end", |
| 2509 |
value: function end(recordTime) { |
| 2510 |
if (recordTime) { |
| 2511 |
this._endTime = performance.now(); |
| 2512 |
} |
| 2513 |
return extend(this.start(), { |
| 2514 |
runtime: this.getRuntime(), |
| 2515 |
status: this.getStatus(), |
| 2516 |
errors: this.getFailedAssertions(), |
| 2517 |
assertions: this.getAssertions() |
| 2518 |
}); |
| 2519 |
} |
| 2520 |
}, { |
| 2521 |
key: "pushAssertion", |
| 2522 |
value: function pushAssertion(assertion) { |
| 2523 |
this.assertions.push(assertion); |
| 2524 |
} |
| 2525 |
}, { |
| 2526 |
key: "getRuntime", |
| 2527 |
value: function getRuntime() { |
| 2528 |
return Math.round(this._endTime - this._startTime); |
| 2529 |
} |
| 2530 |
}, { |
| 2531 |
key: "getStatus", |
| 2532 |
value: function getStatus() { |
| 2533 |
if (this.skipped) { |
| 2534 |
return 'skipped'; |
| 2535 |
} |
| 2536 |
var testPassed = this.getFailedAssertions().length > 0 ? this.todo : !this.todo; |
| 2537 |
if (!testPassed) { |
| 2538 |
return 'failed'; |
| 2539 |
} else if (this.todo) { |
| 2540 |
return 'todo'; |
| 2541 |
} else { |
| 2542 |
return 'passed'; |
| 2543 |
} |
| 2544 |
} |
| 2545 |
}, { |
| 2546 |
key: "getFailedAssertions", |
| 2547 |
value: function getFailedAssertions() { |
| 2548 |
return this.assertions.filter(function (assertion) { |
| 2549 |
return !assertion.passed; |
| 2550 |
}); |
| 2551 |
} |
| 2552 |
}, { |
| 2553 |
key: "getAssertions", |
| 2554 |
value: function getAssertions() { |
| 2555 |
return this.assertions.slice(); |
| 2556 |
} |
| 2557 |
|
| 2558 |
// Remove actual and expected values from assertions. This is to prevent |
| 2559 |
// leaking memory throughout a test suite. |
| 2560 |
}, { |
| 2561 |
key: "slimAssertions", |
| 2562 |
value: function slimAssertions() { |
| 2563 |
this.assertions = this.assertions.map(function (assertion) { |
| 2564 |
delete assertion.actual; |
| 2565 |
delete assertion.expected; |
| 2566 |
return assertion; |
| 2567 |
}); |
| 2568 |
} |
| 2569 |
}]); |
| 2570 |
}(); |
| 2571 |
|
| 2572 |
function Test(settings) { |
| 2573 |
this.expected = null; |
| 2574 |
this.assertions = []; |
| 2575 |
this.module = config.currentModule; |
| 2576 |
this.steps = []; |
| 2577 |
// This powers the QUnit.config.countStepsAsOne feature. |
| 2578 |
// https://github.com/qunitjs/qunit/pull/1775 |
| 2579 |
this.stepsCount = 0; |
| 2580 |
this.timeout = undefined; |
| 2581 |
this.data = undefined; |
| 2582 |
this.withData = false; |
| 2583 |
this.pauses = new StringMap(); |
| 2584 |
this.nextPauseId = 1; |
| 2585 |
|
| 2586 |
// For the most common case, we have: |
| 2587 |
// - 0: new Test |
| 2588 |
// - 1: addTest |
| 2589 |
// - 2: QUnit.test |
| 2590 |
// - 3: user file |
| 2591 |
// |
| 2592 |
// This needs is customised by test.each() |
| 2593 |
this.stackOffset = 3; |
| 2594 |
extend(this, settings); |
| 2595 |
|
| 2596 |
// If a module is skipped, all its tests and the tests of the child suites |
| 2597 |
// should be treated as skipped even if they are defined as `only` or `todo`. |
| 2598 |
// As for `todo` module, all its tests will be treated as `todo` except for |
| 2599 |
// tests defined as `skip` which will be left intact. |
| 2600 |
// |
| 2601 |
// So, if a test is defined as `todo` and is inside a skipped module, we should |
| 2602 |
// then treat that test as if was defined as `skip`. |
| 2603 |
if (this.module.skip) { |
| 2604 |
this.skip = true; |
| 2605 |
this.todo = false; |
| 2606 |
|
| 2607 |
// Skipped tests should be left intact |
| 2608 |
} else if (this.module.todo && !this.skip) { |
| 2609 |
this.todo = true; |
| 2610 |
} |
| 2611 |
|
| 2612 |
// Queuing a late test after the run has ended is not allowed. |
| 2613 |
// This was once supported for internal use by QUnit.onError(). |
| 2614 |
// Ref https://github.com/qunitjs/qunit/issues/1377 |
| 2615 |
if (config.pq.finished) { |
| 2616 |
// Using this for anything other than onError(), such as testing in QUnit.done(), |
| 2617 |
// is unstable and will likely result in the added tests being ignored by CI. |
| 2618 |
// (Meaning the CI passes irregardless of the added tests). |
| 2619 |
// |
| 2620 |
// TODO: Make this an error in QUnit 3.0 |
| 2621 |
// throw new Error( "Unexpected test after runEnd" ); |
| 2622 |
Logger.warn('Unexpected test after runEnd. This is unstable and will fail in QUnit 3.0.'); |
| 2623 |
return; |
| 2624 |
} |
| 2625 |
if (!this.skip && typeof this.callback !== 'function') { |
| 2626 |
var method = this.todo ? 'QUnit.todo' : 'QUnit.test'; |
| 2627 |
throw new TypeError("You must provide a callback to ".concat(method, "(\"").concat(this.testName, "\")")); |
| 2628 |
} |
| 2629 |
|
| 2630 |
// Register unique strings |
| 2631 |
for (var i = 0, l = this.module.tests; i < l.length; i++) { |
| 2632 |
if (this.module.tests[i].name === this.testName) { |
| 2633 |
this.testName += ' '; |
| 2634 |
} |
| 2635 |
} |
| 2636 |
this.testId = generateHash(this.module.name, this.testName); |
| 2637 |
|
| 2638 |
// No validation after this. Beyond this point, failures must be recorded as |
| 2639 |
// a completed test with errors, instead of early bail out. |
| 2640 |
// Otherwise, internals may be left in an inconsistent state. |
| 2641 |
// Ref https://github.com/qunitjs/qunit/issues/1514 |
| 2642 |
|
| 2643 |
++Test.count; |
| 2644 |
this.errorForStack = new Error(); |
| 2645 |
if (this.callback && this.callback.validTest) { |
| 2646 |
// Omit the test-level trace for the internal "No tests" test failure, |
| 2647 |
// There is already an assertion-level trace, and that's noisy enough |
| 2648 |
// as it is. |
| 2649 |
this.errorForStack.stack = undefined; |
| 2650 |
} |
| 2651 |
this.testReport = new TestReport(this.testName, this.module.suiteReport, { |
| 2652 |
todo: this.todo, |
| 2653 |
skip: this.skip, |
| 2654 |
valid: this.valid() |
| 2655 |
}); |
| 2656 |
this.module.tests.push({ |
| 2657 |
name: this.testName, |
| 2658 |
testId: this.testId, |
| 2659 |
skip: !!this.skip |
| 2660 |
}); |
| 2661 |
if (this.skip) { |
| 2662 |
// Skipped tests will fully ignore (and dereference for garbage collect) any sent callback |
| 2663 |
this.callback = function () {}; |
| 2664 |
this.async = false; |
| 2665 |
this.expected = 0; |
| 2666 |
} else { |
| 2667 |
this.assert = new Assert(this); |
| 2668 |
} |
| 2669 |
} |
| 2670 |
Test.count = 0; |
| 2671 |
function getNotStartedModules(startModule) { |
| 2672 |
var module = startModule; |
| 2673 |
var modules = []; |
| 2674 |
while (module && module.testsRun === 0) { |
| 2675 |
modules.push(module); |
| 2676 |
module = module.parentModule; |
| 2677 |
} |
| 2678 |
|
| 2679 |
// The above push modules from the child to the parent |
| 2680 |
// return a reversed order with the top being the top most parent module |
| 2681 |
return modules.reverse(); |
| 2682 |
} |
| 2683 |
Test.prototype = { |
| 2684 |
// Use a getter to avoid computing a stack trace (which can be expensive), |
| 2685 |
// This is displayed by the HTML Reporter, but most other integrations do |
| 2686 |
// not access it. |
| 2687 |
get stack() { |
| 2688 |
return extractStacktrace(this.errorForStack, this.stackOffset); |
| 2689 |
}, |
| 2690 |
before: function before() { |
| 2691 |
var _this = this; |
| 2692 |
var module = this.module; |
| 2693 |
var notStartedModules = getNotStartedModules(module); |
| 2694 |
|
| 2695 |
// ensure the callbacks are executed serially for each module |
| 2696 |
var moduleStartChain = _Promise.resolve(); |
| 2697 |
notStartedModules.forEach(function (startModule) { |
| 2698 |
moduleStartChain = moduleStartChain.then(function () { |
| 2699 |
startModule.stats = { |
| 2700 |
all: 0, |
| 2701 |
bad: 0, |
| 2702 |
started: performance.now() |
| 2703 |
}; |
| 2704 |
emit('suiteStart', startModule.suiteReport.start(true)); |
| 2705 |
return runLoggingCallbacks('moduleStart', { |
| 2706 |
name: startModule.name, |
| 2707 |
tests: startModule.tests |
| 2708 |
}); |
| 2709 |
}); |
| 2710 |
}); |
| 2711 |
return moduleStartChain.then(function () { |
| 2712 |
config.current = _this; |
| 2713 |
_this.testEnvironment = extend({}, module.testEnvironment); |
| 2714 |
_this.started = performance.now(); |
| 2715 |
emit('testStart', _this.testReport.start(true)); |
| 2716 |
return runLoggingCallbacks('testStart', { |
| 2717 |
name: _this.testName, |
| 2718 |
module: module.name, |
| 2719 |
testId: _this.testId, |
| 2720 |
previousFailure: _this.previousFailure |
| 2721 |
}).then(function () { |
| 2722 |
if (!config.pollution) { |
| 2723 |
saveGlobal(); |
| 2724 |
} |
| 2725 |
}); |
| 2726 |
}); |
| 2727 |
}, |
| 2728 |
run: function run() { |
| 2729 |
config.current = this; |
| 2730 |
if (config.notrycatch) { |
| 2731 |
runTest(this); |
| 2732 |
return; |
| 2733 |
} |
| 2734 |
try { |
| 2735 |
runTest(this); |
| 2736 |
} catch (e) { |
| 2737 |
this.pushFailure('Died on test #' + (this.assertions.length + 1) + ': ' + (e.message || e) + '\n' + this.stack, extractStacktrace(e, 0)); |
| 2738 |
|
| 2739 |
// Else next test will carry the responsibility |
| 2740 |
saveGlobal(); |
| 2741 |
|
| 2742 |
// Restart the tests if they're blocking |
| 2743 |
if (config.blocking) { |
| 2744 |
internalRecover(this); |
| 2745 |
} |
| 2746 |
} |
| 2747 |
function runTest(test) { |
| 2748 |
var promise; |
| 2749 |
if (test.withData) { |
| 2750 |
promise = test.callback.call(test.testEnvironment, test.assert, test.data); |
| 2751 |
} else { |
| 2752 |
promise = test.callback.call(test.testEnvironment, test.assert); |
| 2753 |
} |
| 2754 |
test.resolvePromise(promise); |
| 2755 |
|
| 2756 |
// If the test has an async "pause" on it, but the timeout is 0, then we push a |
| 2757 |
// failure as the test should be synchronous. |
| 2758 |
if (test.timeout === 0 && test.pauses.size > 0) { |
| 2759 |
pushFailure('Test did not finish synchronously even though assert.timeout( 0 ) was used.', sourceFromStacktrace(2)); |
| 2760 |
} |
| 2761 |
} |
| 2762 |
}, |
| 2763 |
after: function after() { |
| 2764 |
checkPollution(); |
| 2765 |
}, |
| 2766 |
queueGlobalHook: function queueGlobalHook(hook, hookName) { |
| 2767 |
var _this2 = this; |
| 2768 |
var runHook = function runHook() { |
| 2769 |
config.current = _this2; |
| 2770 |
var promise; |
| 2771 |
if (config.notrycatch) { |
| 2772 |
promise = hook.call(_this2.testEnvironment, _this2.assert); |
| 2773 |
} else { |
| 2774 |
try { |
| 2775 |
promise = hook.call(_this2.testEnvironment, _this2.assert); |
| 2776 |
} catch (error) { |
| 2777 |
_this2.pushFailure('Global ' + hookName + ' failed on ' + _this2.testName + ': ' + errorString(error), extractStacktrace(error, 0)); |
| 2778 |
return; |
| 2779 |
} |
| 2780 |
} |
| 2781 |
_this2.resolvePromise(promise, hookName); |
| 2782 |
}; |
| 2783 |
return runHook; |
| 2784 |
}, |
| 2785 |
queueHook: function queueHook(hook, hookName, hookOwner) { |
| 2786 |
var _this3 = this; |
| 2787 |
var callHook = function callHook() { |
| 2788 |
var promise = hook.call(_this3.testEnvironment, _this3.assert); |
| 2789 |
_this3.resolvePromise(promise, hookName); |
| 2790 |
}; |
| 2791 |
var runHook = function runHook() { |
| 2792 |
if (hookName === 'before') { |
| 2793 |
if (hookOwner.testsRun !== 0) { |
| 2794 |
return; |
| 2795 |
} |
| 2796 |
_this3.preserveEnvironment = true; |
| 2797 |
} |
| 2798 |
|
| 2799 |
// The 'after' hook should only execute when there are not tests left and |
| 2800 |
// when the 'after' and 'finish' tasks are the only tasks left to process |
| 2801 |
if (hookName === 'after' && !lastTestWithinModuleExecuted(hookOwner) && (config.queue.length > 0 || config.pq.taskCount() > 2)) { |
| 2802 |
return; |
| 2803 |
} |
| 2804 |
config.current = _this3; |
| 2805 |
if (config.notrycatch) { |
| 2806 |
callHook(); |
| 2807 |
return; |
| 2808 |
} |
| 2809 |
try { |
| 2810 |
// This try-block includes the indirect call to resolvePromise, which shouldn't |
| 2811 |
// have to be inside try-catch. But, since we support any user-provided thenable |
| 2812 |
// object, the thenable might throw in some unexpected way. |
| 2813 |
// This subtle behaviour is undocumented. To avoid new failures in minor releases |
| 2814 |
// we will not change this until QUnit 3. |
| 2815 |
// TODO: In QUnit 3, reduce this try-block to just hook.call(), matching |
| 2816 |
// the simplicity of queueGlobalHook. |
| 2817 |
callHook(); |
| 2818 |
} catch (error) { |
| 2819 |
_this3.pushFailure(hookName + ' failed on ' + _this3.testName + ': ' + (error.message || error), extractStacktrace(error, 0)); |
| 2820 |
} |
| 2821 |
}; |
| 2822 |
return runHook; |
| 2823 |
}, |
| 2824 |
// Currently only used for module level hooks, can be used to add global level ones |
| 2825 |
hooks: function hooks(handler) { |
| 2826 |
var hooks = []; |
| 2827 |
function processGlobalhooks(test) { |
| 2828 |
if ((handler === 'beforeEach' || handler === 'afterEach') && config.globalHooks[handler]) { |
| 2829 |
for (var i = 0; i < config.globalHooks[handler].length; i++) { |
| 2830 |
hooks.push(test.queueGlobalHook(config.globalHooks[handler][i], handler)); |
| 2831 |
} |
| 2832 |
} |
| 2833 |
} |
| 2834 |
function processHooks(test, module) { |
| 2835 |
if (module.parentModule) { |
| 2836 |
processHooks(test, module.parentModule); |
| 2837 |
} |
| 2838 |
if (module.hooks[handler].length) { |
| 2839 |
for (var i = 0; i < module.hooks[handler].length; i++) { |
| 2840 |
hooks.push(test.queueHook(module.hooks[handler][i], handler, module)); |
| 2841 |
} |
| 2842 |
} |
| 2843 |
} |
| 2844 |
|
| 2845 |
// Hooks are ignored on skipped tests |
| 2846 |
if (!this.skip) { |
| 2847 |
processGlobalhooks(this); |
| 2848 |
processHooks(this, this.module); |
| 2849 |
} |
| 2850 |
return hooks; |
| 2851 |
}, |
| 2852 |
finish: function finish() { |
| 2853 |
config.current = this; |
| 2854 |
|
| 2855 |
// Release the timeout and timeout callback references to be garbage collected. |
| 2856 |
// https://github.com/qunitjs/qunit/pull/1708 |
| 2857 |
if (setTimeout$1) { |
| 2858 |
clearTimeout(this.timeout); |
| 2859 |
config.timeoutHandler = null; |
| 2860 |
} |
| 2861 |
|
| 2862 |
// Release the test callback to ensure that anything referenced has been |
| 2863 |
// released to be garbage collected. |
| 2864 |
this.callback = undefined; |
| 2865 |
if (this.steps.length) { |
| 2866 |
var stepsList = this.steps.join(', '); |
| 2867 |
this.pushFailure('Expected assert.verifySteps() to be called before end of test ' + "after using assert.step(). Unverified steps: ".concat(stepsList), this.stack); |
| 2868 |
} |
| 2869 |
if (!config._deprecated_countEachStep_shown && !config.countStepsAsOne && this.expected !== null && this.stepsCount) { |
| 2870 |
config._deprecated_countEachStep_shown = true; |
| 2871 |
if (config.requireExpects) { |
| 2872 |
Logger.warn('Counting each assert.step() for assert.expect() is changing in QUnit 3.0. You can enable QUnit.config.countStepsAsOne to prepare for the upgrade. https://qunitjs.com/api/assert/expect/'); |
| 2873 |
} else { |
| 2874 |
Logger.warn('Counting each assert.step() for assert.expect() is changing in QUnit 3.0. Omit assert.expect() from tests that use assert.step(), or enable QUnit.config.countStepsAsOne to prepare for the upgrade. https://qunitjs.com/api/assert/expect/'); |
| 2875 |
} |
| 2876 |
} |
| 2877 |
var actualCountForExpect = config.countStepsAsOne ? this.assertions.length - this.stepsCount : this.assertions.length; |
| 2878 |
if (config.requireExpects && this.expected === null) { |
| 2879 |
this.pushFailure('Expected number of assertions to be defined, but expect() was ' + 'not called.', this.stack); |
| 2880 |
} else if (this.expected !== null && this.expected !== actualCountForExpect && this.stepsCount && this.expected === this.assertions.length - this.stepsCount && !config.countStepsAsOne) { |
| 2881 |
this.pushFailure('Expected ' + this.expected + ' assertions, but ' + actualCountForExpect + ' were run\nIt looks like you might prefer to enable QUnit.config.countStepsAsOne, which will become the default in QUnit 3.0. https://qunitjs.com/api/assert/expect/', this.stack); |
| 2882 |
} else if (this.expected !== null && this.expected !== actualCountForExpect && this.stepsCount && this.expected === this.assertions.length && config.countStepsAsOne) { |
| 2883 |
this.pushFailure('Expected ' + this.expected + ' assertions, but ' + actualCountForExpect + ' were run\nRemember that with QUnit.config.countStepsAsOne and in QUnit 3.0, steps no longer count as separate assertions. https://qunitjs.com/api/assert/expect/', this.stack); |
| 2884 |
} else if (this.expected !== null && this.expected !== actualCountForExpect) { |
| 2885 |
this.pushFailure('Expected ' + this.expected + ' assertions, but ' + actualCountForExpect + ' were run', this.stack); |
| 2886 |
} else if (this.expected === null && !actualCountForExpect) { |
| 2887 |
this.pushFailure('Expected at least one assertion, but none were run - call ' + 'expect(0) to accept zero assertions.', this.stack); |
| 2888 |
} |
| 2889 |
var module = this.module; |
| 2890 |
var moduleName = module.name; |
| 2891 |
var testName = this.testName; |
| 2892 |
var skipped = !!this.skip; |
| 2893 |
var todo = !!this.todo; |
| 2894 |
var bad = 0; |
| 2895 |
var storage = config.storage; |
| 2896 |
this.runtime = Math.round(performance.now() - this.started); |
| 2897 |
config.stats.all += this.assertions.length; |
| 2898 |
config.stats.testCount += 1; |
| 2899 |
module.stats.all += this.assertions.length; |
| 2900 |
for (var i = 0; i < this.assertions.length; i++) { |
| 2901 |
// A failing assertion will counts toward the HTML Reporter's |
| 2902 |
// "X assertions, Y failed" line even if it was inside a todo. |
| 2903 |
// Inverting this would be similarly confusing since all but the last |
| 2904 |
// passing assertion inside a todo test should be considered as good. |
| 2905 |
// These stats don't decide the outcome of anything, so counting them |
| 2906 |
// as failing seems the most intuitive. |
| 2907 |
if (!this.assertions[i].result) { |
| 2908 |
bad++; |
| 2909 |
config.stats.bad++; |
| 2910 |
module.stats.bad++; |
| 2911 |
} |
| 2912 |
} |
| 2913 |
if (skipped) { |
| 2914 |
incrementTestsIgnored(module); |
| 2915 |
} else { |
| 2916 |
incrementTestsRun(module); |
| 2917 |
} |
| 2918 |
|
| 2919 |
// Store result when possible. |
| 2920 |
// Note that this also marks todo tests as bad, thus they get hoisted, |
| 2921 |
// and always run first on refresh. |
| 2922 |
if (storage) { |
| 2923 |
if (bad) { |
| 2924 |
storage.setItem('qunit-test-' + moduleName + '-' + testName, bad); |
| 2925 |
} else { |
| 2926 |
storage.removeItem('qunit-test-' + moduleName + '-' + testName); |
| 2927 |
} |
| 2928 |
} |
| 2929 |
|
| 2930 |
// After emitting the js-reporters event we cleanup the assertion data to |
| 2931 |
// avoid leaking it. It is not used by the legacy testDone callbacks. |
| 2932 |
emit('testEnd', this.testReport.end(true)); |
| 2933 |
this.testReport.slimAssertions(); |
| 2934 |
var test = this; |
| 2935 |
return runLoggingCallbacks('testDone', { |
| 2936 |
name: testName, |
| 2937 |
module: moduleName, |
| 2938 |
skipped: skipped, |
| 2939 |
todo: todo, |
| 2940 |
failed: bad, |
| 2941 |
passed: this.assertions.length - bad, |
| 2942 |
total: this.assertions.length, |
| 2943 |
runtime: skipped ? 0 : this.runtime, |
| 2944 |
// HTML Reporter use |
| 2945 |
assertions: this.assertions, |
| 2946 |
testId: this.testId, |
| 2947 |
// Source of Test |
| 2948 |
// generating stack trace is expensive, so using a getter will help defer this until we need it |
| 2949 |
get source() { |
| 2950 |
return test.stack; |
| 2951 |
} |
| 2952 |
}).then(function () { |
| 2953 |
if (allTestsExecuted(module)) { |
| 2954 |
var completedModules = [module]; |
| 2955 |
|
| 2956 |
// Check if the parent modules, iteratively, are done. If that the case, |
| 2957 |
// we emit the `suiteEnd` event and trigger `moduleDone` callback. |
| 2958 |
var parent = module.parentModule; |
| 2959 |
while (parent && allTestsExecuted(parent)) { |
| 2960 |
completedModules.push(parent); |
| 2961 |
parent = parent.parentModule; |
| 2962 |
} |
| 2963 |
var moduleDoneChain = _Promise.resolve(); |
| 2964 |
completedModules.forEach(function (completedModule) { |
| 2965 |
moduleDoneChain = moduleDoneChain.then(function () { |
| 2966 |
return logSuiteEnd(completedModule); |
| 2967 |
}); |
| 2968 |
}); |
| 2969 |
return moduleDoneChain; |
| 2970 |
} |
| 2971 |
}).then(function () { |
| 2972 |
config.current = undefined; |
| 2973 |
}); |
| 2974 |
function logSuiteEnd(module) { |
| 2975 |
// Reset `module.hooks` to ensure that anything referenced in these hooks |
| 2976 |
// has been released to be garbage collected. Descendant modules that were |
| 2977 |
// entirely skipped, e.g. due to filtering, will never have this method |
| 2978 |
// called for them, but might have hooks with references pinning data in |
| 2979 |
// memory (even if the hooks weren't actually executed), so we reset the |
| 2980 |
// hooks on all descendant modules here as well. This is safe because we |
| 2981 |
// will never call this as long as any descendant modules still have tests |
| 2982 |
// to run. This also means that in multi-tiered nesting scenarios we might |
| 2983 |
// reset the hooks multiple times on some modules, but that's harmless. |
| 2984 |
var modules = [module]; |
| 2985 |
while (modules.length) { |
| 2986 |
var nextModule = modules.shift(); |
| 2987 |
nextModule.hooks = {}; |
| 2988 |
modules.push.apply(modules, _toConsumableArray(nextModule.childModules)); |
| 2989 |
} |
| 2990 |
emit('suiteEnd', module.suiteReport.end(true)); |
| 2991 |
return runLoggingCallbacks('moduleDone', { |
| 2992 |
name: module.name, |
| 2993 |
tests: module.tests, |
| 2994 |
failed: module.stats.bad, |
| 2995 |
passed: module.stats.all - module.stats.bad, |
| 2996 |
total: module.stats.all, |
| 2997 |
runtime: Math.round(performance.now() - module.stats.started) |
| 2998 |
}); |
| 2999 |
} |
| 3000 |
}, |
| 3001 |
preserveTestEnvironment: function preserveTestEnvironment() { |
| 3002 |
if (this.preserveEnvironment) { |
| 3003 |
this.module.testEnvironment = this.testEnvironment; |
| 3004 |
this.testEnvironment = extend({}, this.module.testEnvironment); |
| 3005 |
} |
| 3006 |
}, |
| 3007 |
queue: function queue() { |
| 3008 |
var test = this; |
| 3009 |
if (!this.valid()) { |
| 3010 |
incrementTestsIgnored(this.module); |
| 3011 |
return; |
| 3012 |
} |
| 3013 |
function runTest() { |
| 3014 |
return [function () { |
| 3015 |
return test.before(); |
| 3016 |
}].concat(_toConsumableArray(test.hooks('before')), [function () { |
| 3017 |
test.preserveTestEnvironment(); |
| 3018 |
}], _toConsumableArray(test.hooks('beforeEach')), [function () { |
| 3019 |
test.run(); |
| 3020 |
}], _toConsumableArray(test.hooks('afterEach').reverse()), _toConsumableArray(test.hooks('after').reverse()), [function () { |
| 3021 |
test.after(); |
| 3022 |
}, function () { |
| 3023 |
return test.finish(); |
| 3024 |
}]); |
| 3025 |
} |
| 3026 |
var previousFailCount = config.storage && +config.storage.getItem('qunit-test-' + this.module.name + '-' + this.testName); |
| 3027 |
|
| 3028 |
// Prioritize previously failed tests, detected from storage |
| 3029 |
var prioritize = config.reorder && !!previousFailCount; |
| 3030 |
this.previousFailure = !!previousFailCount; |
| 3031 |
config.pq.add(runTest, prioritize); |
| 3032 |
}, |
| 3033 |
pushResult: function pushResult(resultInfo) { |
| 3034 |
if (this !== config.current) { |
| 3035 |
var message = resultInfo && resultInfo.message || ''; |
| 3036 |
var testName = this && this.testName || ''; |
| 3037 |
var error = 'Assertion occurred after test finished.\n' + '> Test: ' + testName + '\n' + '> Message: ' + message + '\n'; |
| 3038 |
throw new Error(error); |
| 3039 |
} |
| 3040 |
|
| 3041 |
// Destructure of resultInfo = { result, actual, expected, message, negative } |
| 3042 |
var details = { |
| 3043 |
module: this.module.name, |
| 3044 |
name: this.testName, |
| 3045 |
result: resultInfo.result, |
| 3046 |
message: resultInfo.message, |
| 3047 |
actual: resultInfo.actual, |
| 3048 |
testId: this.testId, |
| 3049 |
negative: resultInfo.negative || false, |
| 3050 |
runtime: Math.round(performance.now() - this.started), |
| 3051 |
todo: !!this.todo |
| 3052 |
}; |
| 3053 |
if (hasOwn$1.call(resultInfo, 'expected')) { |
| 3054 |
details.expected = resultInfo.expected; |
| 3055 |
} |
| 3056 |
if (!resultInfo.result) { |
| 3057 |
var source = resultInfo.source || sourceFromStacktrace(); |
| 3058 |
if (source) { |
| 3059 |
details.source = source; |
| 3060 |
} |
| 3061 |
} |
| 3062 |
this.logAssertion(details); |
| 3063 |
this.assertions.push({ |
| 3064 |
result: !!resultInfo.result, |
| 3065 |
message: resultInfo.message |
| 3066 |
}); |
| 3067 |
}, |
| 3068 |
pushFailure: function pushFailure(message, source) { |
| 3069 |
if (!(this instanceof Test)) { |
| 3070 |
throw new Error('pushFailure() assertion outside test context, was ' + sourceFromStacktrace(2)); |
| 3071 |
} |
| 3072 |
this.pushResult({ |
| 3073 |
result: false, |
| 3074 |
message: message || 'error', |
| 3075 |
source: source |
| 3076 |
}); |
| 3077 |
}, |
| 3078 |
/** |
| 3079 |
* Log assertion details using both the old QUnit.log interface and |
| 3080 |
* QUnit.on( "assertion" ) interface. |
| 3081 |
* |
| 3082 |
* @private |
| 3083 |
*/ |
| 3084 |
logAssertion: function logAssertion(details) { |
| 3085 |
runLoggingCallbacks('log', details); |
| 3086 |
var assertion = { |
| 3087 |
passed: details.result, |
| 3088 |
actual: details.actual, |
| 3089 |
expected: details.expected, |
| 3090 |
message: details.message, |
| 3091 |
stack: details.source, |
| 3092 |
todo: details.todo |
| 3093 |
}; |
| 3094 |
this.testReport.pushAssertion(assertion); |
| 3095 |
emit('assertion', assertion); |
| 3096 |
}, |
| 3097 |
/** |
| 3098 |
* Reset config.timeout with a new timeout duration. |
| 3099 |
* |
| 3100 |
* @param {number} timeoutDuration |
| 3101 |
*/ |
| 3102 |
internalResetTimeout: function internalResetTimeout(timeoutDuration) { |
| 3103 |
clearTimeout(config.timeout); |
| 3104 |
config.timeout = setTimeout$1(config.timeoutHandler(timeoutDuration), timeoutDuration); |
| 3105 |
}, |
| 3106 |
/** |
| 3107 |
* Create a new async pause and return a new function that can release the pause. |
| 3108 |
* |
| 3109 |
* This mechanism is internally used by: |
| 3110 |
* |
| 3111 |
* - explicit async pauses, created by calling `assert.async()`, |
| 3112 |
* - implicit async pauses, created when `QUnit.test()` or module hook callbacks |
| 3113 |
* use async-await or otherwise return a Promise. |
| 3114 |
* |
| 3115 |
* Happy scenario: |
| 3116 |
* |
| 3117 |
* - Pause is created by calling internalStop(). |
| 3118 |
* |
| 3119 |
* Pause is released normally by invoking release() during the same test. |
| 3120 |
* |
| 3121 |
* The release() callback lets internal processing resume. |
| 3122 |
* |
| 3123 |
* Failure scenarios: |
| 3124 |
* |
| 3125 |
* - The test fails due to an uncaught exception. |
| 3126 |
* |
| 3127 |
* In this case, Test.run() will call internalRecover() which empties the clears all |
| 3128 |
* async pauses and sets the cancelled flag, which means we silently ignore any |
| 3129 |
* late calls to the resume() callback, as we will have moved on to a different |
| 3130 |
* test by then, and we don't want to cause an extra "release during a different test" |
| 3131 |
* errors that the developer isn't really responsible for. This can happen when a test |
| 3132 |
* correctly schedules a call to release(), but also causes an uncaught error. The |
| 3133 |
* uncaught error means we will no longer wait for the release (as it might not arrive). |
| 3134 |
* |
| 3135 |
* - Pause is never released, or called an insufficient number of times. |
| 3136 |
* |
| 3137 |
* Our timeout handler will kill the pause and resume test processing, basically |
| 3138 |
* like internalRecover(), but for one pause instead of any/all. |
| 3139 |
* |
| 3140 |
* Here, too, any late calls to resume() will be silently ignored to avoid |
| 3141 |
* extra errors. We tolerate this since the original test will have already been |
| 3142 |
* marked as failure. |
| 3143 |
* |
| 3144 |
* TODO: QUnit 3 will enable timeouts by default <https://github.com/qunitjs/qunit/issues/1483>, |
| 3145 |
* but right now a test will hang indefinitely if async pauses are not released, |
| 3146 |
* unless QUnit.config.testTimeout or assert.timeout() is used. |
| 3147 |
* |
| 3148 |
* - Pause is spontaneously released during a different test, |
| 3149 |
* or when no test is currently running. |
| 3150 |
* |
| 3151 |
* This is close to impossible because this error only happens if the original test |
| 3152 |
* succesfully finished first (since other failure scenarios kill pauses and ignore |
| 3153 |
* late calls). It can happen if a test ended exactly as expected, but has some |
| 3154 |
* external or shared state continuing to hold a reference to the release callback, |
| 3155 |
* and either the same test scheduled another call to it in the future, or a later test |
| 3156 |
* causes it to be called through some shared state. |
| 3157 |
* |
| 3158 |
* - Pause release() is called too often, during the same test. |
| 3159 |
* |
| 3160 |
* This simply throws an error, after which uncaught error handling picks it up |
| 3161 |
* and processing resumes. |
| 3162 |
* |
| 3163 |
* @param {number} [requiredCalls=1] |
| 3164 |
*/ |
| 3165 |
internalStop: function internalStop() { |
| 3166 |
var requiredCalls = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; |
| 3167 |
config.blocking = true; |
| 3168 |
var test = this; |
| 3169 |
var pauseId = this.nextPauseId++; |
| 3170 |
var pause = { |
| 3171 |
cancelled: false, |
| 3172 |
remaining: requiredCalls |
| 3173 |
}; |
| 3174 |
test.pauses.set(pauseId, pause); |
| 3175 |
function release() { |
| 3176 |
if (pause.cancelled) { |
| 3177 |
return; |
| 3178 |
} |
| 3179 |
if (config.current === undefined) { |
| 3180 |
throw new Error('Unexpected release of async pause after tests finished.\n' + "> Test: ".concat(test.testName, " [async #").concat(pauseId, "]")); |
| 3181 |
} |
| 3182 |
if (config.current !== test) { |
| 3183 |
throw new Error('Unexpected release of async pause during a different test.\n' + "> Test: ".concat(test.testName, " [async #").concat(pauseId, "]")); |
| 3184 |
} |
| 3185 |
if (pause.remaining <= 0) { |
| 3186 |
throw new Error('Tried to release async pause that was already released.\n' + "> Test: ".concat(test.testName, " [async #").concat(pauseId, "]")); |
| 3187 |
} |
| 3188 |
|
| 3189 |
// The `requiredCalls` parameter exists to support `assert.async(count)` |
| 3190 |
pause.remaining--; |
| 3191 |
if (pause.remaining === 0) { |
| 3192 |
test.pauses.delete(pauseId); |
| 3193 |
} |
| 3194 |
internalStart(test); |
| 3195 |
} |
| 3196 |
|
| 3197 |
// Set a recovery timeout, if so configured. |
| 3198 |
if (setTimeout$1) { |
| 3199 |
var timeoutDuration; |
| 3200 |
if (typeof test.timeout === 'number') { |
| 3201 |
timeoutDuration = test.timeout; |
| 3202 |
} else if (typeof config.testTimeout === 'number') { |
| 3203 |
timeoutDuration = config.testTimeout; |
| 3204 |
} |
| 3205 |
if (typeof timeoutDuration === 'number' && timeoutDuration > 0) { |
| 3206 |
config.timeoutHandler = function (timeout) { |
| 3207 |
return function () { |
| 3208 |
config.timeout = null; |
| 3209 |
pause.cancelled = true; |
| 3210 |
test.pauses.delete(pauseId); |
| 3211 |
test.pushFailure("Test took longer than ".concat(timeout, "ms; test timed out."), sourceFromStacktrace(2)); |
| 3212 |
internalRecover(test); |
| 3213 |
}; |
| 3214 |
}; |
| 3215 |
clearTimeout(config.timeout); |
| 3216 |
config.timeout = setTimeout$1(config.timeoutHandler(timeoutDuration), timeoutDuration); |
| 3217 |
} else { |
| 3218 |
clearTimeout(config.timeout); |
| 3219 |
config.timeout = setTimeout$1(function () { |
| 3220 |
config.timeout = null; |
| 3221 |
if (!config._deprecated_timeout_shown) { |
| 3222 |
config._deprecated_timeout_shown = true; |
| 3223 |
Logger.warn("Test \"".concat(test.testName, "\" took longer than 3000ms, but no timeout was set. Set QUnit.config.testTimeout or call assert.timeout() to avoid a timeout in QUnit 3. https://qunitjs.com/api/config/testTimeout/")); |
| 3224 |
} |
| 3225 |
}, 3000); |
| 3226 |
} |
| 3227 |
} |
| 3228 |
return release; |
| 3229 |
}, |
| 3230 |
resolvePromise: function resolvePromise(promise, phase) { |
| 3231 |
if (promise != null) { |
| 3232 |
var _test = this; |
| 3233 |
var then = promise.then; |
| 3234 |
if (typeof then === 'function') { |
| 3235 |
var resume = _test.internalStop(); |
| 3236 |
var resolve = function resolve() { |
| 3237 |
resume(); |
| 3238 |
}; |
| 3239 |
if (config.notrycatch) { |
| 3240 |
then.call(promise, resolve); |
| 3241 |
} else { |
| 3242 |
var reject = function reject(error) { |
| 3243 |
var message = 'Promise rejected ' + (!phase ? 'during' : phase.replace(/Each$/, '')) + ' "' + _test.testName + '": ' + (error && error.message || error); |
| 3244 |
_test.pushFailure(message, extractStacktrace(error, 0)); |
| 3245 |
|
| 3246 |
// Else next test will carry the responsibility |
| 3247 |
saveGlobal(); |
| 3248 |
|
| 3249 |
// Unblock |
| 3250 |
internalRecover(_test); |
| 3251 |
}; |
| 3252 |
then.call(promise, resolve, reject); |
| 3253 |
} |
| 3254 |
} |
| 3255 |
} |
| 3256 |
}, |
| 3257 |
valid: function valid() { |
| 3258 |
// Internally-generated tests are always valid |
| 3259 |
if (this.callback && this.callback.validTest) { |
| 3260 |
return true; |
| 3261 |
} |
| 3262 |
function moduleChainIdMatch(testModule, selectedId) { |
| 3263 |
return ( |
| 3264 |
// undefined or empty array |
| 3265 |
!selectedId || !selectedId.length || inArray(testModule.moduleId, selectedId) || testModule.parentModule && moduleChainIdMatch(testModule.parentModule, selectedId) |
| 3266 |
); |
| 3267 |
} |
| 3268 |
if (!moduleChainIdMatch(this.module, config.moduleId)) { |
| 3269 |
return false; |
| 3270 |
} |
| 3271 |
if (config.testId && config.testId.length && !inArray(this.testId, config.testId)) { |
| 3272 |
return false; |
| 3273 |
} |
| 3274 |
function moduleChainNameMatch(testModule, selectedModule) { |
| 3275 |
if (!selectedModule) { |
| 3276 |
// undefined or empty string |
| 3277 |
return true; |
| 3278 |
} |
| 3279 |
var testModuleName = testModule.name ? testModule.name.toLowerCase() : null; |
| 3280 |
if (testModuleName === selectedModule) { |
| 3281 |
return true; |
| 3282 |
} else if (testModule.parentModule) { |
| 3283 |
return moduleChainNameMatch(testModule.parentModule, selectedModule); |
| 3284 |
} else { |
| 3285 |
return false; |
| 3286 |
} |
| 3287 |
} |
| 3288 |
var selectedModule = config.module && config.module.toLowerCase(); |
| 3289 |
if (!moduleChainNameMatch(this.module, selectedModule)) { |
| 3290 |
return false; |
| 3291 |
} |
| 3292 |
var filter = config.filter; |
| 3293 |
if (!filter) { |
| 3294 |
return true; |
| 3295 |
} |
| 3296 |
var regexFilter = /^(!?)\/([\w\W]*)\/(i?$)/.exec(filter); |
| 3297 |
var fullName = this.module.name + ': ' + this.testName; |
| 3298 |
return regexFilter ? this.regexFilter(!!regexFilter[1], regexFilter[2], regexFilter[3], fullName) : this.stringFilter(filter, fullName); |
| 3299 |
}, |
| 3300 |
regexFilter: function regexFilter(exclude, pattern, flags, fullName) { |
| 3301 |
var regex = new RegExp(pattern, flags); |
| 3302 |
var match = regex.test(fullName); |
| 3303 |
return match !== exclude; |
| 3304 |
}, |
| 3305 |
stringFilter: function stringFilter(filter, fullName) { |
| 3306 |
filter = filter.toLowerCase(); |
| 3307 |
fullName = fullName.toLowerCase(); |
| 3308 |
var include = filter.charAt(0) !== '!'; |
| 3309 |
if (!include) { |
| 3310 |
filter = filter.slice(1); |
| 3311 |
} |
| 3312 |
|
| 3313 |
// If the filter matches, we need to honour include |
| 3314 |
if (fullName.indexOf(filter) !== -1) { |
| 3315 |
return include; |
| 3316 |
} |
| 3317 |
|
| 3318 |
// Otherwise, do the opposite |
| 3319 |
return !include; |
| 3320 |
} |
| 3321 |
}; |
| 3322 |
function pushFailure() { |
| 3323 |
if (!config.current) { |
| 3324 |
throw new Error('pushFailure() assertion outside test context, in ' + sourceFromStacktrace(2)); |
| 3325 |
} |
| 3326 |
|
| 3327 |
// Gets current test obj |
| 3328 |
var currentTest = config.current; |
| 3329 |
return currentTest.pushFailure.apply(currentTest, arguments); |
| 3330 |
} |
| 3331 |
function saveGlobal() { |
| 3332 |
config.pollution = []; |
| 3333 |
if (config.noglobals) { |
| 3334 |
for (var key in g) { |
| 3335 |
if (hasOwn$1.call(g, key)) { |
| 3336 |
// In Opera sometimes DOM element ids show up here, ignore them |
| 3337 |
if (/^qunit-test-output/.test(key)) { |
| 3338 |
continue; |
| 3339 |
} |
| 3340 |
config.pollution.push(key); |
| 3341 |
} |
| 3342 |
} |
| 3343 |
} |
| 3344 |
} |
| 3345 |
function checkPollution() { |
| 3346 |
var old = config.pollution; |
| 3347 |
saveGlobal(); |
| 3348 |
var newGlobals = diff$1(config.pollution, old); |
| 3349 |
if (newGlobals.length > 0) { |
| 3350 |
pushFailure('Introduced global variable(s): ' + newGlobals.join(', ')); |
| 3351 |
} |
| 3352 |
var deletedGlobals = diff$1(old, config.pollution); |
| 3353 |
if (deletedGlobals.length > 0) { |
| 3354 |
pushFailure('Deleted global variable(s): ' + deletedGlobals.join(', ')); |
| 3355 |
} |
| 3356 |
} |
| 3357 |
var focused = false; // indicates that the "only" filter was used |
| 3358 |
|
| 3359 |
function addTest(settings) { |
| 3360 |
if (focused || config.currentModule.ignored) { |
| 3361 |
return; |
| 3362 |
} |
| 3363 |
var newTest = new Test(settings); |
| 3364 |
newTest.queue(); |
| 3365 |
} |
| 3366 |
function addOnlyTest(settings) { |
| 3367 |
if (config.currentModule.ignored) { |
| 3368 |
return; |
| 3369 |
} |
| 3370 |
if (!focused) { |
| 3371 |
config.queue.length = 0; |
| 3372 |
clearSuiteReports(config.currentModule); |
| 3373 |
focused = true; |
| 3374 |
} |
| 3375 |
var newTest = new Test(settings); |
| 3376 |
newTest.queue(); |
| 3377 |
} |
| 3378 |
|
| 3379 |
// Will be exposed as QUnit.test |
| 3380 |
function test(testName, callback) { |
| 3381 |
addTest({ |
| 3382 |
testName: testName, |
| 3383 |
callback: callback |
| 3384 |
}); |
| 3385 |
} |
| 3386 |
function makeEachTestName(testName, argument) { |
| 3387 |
return "".concat(testName, " [").concat(argument, "]"); |
| 3388 |
} |
| 3389 |
|
| 3390 |
// Characters to avoid in test names especially CLI/AP output: |
| 3391 |
// * x00-1F: e.g. NULL, backspace (\b), line breaks (\r\n), ESC. |
| 3392 |
// * x74: DEL. |
| 3393 |
// * xA0: non-breaking space. |
| 3394 |
// |
| 3395 |
// See https://en.wikipedia.org/wiki/ASCII#Character_order |
| 3396 |
// |
| 3397 |
// eslint-disable-next-line no-control-regex |
| 3398 |
var rNonObviousStr = /[\x00-\x1F\x7F\xA0]/; |
| 3399 |
function runEach(data, eachFn) { |
| 3400 |
if (Array.isArray(data)) { |
| 3401 |
for (var i = 0; i < data.length; i++) { |
| 3402 |
var value = data[i]; |
| 3403 |
|
| 3404 |
// Create automatic labels for primitive data in arrays passed to test.each(). |
| 3405 |
// We want to avoid the default "example [0], example [1]" where possible since |
| 3406 |
// these are not self-explanatory in results, and are also tedious to locate |
| 3407 |
// the source of since the numerical key of an array isn't literally in the |
| 3408 |
// code (you have to count). |
| 3409 |
// |
| 3410 |
// Design requirements: |
| 3411 |
// * Unique. Each label must be unique and correspond 1:1 with a data value. |
| 3412 |
// This way each test name will hash to a unique testId with Rerun link, |
| 3413 |
// without having to rely on Test class enforcing uniqueness with invisible |
| 3414 |
// space hack. |
| 3415 |
// * Unambigious. While technical uniqueness is a hard requirement above, |
| 3416 |
// we also want the labels to be obvious and unambiguous to humans. |
| 3417 |
// For example, abbrebating "foobar" and "foobaz" to "f" and "fo" is |
| 3418 |
// technically unique, but ambigious to humans which one is which. |
| 3419 |
// * Short and readable. Where possible we omit the array index numbers |
| 3420 |
// so that in most cases, the value is simply shown as-is. |
| 3421 |
// We prefer "example [foo], example [bar]" |
| 3422 |
// over "example [0: foo], example [2: bar]". |
| 3423 |
// This also has the benefit of being stable and robust against e.g. |
| 3424 |
// re-ordering data or adding new items during development, without |
| 3425 |
// invalidating a previous filter or rerun link immediately. |
| 3426 |
var valueType = _typeof(value); |
| 3427 |
var testKey = i; |
| 3428 |
if (valueType === 'string' && value.length <= 40 && !rNonObviousStr.test(value) && !/\s*\d+: /.test(value)) { |
| 3429 |
testKey = value; |
| 3430 |
} else if (valueType === 'string' || valueType === 'number' || valueType === 'boolean' || valueType === 'undefined' || value === null) { |
| 3431 |
var valueForName = String(value); |
| 3432 |
if (!rNonObviousStr.test(valueForName)) { |
| 3433 |
testKey = i + ': ' + (valueForName.length <= 30 ? valueForName : valueForName.slice(0, 29) + '…'); |
| 3434 |
} |
| 3435 |
} |
| 3436 |
eachFn(value, testKey); |
| 3437 |
} |
| 3438 |
} else if (_typeof(data) === 'object' && data !== null) { |
| 3439 |
for (var key in data) { |
| 3440 |
eachFn(data[key], key); |
| 3441 |
} |
| 3442 |
} else { |
| 3443 |
throw new Error("test.each() expects an array or object as input, but\nfound ".concat(_typeof(data), " instead.")); |
| 3444 |
} |
| 3445 |
} |
| 3446 |
extend(test, { |
| 3447 |
todo: function todo(testName, callback) { |
| 3448 |
addTest({ |
| 3449 |
testName: testName, |
| 3450 |
callback: callback, |
| 3451 |
todo: true |
| 3452 |
}); |
| 3453 |
}, |
| 3454 |
skip: function skip(testName) { |
| 3455 |
addTest({ |
| 3456 |
testName: testName, |
| 3457 |
skip: true |
| 3458 |
}); |
| 3459 |
}, |
| 3460 |
if: function _if(testName, condition, callback) { |
| 3461 |
addTest({ |
| 3462 |
testName: testName, |
| 3463 |
callback: callback, |
| 3464 |
skip: !condition |
| 3465 |
}); |
| 3466 |
}, |
| 3467 |
only: function only(testName, callback) { |
| 3468 |
addOnlyTest({ |
| 3469 |
testName: testName, |
| 3470 |
callback: callback |
| 3471 |
}); |
| 3472 |
}, |
| 3473 |
each: function each(testName, dataset, callback) { |
| 3474 |
runEach(dataset, function (data, testKey) { |
| 3475 |
addTest({ |
| 3476 |
testName: makeEachTestName(testName, testKey), |
| 3477 |
callback: callback, |
| 3478 |
withData: true, |
| 3479 |
stackOffset: 5, |
| 3480 |
data: data |
| 3481 |
}); |
| 3482 |
}); |
| 3483 |
} |
| 3484 |
}); |
| 3485 |
test.todo.each = function (testName, dataset, callback) { |
| 3486 |
runEach(dataset, function (data, testKey) { |
| 3487 |
addTest({ |
| 3488 |
testName: makeEachTestName(testName, testKey), |
| 3489 |
callback: callback, |
| 3490 |
todo: true, |
| 3491 |
withData: true, |
| 3492 |
stackOffset: 5, |
| 3493 |
data: data |
| 3494 |
}); |
| 3495 |
}); |
| 3496 |
}; |
| 3497 |
test.skip.each = function (testName, dataset) { |
| 3498 |
runEach(dataset, function (_, testKey) { |
| 3499 |
addTest({ |
| 3500 |
testName: makeEachTestName(testName, testKey), |
| 3501 |
stackOffset: 5, |
| 3502 |
skip: true |
| 3503 |
}); |
| 3504 |
}); |
| 3505 |
}; |
| 3506 |
test.if.each = function (testName, condition, dataset, callback) { |
| 3507 |
runEach(dataset, function (data, testKey) { |
| 3508 |
addTest({ |
| 3509 |
testName: makeEachTestName(testName, testKey), |
| 3510 |
callback: callback, |
| 3511 |
withData: true, |
| 3512 |
stackOffset: 5, |
| 3513 |
skip: !condition, |
| 3514 |
data: condition ? data : undefined |
| 3515 |
}); |
| 3516 |
}); |
| 3517 |
}; |
| 3518 |
test.only.each = function (testName, dataset, callback) { |
| 3519 |
runEach(dataset, function (data, testKey) { |
| 3520 |
addOnlyTest({ |
| 3521 |
testName: makeEachTestName(testName, testKey), |
| 3522 |
callback: callback, |
| 3523 |
withData: true, |
| 3524 |
stackOffset: 5, |
| 3525 |
data: data |
| 3526 |
}); |
| 3527 |
}); |
| 3528 |
}; |
| 3529 |
|
| 3530 |
// Forcefully release all processing holds. |
| 3531 |
function internalRecover(test) { |
| 3532 |
test.pauses.forEach(function (pause) { |
| 3533 |
pause.cancelled = true; |
| 3534 |
}); |
| 3535 |
test.pauses.clear(); |
| 3536 |
internalStart(test); |
| 3537 |
} |
| 3538 |
|
| 3539 |
// Release a processing hold, scheduling a resumption attempt if no holds remain. |
| 3540 |
function internalStart(test) { |
| 3541 |
// Ignore if other async pauses still exist. |
| 3542 |
if (test.pauses.size > 0) { |
| 3543 |
return; |
| 3544 |
} |
| 3545 |
|
| 3546 |
// Add a slight delay to allow more assertions etc. |
| 3547 |
if (setTimeout$1) { |
| 3548 |
clearTimeout(config.timeout); |
| 3549 |
config.timeout = setTimeout$1(function () { |
| 3550 |
if (test.pauses.size > 0) { |
| 3551 |
return; |
| 3552 |
} |
| 3553 |
clearTimeout(config.timeout); |
| 3554 |
config.timeout = null; |
| 3555 |
config.blocking = false; |
| 3556 |
config.pq.advance(); |
| 3557 |
}); |
| 3558 |
} else { |
| 3559 |
config.blocking = false; |
| 3560 |
config.pq.advance(); |
| 3561 |
} |
| 3562 |
} |
| 3563 |
function collectTests(module) { |
| 3564 |
var tests = [].concat(module.tests); |
| 3565 |
var modules = _toConsumableArray(module.childModules); |
| 3566 |
|
| 3567 |
// Do a breadth-first traversal of the child modules |
| 3568 |
while (modules.length) { |
| 3569 |
var nextModule = modules.shift(); |
| 3570 |
tests.push.apply(tests, nextModule.tests); |
| 3571 |
modules.push.apply(modules, _toConsumableArray(nextModule.childModules)); |
| 3572 |
} |
| 3573 |
return tests; |
| 3574 |
} |
| 3575 |
|
| 3576 |
// This returns true after all executable and skippable tests |
| 3577 |
// in a module have been proccessed, and informs 'suiteEnd' |
| 3578 |
// and moduleDone(). |
| 3579 |
function allTestsExecuted(module) { |
| 3580 |
return module.testsRun + module.testsIgnored === collectTests(module).length; |
| 3581 |
} |
| 3582 |
|
| 3583 |
// This returns true during the last executable non-skipped test |
| 3584 |
// within a module, and informs the running of the 'after' hook |
| 3585 |
// for a given module. This runs only once for a given module, |
| 3586 |
// but must run during the last non-skipped test. When it runs, |
| 3587 |
// there may be non-zero skipped tests left. |
| 3588 |
function lastTestWithinModuleExecuted(module) { |
| 3589 |
return module.testsRun === collectTests(module).filter(function (test) { |
| 3590 |
return !test.skip; |
| 3591 |
}).length - 1; |
| 3592 |
} |
| 3593 |
function incrementTestsRun(module) { |
| 3594 |
module.testsRun++; |
| 3595 |
while (module = module.parentModule) { |
| 3596 |
module.testsRun++; |
| 3597 |
} |
| 3598 |
} |
| 3599 |
function incrementTestsIgnored(module) { |
| 3600 |
module.testsIgnored++; |
| 3601 |
while (module = module.parentModule) { |
| 3602 |
module.testsIgnored++; |
| 3603 |
} |
| 3604 |
} |
| 3605 |
|
| 3606 |
/* global module, exports, define */ |
| 3607 |
function exportQUnit(QUnit) { |
| 3608 |
var exportedModule = false; |
| 3609 |
if (window$1 && document) { |
| 3610 |
// QUnit may be defined when it is preconfigured but then only QUnit and QUnit.config may be defined. |
| 3611 |
if (window$1.QUnit && window$1.QUnit.version) { |
| 3612 |
throw new Error('QUnit has already been defined.'); |
| 3613 |
} |
| 3614 |
window$1.QUnit = QUnit; |
| 3615 |
exportedModule = true; |
| 3616 |
} |
| 3617 |
|
| 3618 |
// For Node.js |
| 3619 |
if (typeof module !== 'undefined' && module && module.exports) { |
| 3620 |
module.exports = QUnit; |
| 3621 |
|
| 3622 |
// For consistency with CommonJS environments' exports |
| 3623 |
module.exports.QUnit = QUnit; |
| 3624 |
exportedModule = true; |
| 3625 |
} |
| 3626 |
|
| 3627 |
// For CommonJS with exports, but without module.exports, like Rhino |
| 3628 |
if (typeof exports !== 'undefined' && exports) { |
| 3629 |
exports.QUnit = QUnit; |
| 3630 |
exportedModule = true; |
| 3631 |
} |
| 3632 |
|
| 3633 |
// For AMD |
| 3634 |
if (typeof define === 'function' && define.amd) { |
| 3635 |
define(function () { |
| 3636 |
return QUnit; |
| 3637 |
}); |
| 3638 |
QUnit.config.autostart = false; |
| 3639 |
exportedModule = true; |
| 3640 |
} |
| 3641 |
|
| 3642 |
// For other environments, including Web Workers (globalThis === self), |
| 3643 |
// SpiderMonkey (mozjs), and other embedded JavaScript engines |
| 3644 |
if (!exportedModule) { |
| 3645 |
g.QUnit = QUnit; |
| 3646 |
} |
| 3647 |
} |
| 3648 |
|
| 3649 |
var ConsoleReporter = /*#__PURE__*/function () { |
| 3650 |
function ConsoleReporter(runner) { |
| 3651 |
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 3652 |
_classCallCheck(this, ConsoleReporter); |
| 3653 |
// Cache references to console methods to ensure we can report failures |
| 3654 |
// from tests tests that mock the console object itself. |
| 3655 |
// https://github.com/qunitjs/qunit/issues/1340 |
| 3656 |
// Support IE 9: Function#bind is supported, but no console.log.bind(). |
| 3657 |
this.log = options.log || Function.prototype.bind.call(console$1.log, console$1); |
| 3658 |
runner.on('error', this.onError.bind(this)); |
| 3659 |
runner.on('runStart', this.onRunStart.bind(this)); |
| 3660 |
runner.on('testStart', this.onTestStart.bind(this)); |
| 3661 |
runner.on('testEnd', this.onTestEnd.bind(this)); |
| 3662 |
runner.on('runEnd', this.onRunEnd.bind(this)); |
| 3663 |
} |
| 3664 |
return _createClass(ConsoleReporter, [{ |
| 3665 |
key: "onError", |
| 3666 |
value: function onError(error) { |
| 3667 |
this.log('error', error); |
| 3668 |
} |
| 3669 |
}, { |
| 3670 |
key: "onRunStart", |
| 3671 |
value: function onRunStart(runStart) { |
| 3672 |
this.log('runStart', runStart); |
| 3673 |
} |
| 3674 |
}, { |
| 3675 |
key: "onTestStart", |
| 3676 |
value: function onTestStart(test) { |
| 3677 |
this.log('testStart', test); |
| 3678 |
} |
| 3679 |
}, { |
| 3680 |
key: "onTestEnd", |
| 3681 |
value: function onTestEnd(test) { |
| 3682 |
this.log('testEnd', test); |
| 3683 |
} |
| 3684 |
}, { |
| 3685 |
key: "onRunEnd", |
| 3686 |
value: function onRunEnd(runEnd) { |
| 3687 |
this.log('runEnd', runEnd); |
| 3688 |
} |
| 3689 |
}], [{ |
| 3690 |
key: "init", |
| 3691 |
value: function init(runner, options) { |
| 3692 |
return new ConsoleReporter(runner, options); |
| 3693 |
} |
| 3694 |
}]); |
| 3695 |
}(); |
| 3696 |
|
| 3697 |
// TODO: Consider using globalThis instead of window, so that the reporter |
| 3698 |
// works for Node.js as well. As this can add overhead, we should make |
| 3699 |
// this opt-in before we enable it for CLI. |
| 3700 |
// |
| 3701 |
// QUnit 3 will switch from `window` to `globalThis` and then make it |
| 3702 |
// no longer an implicit feature of the HTML Reporter, but rather let |
| 3703 |
// it be opt-in via `QUnit.config.reporters = ['perf']` or something |
| 3704 |
// like that. |
| 3705 |
var nativePerf = window$1 && typeof window$1.performance !== 'undefined' && |
| 3706 |
// eslint-disable-next-line compat/compat -- Checked |
| 3707 |
typeof window$1.performance.mark === 'function' && |
| 3708 |
// eslint-disable-next-line compat/compat -- Checked |
| 3709 |
typeof window$1.performance.measure === 'function' ? window$1.performance : undefined; |
| 3710 |
var perf = { |
| 3711 |
measure: nativePerf ? function (comment, startMark, endMark) { |
| 3712 |
// `performance.measure` may fail if the mark could not be found. |
| 3713 |
// reasons a specific mark could not be found include: outside code invoking `performance.clearMarks()` |
| 3714 |
try { |
| 3715 |
nativePerf.measure(comment, startMark, endMark); |
| 3716 |
} catch (ex) { |
| 3717 |
Logger.warn('performance.measure could not be executed because of ', ex.message); |
| 3718 |
} |
| 3719 |
} : function () {}, |
| 3720 |
mark: nativePerf ? nativePerf.mark.bind(nativePerf) : function () {} |
| 3721 |
}; |
| 3722 |
var PerfReporter = /*#__PURE__*/function () { |
| 3723 |
function PerfReporter(runner) { |
| 3724 |
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 3725 |
_classCallCheck(this, PerfReporter); |
| 3726 |
this.perf = options.perf || perf; |
| 3727 |
runner.on('runStart', this.onRunStart.bind(this)); |
| 3728 |
runner.on('runEnd', this.onRunEnd.bind(this)); |
| 3729 |
runner.on('suiteStart', this.onSuiteStart.bind(this)); |
| 3730 |
runner.on('suiteEnd', this.onSuiteEnd.bind(this)); |
| 3731 |
runner.on('testStart', this.onTestStart.bind(this)); |
| 3732 |
runner.on('testEnd', this.onTestEnd.bind(this)); |
| 3733 |
} |
| 3734 |
return _createClass(PerfReporter, [{ |
| 3735 |
key: "onRunStart", |
| 3736 |
value: function onRunStart() { |
| 3737 |
this.perf.mark('qunit_suite_0_start'); |
| 3738 |
} |
| 3739 |
}, { |
| 3740 |
key: "onSuiteStart", |
| 3741 |
value: function onSuiteStart(suiteStart) { |
| 3742 |
var suiteLevel = suiteStart.fullName.length; |
| 3743 |
this.perf.mark("qunit_suite_".concat(suiteLevel, "_start")); |
| 3744 |
} |
| 3745 |
}, { |
| 3746 |
key: "onSuiteEnd", |
| 3747 |
value: function onSuiteEnd(suiteEnd) { |
| 3748 |
var suiteLevel = suiteEnd.fullName.length; |
| 3749 |
var suiteName = suiteEnd.fullName.join(' – '); |
| 3750 |
this.perf.mark("qunit_suite_".concat(suiteLevel, "_end")); |
| 3751 |
this.perf.measure("QUnit Test Suite: ".concat(suiteName), "qunit_suite_".concat(suiteLevel, "_start"), "qunit_suite_".concat(suiteLevel, "_end")); |
| 3752 |
} |
| 3753 |
}, { |
| 3754 |
key: "onTestStart", |
| 3755 |
value: function onTestStart() { |
| 3756 |
this.perf.mark('qunit_test_start'); |
| 3757 |
} |
| 3758 |
}, { |
| 3759 |
key: "onTestEnd", |
| 3760 |
value: function onTestEnd(testEnd) { |
| 3761 |
this.perf.mark('qunit_test_end'); |
| 3762 |
var testName = testEnd.fullName.join(' – '); |
| 3763 |
this.perf.measure("QUnit Test: ".concat(testName), 'qunit_test_start', 'qunit_test_end'); |
| 3764 |
} |
| 3765 |
}, { |
| 3766 |
key: "onRunEnd", |
| 3767 |
value: function onRunEnd() { |
| 3768 |
this.perf.mark('qunit_suite_0_end'); |
| 3769 |
this.perf.measure('QUnit Test Run', 'qunit_suite_0_start', 'qunit_suite_0_end'); |
| 3770 |
} |
| 3771 |
}], [{ |
| 3772 |
key: "init", |
| 3773 |
value: function init(runner, options) { |
| 3774 |
return new PerfReporter(runner, options); |
| 3775 |
} |
| 3776 |
}]); |
| 3777 |
}(); |
| 3778 |
|
| 3779 |
var FORCE_COLOR, |
| 3780 |
NODE_DISABLE_COLORS, |
| 3781 |
NO_COLOR, |
| 3782 |
TERM, |
| 3783 |
isTTY = true; |
| 3784 |
if (typeof process !== 'undefined') { |
| 3785 |
var _ref = process.env || {}; |
| 3786 |
FORCE_COLOR = _ref.FORCE_COLOR; |
| 3787 |
NODE_DISABLE_COLORS = _ref.NODE_DISABLE_COLORS; |
| 3788 |
NO_COLOR = _ref.NO_COLOR; |
| 3789 |
TERM = _ref.TERM; |
| 3790 |
isTTY = process.stdout && process.stdout.isTTY; |
| 3791 |
} |
| 3792 |
var $ = { |
| 3793 |
enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (FORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY), |
| 3794 |
// modifiers |
| 3795 |
reset: init(0, 0), |
| 3796 |
bold: init(1, 22), |
| 3797 |
dim: init(2, 22), |
| 3798 |
italic: init(3, 23), |
| 3799 |
underline: init(4, 24), |
| 3800 |
inverse: init(7, 27), |
| 3801 |
hidden: init(8, 28), |
| 3802 |
strikethrough: init(9, 29), |
| 3803 |
// colors |
| 3804 |
black: init(30, 39), |
| 3805 |
red: init(31, 39), |
| 3806 |
green: init(32, 39), |
| 3807 |
yellow: init(33, 39), |
| 3808 |
blue: init(34, 39), |
| 3809 |
magenta: init(35, 39), |
| 3810 |
cyan: init(36, 39), |
| 3811 |
white: init(37, 39), |
| 3812 |
gray: init(90, 39), |
| 3813 |
grey: init(90, 39), |
| 3814 |
// background colors |
| 3815 |
bgBlack: init(40, 49), |
| 3816 |
bgRed: init(41, 49), |
| 3817 |
bgGreen: init(42, 49), |
| 3818 |
bgYellow: init(43, 49), |
| 3819 |
bgBlue: init(44, 49), |
| 3820 |
bgMagenta: init(45, 49), |
| 3821 |
bgCyan: init(46, 49), |
| 3822 |
bgWhite: init(47, 49) |
| 3823 |
}; |
| 3824 |
function run(arr, str) { |
| 3825 |
var i = 0, |
| 3826 |
tmp, |
| 3827 |
beg = '', |
| 3828 |
end = ''; |
| 3829 |
for (; i < arr.length; i++) { |
| 3830 |
tmp = arr[i]; |
| 3831 |
beg += tmp.open; |
| 3832 |
end += tmp.close; |
| 3833 |
if (!!~str.indexOf(tmp.close)) { |
| 3834 |
str = str.replace(tmp.rgx, tmp.close + tmp.open); |
| 3835 |
} |
| 3836 |
} |
| 3837 |
return beg + str + end; |
| 3838 |
} |
| 3839 |
function chain(has, keys) { |
| 3840 |
var ctx = { |
| 3841 |
has: has, |
| 3842 |
keys: keys |
| 3843 |
}; |
| 3844 |
ctx.reset = $.reset.bind(ctx); |
| 3845 |
ctx.bold = $.bold.bind(ctx); |
| 3846 |
ctx.dim = $.dim.bind(ctx); |
| 3847 |
ctx.italic = $.italic.bind(ctx); |
| 3848 |
ctx.underline = $.underline.bind(ctx); |
| 3849 |
ctx.inverse = $.inverse.bind(ctx); |
| 3850 |
ctx.hidden = $.hidden.bind(ctx); |
| 3851 |
ctx.strikethrough = $.strikethrough.bind(ctx); |
| 3852 |
ctx.black = $.black.bind(ctx); |
| 3853 |
ctx.red = $.red.bind(ctx); |
| 3854 |
ctx.green = $.green.bind(ctx); |
| 3855 |
ctx.yellow = $.yellow.bind(ctx); |
| 3856 |
ctx.blue = $.blue.bind(ctx); |
| 3857 |
ctx.magenta = $.magenta.bind(ctx); |
| 3858 |
ctx.cyan = $.cyan.bind(ctx); |
| 3859 |
ctx.white = $.white.bind(ctx); |
| 3860 |
ctx.gray = $.gray.bind(ctx); |
| 3861 |
ctx.grey = $.grey.bind(ctx); |
| 3862 |
ctx.bgBlack = $.bgBlack.bind(ctx); |
| 3863 |
ctx.bgRed = $.bgRed.bind(ctx); |
| 3864 |
ctx.bgGreen = $.bgGreen.bind(ctx); |
| 3865 |
ctx.bgYellow = $.bgYellow.bind(ctx); |
| 3866 |
ctx.bgBlue = $.bgBlue.bind(ctx); |
| 3867 |
ctx.bgMagenta = $.bgMagenta.bind(ctx); |
| 3868 |
ctx.bgCyan = $.bgCyan.bind(ctx); |
| 3869 |
ctx.bgWhite = $.bgWhite.bind(ctx); |
| 3870 |
return ctx; |
| 3871 |
} |
| 3872 |
function init(open, close) { |
| 3873 |
var blk = { |
| 3874 |
open: "\x1B[".concat(open, "m"), |
| 3875 |
close: "\x1B[".concat(close, "m"), |
| 3876 |
rgx: new RegExp("\\x1b\\[".concat(close, "m"), 'g') |
| 3877 |
}; |
| 3878 |
return function (txt) { |
| 3879 |
if (this !== void 0 && this.has !== void 0) { |
| 3880 |
!!~this.has.indexOf(open) || (this.has.push(open), this.keys.push(blk)); |
| 3881 |
return txt === void 0 ? this : $.enabled ? run(this.keys, txt + '') : txt + ''; |
| 3882 |
} |
| 3883 |
return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt + '') : txt + ''; |
| 3884 |
}; |
| 3885 |
} |
| 3886 |
|
| 3887 |
/** |
| 3888 |
* Format a given value into YAML. |
| 3889 |
* |
| 3890 |
* YAML is a superset of JSON that supports all the same data |
| 3891 |
* types and syntax, and more. As such, it is always possible |
| 3892 |
* to fallback to JSON.stringfify, but we generally avoid |
| 3893 |
* that to make output easier to read for humans. |
| 3894 |
* |
| 3895 |
* Supported data types: |
| 3896 |
* |
| 3897 |
* - null |
| 3898 |
* - boolean |
| 3899 |
* - number |
| 3900 |
* - string |
| 3901 |
* - array |
| 3902 |
* - object |
| 3903 |
* |
| 3904 |
* Anything else (including NaN, Infinity, and undefined) |
| 3905 |
* must be described in strings, for display purposes. |
| 3906 |
* |
| 3907 |
* Note that quotes are optional in YAML strings if the |
| 3908 |
* strings are "simple", and as such we generally prefer |
| 3909 |
* that for improved readability. We output strings in |
| 3910 |
* one of three ways: |
| 3911 |
* |
| 3912 |
* - bare unquoted text, for simple one-line strings. |
| 3913 |
* - JSON (quoted text), for complex one-line strings. |
| 3914 |
* - YAML Block, for complex multi-line strings. |
| 3915 |
* |
| 3916 |
* Objects with cyclical references will be stringifed as |
| 3917 |
* "[Circular]" as they cannot otherwise be represented. |
| 3918 |
*/ |
| 3919 |
function prettyYamlValue(value) { |
| 3920 |
var indent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2; |
| 3921 |
if (value === undefined) { |
| 3922 |
// Not supported in JSON/YAML, turn into string |
| 3923 |
// and let the below output it as bare string. |
| 3924 |
value = String(value); |
| 3925 |
} |
| 3926 |
|
| 3927 |
// Support IE 9-11: Use isFinite instead of ES6 Number.isFinite |
| 3928 |
if (typeof value === 'number' && !isFinite(value)) { |
| 3929 |
// Turn NaN and Infinity into simple strings. |
| 3930 |
// Paranoia: Don't return directly just in case there's |
| 3931 |
// a way to add special characters here. |
| 3932 |
value = String(value); |
| 3933 |
} |
| 3934 |
if (typeof value === 'number') { |
| 3935 |
// Simple numbers |
| 3936 |
return JSON.stringify(value); |
| 3937 |
} |
| 3938 |
if (typeof value === 'string') { |
| 3939 |
// If any of these match, then we can't output it |
| 3940 |
// as bare unquoted text, because that would either |
| 3941 |
// cause data loss or invalid YAML syntax. |
| 3942 |
// |
| 3943 |
// - Quotes, escapes, line breaks, or JSON-like stuff. |
| 3944 |
// - Not allowed in YAML unquoted strings per https://yaml.org/spec/1.2.2/#733-plain-style |
| 3945 |
// * ": " (colon followed by space) |
| 3946 |
// * " #" (space followed by hash) |
| 3947 |
var rSpecialJson = /['"\\/[{}\]\r\n|:#]/; |
| 3948 |
|
| 3949 |
// - Characters that are special at the start of a YAML value |
| 3950 |
var rSpecialYaml = /[-?:,[\]{}#&*!|=>'"%@`]/; |
| 3951 |
|
| 3952 |
// - Leading or trailing whitespace. |
| 3953 |
var rUntrimmed = /(^\s|\s$)/; |
| 3954 |
|
| 3955 |
// - Ambiguous as YAML number, e.g. '2', '-1.2', '.2', or '2_000' |
| 3956 |
var rNumerical = /^[\d._-]+$/; |
| 3957 |
|
| 3958 |
// - Ambiguous as YAML bool. |
| 3959 |
// Use case-insensitive match, although technically only |
| 3960 |
// fully-lower, fully-upper, or uppercase-first would be ambiguous. |
| 3961 |
// e.g. true/True/TRUE, but not tRUe. |
| 3962 |
var rBool = /^(true|false|y|n|yes|no|on|off)$/i; |
| 3963 |
|
| 3964 |
// Is this a complex string? |
| 3965 |
if (value === '' || rSpecialJson.test(value) || rSpecialYaml.test(value[0]) || rUntrimmed.test(value) || rNumerical.test(value) || rBool.test(value)) { |
| 3966 |
if (!/\n/.test(value)) { |
| 3967 |
// Complex one-line string, use JSON (quoted string) |
| 3968 |
return JSON.stringify(value); |
| 3969 |
} |
| 3970 |
|
| 3971 |
// See also <https://yaml-multiline.info/> |
| 3972 |
// Support IE 9-11: Avoid ES6 String#repeat |
| 3973 |
var _prefix = new Array(indent * 2 + 1).join(' '); |
| 3974 |
var trailingLinebreakMatch = value.match(/\n+$/); |
| 3975 |
var trailingLinebreaks = trailingLinebreakMatch ? trailingLinebreakMatch[0].length : 0; |
| 3976 |
if (trailingLinebreaks === 1) { |
| 3977 |
// Use the most straight-forward "Block" string in YAML |
| 3978 |
// without any "Chomping" indicators. |
| 3979 |
var lines = value |
| 3980 |
|
| 3981 |
// Ignore the last new line, since we'll get that one for free |
| 3982 |
// with the straight-forward Block syntax. |
| 3983 |
.replace(/\n$/, '').split('\n').map(function (line) { |
| 3984 |
return _prefix + line; |
| 3985 |
}); |
| 3986 |
return '|\n' + lines.join('\n'); |
| 3987 |
} else { |
| 3988 |
// This has either no trailing new lines, or more than 1. |
| 3989 |
// Use |+ so that YAML parsers will preserve it exactly. |
| 3990 |
var _lines = value.split('\n').map(function (line) { |
| 3991 |
return _prefix + line; |
| 3992 |
}); |
| 3993 |
return '|+\n' + _lines.join('\n'); |
| 3994 |
} |
| 3995 |
} else { |
| 3996 |
// Simple string, use bare unquoted text |
| 3997 |
return value; |
| 3998 |
} |
| 3999 |
} |
| 4000 |
var prefix = new Array(indent + 1).join(' '); |
| 4001 |
|
| 4002 |
// Handle null, boolean, array, and object |
| 4003 |
return JSON.stringify(decycledShallowClone(value), null, 2).split('\n').map(function (line, i) { |
| 4004 |
return i === 0 ? line : prefix + line; |
| 4005 |
}).join('\n'); |
| 4006 |
} |
| 4007 |
|
| 4008 |
/** |
| 4009 |
* Creates a shallow clone of an object where cycles have |
| 4010 |
* been replaced with "[Circular]". |
| 4011 |
*/ |
| 4012 |
function decycledShallowClone(object) { |
| 4013 |
var ancestors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; |
| 4014 |
if (ancestors.indexOf(object) !== -1) { |
| 4015 |
return '[Circular]'; |
| 4016 |
} |
| 4017 |
var type = Object.prototype.toString.call(object).replace(/^\[.+\s(.+?)]$/, '$1').toLowerCase(); |
| 4018 |
var clone; |
| 4019 |
switch (type) { |
| 4020 |
case 'array': |
| 4021 |
ancestors.push(object); |
| 4022 |
clone = object.map(function (element) { |
| 4023 |
return decycledShallowClone(element, ancestors); |
| 4024 |
}); |
| 4025 |
ancestors.pop(); |
| 4026 |
break; |
| 4027 |
case 'object': |
| 4028 |
ancestors.push(object); |
| 4029 |
clone = {}; |
| 4030 |
Object.keys(object).forEach(function (key) { |
| 4031 |
clone[key] = decycledShallowClone(object[key], ancestors); |
| 4032 |
}); |
| 4033 |
ancestors.pop(); |
| 4034 |
break; |
| 4035 |
default: |
| 4036 |
clone = object; |
| 4037 |
} |
| 4038 |
return clone; |
| 4039 |
} |
| 4040 |
var TapReporter = /*#__PURE__*/function () { |
| 4041 |
function TapReporter(runner) { |
| 4042 |
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 4043 |
_classCallCheck(this, TapReporter); |
| 4044 |
// Cache references to console methods to ensure we can report failures |
| 4045 |
// from tests tests that mock the console object itself. |
| 4046 |
// https://github.com/qunitjs/qunit/issues/1340 |
| 4047 |
// Support IE 9: Function#bind is supported, but no console.log.bind(). |
| 4048 |
this.log = options.log || Function.prototype.bind.call(console$1.log, console$1); |
| 4049 |
this.testCount = 0; |
| 4050 |
this.started = false; |
| 4051 |
this.ended = false; |
| 4052 |
this.bailed = false; |
| 4053 |
runner.on('error', this.onError.bind(this)); |
| 4054 |
runner.on('runStart', this.onRunStart.bind(this)); |
| 4055 |
runner.on('testEnd', this.onTestEnd.bind(this)); |
| 4056 |
runner.on('runEnd', this.onRunEnd.bind(this)); |
| 4057 |
} |
| 4058 |
return _createClass(TapReporter, [{ |
| 4059 |
key: "onRunStart", |
| 4060 |
value: function onRunStart(_runSuite) { |
| 4061 |
if (!this.started) { |
| 4062 |
this.log('TAP version 13'); |
| 4063 |
this.started = true; |
| 4064 |
} |
| 4065 |
} |
| 4066 |
}, { |
| 4067 |
key: "onError", |
| 4068 |
value: function onError(error) { |
| 4069 |
if (this.bailed) { |
| 4070 |
return; |
| 4071 |
} |
| 4072 |
this.bailed = true; |
| 4073 |
|
| 4074 |
// Imitate onTestEnd |
| 4075 |
// Skip this if we're past "runEnd" as it would look odd |
| 4076 |
if (!this.ended) { |
| 4077 |
this.onRunStart(); |
| 4078 |
this.testCount = this.testCount + 1; |
| 4079 |
this.log("not ok ".concat(this.testCount, " ").concat($.red('global failure'))); |
| 4080 |
this.logError(error); |
| 4081 |
} |
| 4082 |
this.log('Bail out! ' + errorString(error).split('\n')[0]); |
| 4083 |
if (this.ended) { |
| 4084 |
this.logError(error); |
| 4085 |
} |
| 4086 |
} |
| 4087 |
}, { |
| 4088 |
key: "onTestEnd", |
| 4089 |
value: function onTestEnd(test) { |
| 4090 |
var _this = this; |
| 4091 |
this.testCount = this.testCount + 1; |
| 4092 |
if (test.status === 'passed') { |
| 4093 |
this.log("ok ".concat(this.testCount, " ").concat(test.fullName.join(' > '))); |
| 4094 |
} else if (test.status === 'skipped') { |
| 4095 |
this.log("ok ".concat(this.testCount, " ").concat($.yellow(test.fullName.join(' > ')), " # SKIP")); |
| 4096 |
} else if (test.status === 'todo') { |
| 4097 |
this.log("not ok ".concat(this.testCount, " ").concat($.cyan(test.fullName.join(' > ')), " # TODO")); |
| 4098 |
test.errors.forEach(function (error) { |
| 4099 |
return _this.logAssertion(error, 'todo'); |
| 4100 |
}); |
| 4101 |
} else { |
| 4102 |
this.log("not ok ".concat(this.testCount, " ").concat($.red(test.fullName.join(' > ')))); |
| 4103 |
test.errors.forEach(function (error) { |
| 4104 |
return _this.logAssertion(error); |
| 4105 |
}); |
| 4106 |
} |
| 4107 |
} |
| 4108 |
}, { |
| 4109 |
key: "onRunEnd", |
| 4110 |
value: function onRunEnd(runEnd) { |
| 4111 |
this.ended = true; |
| 4112 |
this.log("1..".concat(runEnd.testCounts.total)); |
| 4113 |
this.log("# pass ".concat(runEnd.testCounts.passed)); |
| 4114 |
this.log("# ".concat($.yellow("skip ".concat(runEnd.testCounts.skipped)))); |
| 4115 |
this.log("# ".concat($.cyan("todo ".concat(runEnd.testCounts.todo)))); |
| 4116 |
this.log("# ".concat($.red("fail ".concat(runEnd.testCounts.failed)))); |
| 4117 |
} |
| 4118 |
}, { |
| 4119 |
key: "logAssertion", |
| 4120 |
value: function logAssertion(error, severity) { |
| 4121 |
var out = ' ---'; |
| 4122 |
out += "\n message: ".concat(prettyYamlValue(error.message || 'failed')); |
| 4123 |
out += "\n severity: ".concat(prettyYamlValue(severity || 'failed')); |
| 4124 |
|
| 4125 |
// When pushFailure() is used, actual/expected are initially unset but |
| 4126 |
// eventually in Test#logAssertion, for testReport#pushAssertion, these are |
| 4127 |
// forged into existence as undefined. |
| 4128 |
var hasAny = error.expected !== undefined || error.actual !== undefined; |
| 4129 |
if (hasAny) { |
| 4130 |
out += "\n actual : ".concat(prettyYamlValue(error.actual)); |
| 4131 |
out += "\n expected: ".concat(prettyYamlValue(error.expected)); |
| 4132 |
} |
| 4133 |
if (error.stack) { |
| 4134 |
// Since stacks aren't user generated, take a bit of liberty by |
| 4135 |
// adding a trailing new line to allow a straight-forward YAML Blocks. |
| 4136 |
var fmtStack = annotateStacktrace(error.stack, $.grey); |
| 4137 |
if (fmtStack.length) { |
| 4138 |
out += "\n stack: ".concat(prettyYamlValue(fmtStack + '\n')); |
| 4139 |
} |
| 4140 |
} |
| 4141 |
out += '\n ...'; |
| 4142 |
this.log(out); |
| 4143 |
} |
| 4144 |
}, { |
| 4145 |
key: "logError", |
| 4146 |
value: function logError(error) { |
| 4147 |
var out = ' ---'; |
| 4148 |
out += "\n message: ".concat(prettyYamlValue(errorString(error))); |
| 4149 |
out += "\n severity: ".concat(prettyYamlValue('failed')); |
| 4150 |
if (error && error.stack) { |
| 4151 |
var fmtStack = annotateStacktrace(error.stack, $.grey, error.toString()); |
| 4152 |
if (fmtStack.length) { |
| 4153 |
out += "\n stack: ".concat(prettyYamlValue(fmtStack + '\n')); |
| 4154 |
} |
| 4155 |
} |
| 4156 |
out += '\n ...'; |
| 4157 |
this.log(out); |
| 4158 |
} |
| 4159 |
}], [{ |
| 4160 |
key: "init", |
| 4161 |
value: function init(runner, options) { |
| 4162 |
return new TapReporter(runner, options); |
| 4163 |
} |
| 4164 |
}]); |
| 4165 |
}(); |
| 4166 |
|
| 4167 |
var reporters = { |
| 4168 |
console: ConsoleReporter, |
| 4169 |
perf: PerfReporter, |
| 4170 |
tap: TapReporter |
| 4171 |
}; |
| 4172 |
|
| 4173 |
function makeAddGlobalHook(hookName) { |
| 4174 |
return function addGlobalHook(callback) { |
| 4175 |
if (!config.globalHooks[hookName]) { |
| 4176 |
config.globalHooks[hookName] = []; |
| 4177 |
} |
| 4178 |
config.globalHooks[hookName].push(callback); |
| 4179 |
}; |
| 4180 |
} |
| 4181 |
var hooks = { |
| 4182 |
beforeEach: makeAddGlobalHook('beforeEach'), |
| 4183 |
afterEach: makeAddGlobalHook('afterEach') |
| 4184 |
}; |
| 4185 |
|
| 4186 |
/** |
| 4187 |
* Creates a seeded "sample" generator which is used for randomizing tests. |
| 4188 |
*/ |
| 4189 |
function unitSamplerGenerator(seed) { |
| 4190 |
// 32-bit xorshift, requires only a nonzero seed |
| 4191 |
// https://excamera.com/sphinx/article-xorshift.html |
| 4192 |
var sample = parseInt(generateHash(seed), 16) || -1; |
| 4193 |
return function () { |
| 4194 |
sample ^= sample << 13; |
| 4195 |
sample ^= sample >>> 17; |
| 4196 |
sample ^= sample << 5; |
| 4197 |
|
| 4198 |
// ECMAScript has no unsigned number type |
| 4199 |
if (sample < 0) { |
| 4200 |
sample += 0x100000000; |
| 4201 |
} |
| 4202 |
return sample / 0x100000000; |
| 4203 |
}; |
| 4204 |
} |
| 4205 |
var ProcessingQueue = /*#__PURE__*/function () { |
| 4206 |
/** |
| 4207 |
* @param {Function} test Reference to the QUnit.test() method |
| 4208 |
*/ |
| 4209 |
function ProcessingQueue(test) { |
| 4210 |
_classCallCheck(this, ProcessingQueue); |
| 4211 |
this.test = test; |
| 4212 |
this.priorityCount = 0; |
| 4213 |
this.unitSampler = null; |
| 4214 |
|
| 4215 |
// This is a queue of functions that are tasks within a single test. |
| 4216 |
// After tests are dequeued from config.queue they are expanded into |
| 4217 |
// a set of tasks in this queue. |
| 4218 |
this.taskQueue = []; |
| 4219 |
this.finished = false; |
| 4220 |
} |
| 4221 |
|
| 4222 |
/** |
| 4223 |
* Advances the taskQueue to the next task. If the taskQueue is empty, |
| 4224 |
* process the testQueue |
| 4225 |
*/ |
| 4226 |
return _createClass(ProcessingQueue, [{ |
| 4227 |
key: "advance", |
| 4228 |
value: function advance() { |
| 4229 |
this.advanceTaskQueue(); |
| 4230 |
if (!this.taskQueue.length && !config.blocking && !config.current) { |
| 4231 |
this.advanceTestQueue(); |
| 4232 |
} |
| 4233 |
} |
| 4234 |
|
| 4235 |
/** |
| 4236 |
* Advances the taskQueue with an increased depth |
| 4237 |
*/ |
| 4238 |
}, { |
| 4239 |
key: "advanceTaskQueue", |
| 4240 |
value: function advanceTaskQueue() { |
| 4241 |
var start = performance.now(); |
| 4242 |
config.depth = (config.depth || 0) + 1; |
| 4243 |
this.processTaskQueue(start); |
| 4244 |
config.depth--; |
| 4245 |
} |
| 4246 |
|
| 4247 |
/** |
| 4248 |
* Process the first task on the taskQueue as a promise. |
| 4249 |
* Each task is a function added by Test#queue() in /src/test.js |
| 4250 |
*/ |
| 4251 |
}, { |
| 4252 |
key: "processTaskQueue", |
| 4253 |
value: function processTaskQueue(start) { |
| 4254 |
var _this = this; |
| 4255 |
if (this.taskQueue.length && !config.blocking) { |
| 4256 |
var elapsedTime = performance.now() - start; |
| 4257 |
if (!setTimeout$1 || config.updateRate <= 0 || elapsedTime < config.updateRate) { |
| 4258 |
var task = this.taskQueue.shift(); |
| 4259 |
_Promise.resolve(task()).then(function () { |
| 4260 |
if (!_this.taskQueue.length) { |
| 4261 |
_this.advance(); |
| 4262 |
} else { |
| 4263 |
_this.processTaskQueue(start); |
| 4264 |
} |
| 4265 |
}); |
| 4266 |
} else { |
| 4267 |
setTimeout$1(function () { |
| 4268 |
_this.advance(); |
| 4269 |
}); |
| 4270 |
} |
| 4271 |
} |
| 4272 |
} |
| 4273 |
|
| 4274 |
/** |
| 4275 |
* Advance the testQueue to the next test to process. Call done() if testQueue completes. |
| 4276 |
*/ |
| 4277 |
}, { |
| 4278 |
key: "advanceTestQueue", |
| 4279 |
value: function advanceTestQueue() { |
| 4280 |
if (!config.blocking && !config.queue.length && config.depth === 0) { |
| 4281 |
this.done(); |
| 4282 |
return; |
| 4283 |
} |
| 4284 |
var testTasks = config.queue.shift(); |
| 4285 |
this.addToTaskQueue(testTasks()); |
| 4286 |
if (this.priorityCount > 0) { |
| 4287 |
this.priorityCount--; |
| 4288 |
} |
| 4289 |
this.advance(); |
| 4290 |
} |
| 4291 |
|
| 4292 |
/** |
| 4293 |
* Enqueue the tasks for a test into the task queue. |
| 4294 |
* @param {Array} tasksArray |
| 4295 |
*/ |
| 4296 |
}, { |
| 4297 |
key: "addToTaskQueue", |
| 4298 |
value: function addToTaskQueue(tasksArray) { |
| 4299 |
var _this$taskQueue; |
| 4300 |
(_this$taskQueue = this.taskQueue).push.apply(_this$taskQueue, _toConsumableArray(tasksArray)); |
| 4301 |
} |
| 4302 |
|
| 4303 |
/** |
| 4304 |
* Return the number of tasks remaining in the task queue to be processed. |
| 4305 |
* @return {number} |
| 4306 |
*/ |
| 4307 |
}, { |
| 4308 |
key: "taskCount", |
| 4309 |
value: function taskCount() { |
| 4310 |
return this.taskQueue.length; |
| 4311 |
} |
| 4312 |
|
| 4313 |
/** |
| 4314 |
* Adds a test to the TestQueue for execution. |
| 4315 |
* @param {Function} testTasksFunc |
| 4316 |
* @param {boolean} prioritize |
| 4317 |
*/ |
| 4318 |
}, { |
| 4319 |
key: "add", |
| 4320 |
value: function add(testTasksFunc, prioritize) { |
| 4321 |
if (prioritize) { |
| 4322 |
config.queue.splice(this.priorityCount++, 0, testTasksFunc); |
| 4323 |
} else if (config.seed) { |
| 4324 |
if (!this.unitSampler) { |
| 4325 |
this.unitSampler = unitSamplerGenerator(config.seed); |
| 4326 |
} |
| 4327 |
|
| 4328 |
// Insert into a random position after all prioritized items |
| 4329 |
var index = Math.floor(this.unitSampler() * (config.queue.length - this.priorityCount + 1)); |
| 4330 |
config.queue.splice(this.priorityCount + index, 0, testTasksFunc); |
| 4331 |
} else { |
| 4332 |
config.queue.push(testTasksFunc); |
| 4333 |
} |
| 4334 |
} |
| 4335 |
|
| 4336 |
/** |
| 4337 |
* This function is called when the ProcessingQueue is done processing all |
| 4338 |
* items. It handles emitting the final run events. |
| 4339 |
*/ |
| 4340 |
}, { |
| 4341 |
key: "done", |
| 4342 |
value: function done() { |
| 4343 |
// We have reached the end of the processing queue and are about to emit the |
| 4344 |
// "runEnd" event after which reporters typically stop listening and exit |
| 4345 |
// the process. First, check if we need to emit one final test. |
| 4346 |
if (config.stats.testCount === 0 && config.failOnZeroTests === true) { |
| 4347 |
var error; |
| 4348 |
if (config.filter && config.filter.length) { |
| 4349 |
error = new Error("No tests matched the filter \"".concat(config.filter, "\".")); |
| 4350 |
} else if (config.module && config.module.length) { |
| 4351 |
error = new Error("No tests matched the module \"".concat(config.module, "\".")); |
| 4352 |
} else if (config.moduleId && config.moduleId.length) { |
| 4353 |
error = new Error("No tests matched the moduleId \"".concat(config.moduleId, "\".")); |
| 4354 |
} else if (config.testId && config.testId.length) { |
| 4355 |
error = new Error("No tests matched the testId \"".concat(config.testId, "\".")); |
| 4356 |
} else { |
| 4357 |
error = new Error('No tests were run.'); |
| 4358 |
} |
| 4359 |
this.test('global failure', extend(function (assert) { |
| 4360 |
assert.pushResult({ |
| 4361 |
result: false, |
| 4362 |
message: error.message, |
| 4363 |
source: error.stack |
| 4364 |
}); |
| 4365 |
}, { |
| 4366 |
validTest: true |
| 4367 |
})); |
| 4368 |
|
| 4369 |
// We do need to call `advance()` in order to resume the processing queue. |
| 4370 |
// Once this new test is finished processing, we'll reach `done` again, and |
| 4371 |
// that time the above condition will evaluate to false. |
| 4372 |
this.advance(); |
| 4373 |
return; |
| 4374 |
} |
| 4375 |
var storage = config.storage; |
| 4376 |
var runtime = Math.round(performance.now() - config.started); |
| 4377 |
var passed = config.stats.all - config.stats.bad; |
| 4378 |
this.finished = true; |
| 4379 |
emit('runEnd', runSuite.end(true)); |
| 4380 |
runLoggingCallbacks('done', { |
| 4381 |
// @deprecated since 2.19.0 Use done() without `details` parameter, |
| 4382 |
// or use `QUnit.on('runEnd')` instead. Parameter to be replaced in |
| 4383 |
// QUnit 3.0 with test counts. |
| 4384 |
passed: passed, |
| 4385 |
failed: config.stats.bad, |
| 4386 |
total: config.stats.all, |
| 4387 |
runtime: runtime |
| 4388 |
}).then(function () { |
| 4389 |
// Clear own storage items if all tests passed |
| 4390 |
if (storage && config.stats.bad === 0) { |
| 4391 |
for (var i = storage.length - 1; i >= 0; i--) { |
| 4392 |
var key = storage.key(i); |
| 4393 |
if (key.indexOf('qunit-test-') === 0) { |
| 4394 |
storage.removeItem(key); |
| 4395 |
} |
| 4396 |
} |
| 4397 |
} |
| 4398 |
}); |
| 4399 |
} |
| 4400 |
}]); |
| 4401 |
}(); |
| 4402 |
|
| 4403 |
/** |
| 4404 |
* Handle a global error that should result in a failed test run. |
| 4405 |
* |
| 4406 |
* Summary: |
| 4407 |
* |
| 4408 |
* - If we're strictly inside a test (or one if its module hooks), the exception |
| 4409 |
* becomes a failed assertion. |
| 4410 |
* |
| 4411 |
* This has the important side-effect that uncaught exceptions (such as |
| 4412 |
* calling an undefined function) during a "todo" test do NOT result in |
| 4413 |
* a failed test run. |
| 4414 |
* |
| 4415 |
* - If we're anywhere outside a test (be it in early event callbacks, or |
| 4416 |
* internally between tests, or somewhere after "runEnd" if the process is |
| 4417 |
* still alive for some reason), then send an "error" event to the reporters. |
| 4418 |
* |
| 4419 |
* @since 2.17.0 |
| 4420 |
* @param {Error|any} error |
| 4421 |
*/ |
| 4422 |
function onUncaughtException(error) { |
| 4423 |
if (config.current) { |
| 4424 |
// This omits 'actual' and 'expected' (undefined) |
| 4425 |
config.current.assert.pushResult({ |
| 4426 |
result: false, |
| 4427 |
message: "global failure: ".concat(errorString(error)), |
| 4428 |
// We could let callers specify an offset to subtract a number of frames via |
| 4429 |
// sourceFromStacktrace, in case they are a wrapper further away from the error |
| 4430 |
// handler, and thus reduce some noise in the stack trace. However, we're not |
| 4431 |
// doing this right now because it would almost never be used in practice given |
| 4432 |
// the vast majority of error values will be Error objects, and thus have their |
| 4433 |
// own stack trace already. |
| 4434 |
source: error && error.stack || sourceFromStacktrace(2) |
| 4435 |
}); |
| 4436 |
} else { |
| 4437 |
// The "error" event was added in QUnit 2.17. |
| 4438 |
// Increase "bad assertion" stats despite no longer pushing an assertion in this case. |
| 4439 |
// This ensures "runEnd" and "QUnit.done()" handlers behave as expected, since the "bad" |
| 4440 |
// count is typically how reporters decide on the boolean outcome of the test run. |
| 4441 |
runSuite.globalFailureCount++; |
| 4442 |
config.stats.bad++; |
| 4443 |
config.stats.all++; |
| 4444 |
emit('error', error); |
| 4445 |
} |
| 4446 |
} |
| 4447 |
|
| 4448 |
/** |
| 4449 |
* Handle a window.onerror error. |
| 4450 |
* |
| 4451 |
* If there is a current test that sets the internal `ignoreGlobalErrors` field |
| 4452 |
* (such as during `assert.throws()`), then the error is ignored and native |
| 4453 |
* error reporting is suppressed as well. This is because in browsers, an error |
| 4454 |
* can sometimes end up in `window.onerror` instead of in the local try/catch. |
| 4455 |
* This ignoring of errors does not apply to our general onUncaughtException |
| 4456 |
* method, nor to our `unhandledRejection` handlers, as those are not meant |
| 4457 |
* to receive an "expected" error during `assert.throws()`. |
| 4458 |
* |
| 4459 |
* @see <https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror> |
| 4460 |
* @deprecated since 2.17.0 Use QUnit.onUncaughtException instead. |
| 4461 |
* @param {Object} details |
| 4462 |
* @param {string} details.message |
| 4463 |
* @param {string} details.fileName |
| 4464 |
* @param {number} details.lineNumber |
| 4465 |
* @param {string|undefined} [details.stacktrace] |
| 4466 |
* @return {bool} True if native error reporting should be suppressed. |
| 4467 |
*/ |
| 4468 |
function onWindowError(details) { |
| 4469 |
Logger.warn('QUnit.onError is deprecated and will be removed in QUnit 3.0.' + ' Please use QUnit.onUncaughtException instead.'); |
| 4470 |
if (config.current && config.current.ignoreGlobalErrors) { |
| 4471 |
return true; |
| 4472 |
} |
| 4473 |
var err = new Error(details.message); |
| 4474 |
err.stack = details.stacktrace || details.fileName + ':' + details.lineNumber; |
| 4475 |
onUncaughtException(err); |
| 4476 |
return false; |
| 4477 |
} |
| 4478 |
|
| 4479 |
/* eslint-disable indent */ |
| 4480 |
|
| 4481 |
/* |
| 4482 |
* This file is a modified version of google-diff-match-patch's JavaScript implementation |
| 4483 |
* (https://code.google.com/p/google-diff-match-patch/source/browse/trunk/javascript/diff_match_patch_uncompressed.js), |
| 4484 |
* modifications are licensed as more fully set forth in LICENSE.txt. |
| 4485 |
* |
| 4486 |
* The original source of google-diff-match-patch is attributable and licensed as follows: |
| 4487 |
* |
| 4488 |
* Copyright 2006 Google Inc. |
| 4489 |
* https://code.google.com/p/google-diff-match-patch/ |
| 4490 |
* |
| 4491 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4492 |
* you may not use this file except in compliance with the License. |
| 4493 |
* You may obtain a copy of the License at |
| 4494 |
* |
| 4495 |
* https://www.apache.org/licenses/LICENSE-2.0 |
| 4496 |
* |
| 4497 |
* Unless required by applicable law or agreed to in writing, software |
| 4498 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 4499 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 4500 |
* See the License for the specific language governing permissions and |
| 4501 |
* limitations under the License. |
| 4502 |
* |
| 4503 |
* More Info: |
| 4504 |
* https://code.google.com/p/google-diff-match-patch/ |
| 4505 |
* |
| 4506 |
* Usage: QUnit.diff(expected, actual) |
| 4507 |
* |
| 4508 |
*/ |
| 4509 |
function DiffMatchPatch() {} |
| 4510 |
|
| 4511 |
// DIFF FUNCTIONS |
| 4512 |
|
| 4513 |
/** |
| 4514 |
* The data structure representing a diff is an array of tuples: |
| 4515 |
* [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']] |
| 4516 |
* which means: delete 'Hello', add 'Goodbye' and keep ' world.' |
| 4517 |
*/ |
| 4518 |
var DIFF_DELETE = -1; |
| 4519 |
var DIFF_INSERT = 1; |
| 4520 |
var DIFF_EQUAL = 0; |
| 4521 |
var hasOwn = Object.prototype.hasOwnProperty; |
| 4522 |
|
| 4523 |
/** |
| 4524 |
* Find the differences between two texts. Simplifies the problem by stripping |
| 4525 |
* any common prefix or suffix off the texts before diffing. |
| 4526 |
* @param {string} text1 Old string to be diffed. |
| 4527 |
* @param {string} text2 New string to be diffed. |
| 4528 |
* @param {boolean=} optChecklines Optional speedup flag. If present and false, |
| 4529 |
* then don't run a line-level diff first to identify the changed areas. |
| 4530 |
* Defaults to true, which does a faster, slightly less optimal diff. |
| 4531 |
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. |
| 4532 |
*/ |
| 4533 |
DiffMatchPatch.prototype.DiffMain = function (text1, text2, optChecklines) { |
| 4534 |
// The diff must be complete in up to 1 second. |
| 4535 |
var deadline = Date.now() + 1000; |
| 4536 |
|
| 4537 |
// Check for null inputs. |
| 4538 |
if (text1 === null || text2 === null) { |
| 4539 |
throw new Error('Cannot diff null input.'); |
| 4540 |
} |
| 4541 |
|
| 4542 |
// Check for equality (speedup). |
| 4543 |
if (text1 === text2) { |
| 4544 |
if (text1) { |
| 4545 |
return [[DIFF_EQUAL, text1]]; |
| 4546 |
} |
| 4547 |
return []; |
| 4548 |
} |
| 4549 |
if (typeof optChecklines === 'undefined') { |
| 4550 |
optChecklines = true; |
| 4551 |
} |
| 4552 |
|
| 4553 |
// Trim off common prefix (speedup). |
| 4554 |
var commonlength = this.diffCommonPrefix(text1, text2); |
| 4555 |
var commonprefix = text1.substring(0, commonlength); |
| 4556 |
text1 = text1.substring(commonlength); |
| 4557 |
text2 = text2.substring(commonlength); |
| 4558 |
|
| 4559 |
// Trim off common suffix (speedup). |
| 4560 |
commonlength = this.diffCommonSuffix(text1, text2); |
| 4561 |
var commonsuffix = text1.substring(text1.length - commonlength); |
| 4562 |
text1 = text1.substring(0, text1.length - commonlength); |
| 4563 |
text2 = text2.substring(0, text2.length - commonlength); |
| 4564 |
|
| 4565 |
// Compute the diff on the middle block. |
| 4566 |
var diffs = this.diffCompute(text1, text2, optChecklines, deadline); |
| 4567 |
|
| 4568 |
// Restore the prefix and suffix. |
| 4569 |
if (commonprefix) { |
| 4570 |
diffs.unshift([DIFF_EQUAL, commonprefix]); |
| 4571 |
} |
| 4572 |
if (commonsuffix) { |
| 4573 |
diffs.push([DIFF_EQUAL, commonsuffix]); |
| 4574 |
} |
| 4575 |
this.diffCleanupMerge(diffs); |
| 4576 |
return diffs; |
| 4577 |
}; |
| 4578 |
|
| 4579 |
/** |
| 4580 |
* Reduce the number of edits by eliminating operationally trivial equalities. |
| 4581 |
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. |
| 4582 |
*/ |
| 4583 |
DiffMatchPatch.prototype.diffCleanupEfficiency = function (diffs) { |
| 4584 |
var changes, equalities, equalitiesLength, lastequality, pointer, preIns, preDel, postIns, postDel; |
| 4585 |
changes = false; |
| 4586 |
equalities = []; // Stack of indices where equalities are found. |
| 4587 |
equalitiesLength = 0; // Keeping our own length var is faster in JS. |
| 4588 |
/** @type {?string} */ |
| 4589 |
lastequality = null; |
| 4590 |
|
| 4591 |
// Always equal to diffs[equalities[equalitiesLength - 1]][1] |
| 4592 |
pointer = 0; // Index of current position. |
| 4593 |
|
| 4594 |
// Is there an insertion operation before the last equality. |
| 4595 |
preIns = false; |
| 4596 |
|
| 4597 |
// Is there a deletion operation before the last equality. |
| 4598 |
preDel = false; |
| 4599 |
|
| 4600 |
// Is there an insertion operation after the last equality. |
| 4601 |
postIns = false; |
| 4602 |
|
| 4603 |
// Is there a deletion operation after the last equality. |
| 4604 |
postDel = false; |
| 4605 |
while (pointer < diffs.length) { |
| 4606 |
// Equality found. |
| 4607 |
if (diffs[pointer][0] === DIFF_EQUAL) { |
| 4608 |
if (diffs[pointer][1].length < 4 && (postIns || postDel)) { |
| 4609 |
// Candidate found. |
| 4610 |
equalities[equalitiesLength++] = pointer; |
| 4611 |
preIns = postIns; |
| 4612 |
preDel = postDel; |
| 4613 |
lastequality = diffs[pointer][1]; |
| 4614 |
} else { |
| 4615 |
// Not a candidate, and can never become one. |
| 4616 |
equalitiesLength = 0; |
| 4617 |
lastequality = null; |
| 4618 |
} |
| 4619 |
postIns = postDel = false; |
| 4620 |
|
| 4621 |
// An insertion or deletion. |
| 4622 |
} else { |
| 4623 |
if (diffs[pointer][0] === DIFF_DELETE) { |
| 4624 |
postDel = true; |
| 4625 |
} else { |
| 4626 |
postIns = true; |
| 4627 |
} |
| 4628 |
|
| 4629 |
/* |
| 4630 |
* Five types to be split: |
| 4631 |
* <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del> |
| 4632 |
* <ins>A</ins>X<ins>C</ins><del>D</del> |
| 4633 |
* <ins>A</ins><del>B</del>X<ins>C</ins> |
| 4634 |
* <ins>A</del>X<ins>C</ins><del>D</del> |
| 4635 |
* <ins>A</ins><del>B</del>X<del>C</del> |
| 4636 |
*/ |
| 4637 |
if (lastequality && (preIns && preDel && postIns && postDel || lastequality.length < 2 && preIns + preDel + postIns + postDel === 3)) { |
| 4638 |
// Duplicate record. |
| 4639 |
diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastequality]); |
| 4640 |
|
| 4641 |
// Change second copy to insert. |
| 4642 |
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; |
| 4643 |
equalitiesLength--; // Throw away the equality we just deleted; |
| 4644 |
lastequality = null; |
| 4645 |
if (preIns && preDel) { |
| 4646 |
// No changes made which could affect previous entry, keep going. |
| 4647 |
postIns = postDel = true; |
| 4648 |
equalitiesLength = 0; |
| 4649 |
} else { |
| 4650 |
equalitiesLength--; // Throw away the previous equality. |
| 4651 |
pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1; |
| 4652 |
postIns = postDel = false; |
| 4653 |
} |
| 4654 |
changes = true; |
| 4655 |
} |
| 4656 |
} |
| 4657 |
pointer++; |
| 4658 |
} |
| 4659 |
if (changes) { |
| 4660 |
this.diffCleanupMerge(diffs); |
| 4661 |
} |
| 4662 |
}; |
| 4663 |
|
| 4664 |
/** |
| 4665 |
* Convert a diff array into a pretty HTML report. |
| 4666 |
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. |
| 4667 |
* @param {integer} string to be beautified. |
| 4668 |
* @return {string} HTML representation. |
| 4669 |
*/ |
| 4670 |
DiffMatchPatch.prototype.diffPrettyHtml = function (diffs) { |
| 4671 |
var html = []; |
| 4672 |
for (var x = 0; x < diffs.length; x++) { |
| 4673 |
var op = diffs[x][0]; // Operation (insert, delete, equal) |
| 4674 |
var data = diffs[x][1]; // Text of change. |
| 4675 |
switch (op) { |
| 4676 |
case DIFF_INSERT: |
| 4677 |
html[x] = '<ins>' + escapeText(data) + '</ins>'; |
| 4678 |
break; |
| 4679 |
case DIFF_DELETE: |
| 4680 |
html[x] = '<del>' + escapeText(data) + '</del>'; |
| 4681 |
break; |
| 4682 |
case DIFF_EQUAL: |
| 4683 |
html[x] = '<span>' + escapeText(data) + '</span>'; |
| 4684 |
break; |
| 4685 |
} |
| 4686 |
} |
| 4687 |
return html.join(''); |
| 4688 |
}; |
| 4689 |
|
| 4690 |
/** |
| 4691 |
* Determine the common prefix of two strings. |
| 4692 |
* @param {string} text1 First string. |
| 4693 |
* @param {string} text2 Second string. |
| 4694 |
* @return {number} The number of characters common to the start of each |
| 4695 |
* string. |
| 4696 |
*/ |
| 4697 |
DiffMatchPatch.prototype.diffCommonPrefix = function (text1, text2) { |
| 4698 |
var pointermid, pointermax, pointermin, pointerstart; |
| 4699 |
|
| 4700 |
// Quick check for common null cases. |
| 4701 |
if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) { |
| 4702 |
return 0; |
| 4703 |
} |
| 4704 |
|
| 4705 |
// Binary search. |
| 4706 |
// Performance analysis: https://neil.fraser.name/news/2007/10/09/ |
| 4707 |
pointermin = 0; |
| 4708 |
pointermax = Math.min(text1.length, text2.length); |
| 4709 |
pointermid = pointermax; |
| 4710 |
pointerstart = 0; |
| 4711 |
while (pointermin < pointermid) { |
| 4712 |
if (text1.substring(pointerstart, pointermid) === text2.substring(pointerstart, pointermid)) { |
| 4713 |
pointermin = pointermid; |
| 4714 |
pointerstart = pointermin; |
| 4715 |
} else { |
| 4716 |
pointermax = pointermid; |
| 4717 |
} |
| 4718 |
pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin); |
| 4719 |
} |
| 4720 |
return pointermid; |
| 4721 |
}; |
| 4722 |
|
| 4723 |
/** |
| 4724 |
* Determine the common suffix of two strings. |
| 4725 |
* @param {string} text1 First string. |
| 4726 |
* @param {string} text2 Second string. |
| 4727 |
* @return {number} The number of characters common to the end of each string. |
| 4728 |
*/ |
| 4729 |
DiffMatchPatch.prototype.diffCommonSuffix = function (text1, text2) { |
| 4730 |
var pointermid, pointermax, pointermin, pointerend; |
| 4731 |
|
| 4732 |
// Quick check for common null cases. |
| 4733 |
if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) { |
| 4734 |
return 0; |
| 4735 |
} |
| 4736 |
|
| 4737 |
// Binary search. |
| 4738 |
// Performance analysis: https://neil.fraser.name/news/2007/10/09/ |
| 4739 |
pointermin = 0; |
| 4740 |
pointermax = Math.min(text1.length, text2.length); |
| 4741 |
pointermid = pointermax; |
| 4742 |
pointerend = 0; |
| 4743 |
while (pointermin < pointermid) { |
| 4744 |
if (text1.substring(text1.length - pointermid, text1.length - pointerend) === text2.substring(text2.length - pointermid, text2.length - pointerend)) { |
| 4745 |
pointermin = pointermid; |
| 4746 |
pointerend = pointermin; |
| 4747 |
} else { |
| 4748 |
pointermax = pointermid; |
| 4749 |
} |
| 4750 |
pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin); |
| 4751 |
} |
| 4752 |
return pointermid; |
| 4753 |
}; |
| 4754 |
|
| 4755 |
/** |
| 4756 |
* Find the differences between two texts. Assumes that the texts do not |
| 4757 |
* have any common prefix or suffix. |
| 4758 |
* @param {string} text1 Old string to be diffed. |
| 4759 |
* @param {string} text2 New string to be diffed. |
| 4760 |
* @param {boolean} checklines Speedup flag. If false, then don't run a |
| 4761 |
* line-level diff first to identify the changed areas. |
| 4762 |
* If true, then run a faster, slightly less optimal diff. |
| 4763 |
* @param {number} deadline Time when the diff should be complete by. |
| 4764 |
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. |
| 4765 |
* @private |
| 4766 |
*/ |
| 4767 |
DiffMatchPatch.prototype.diffCompute = function (text1, text2, checklines, deadline) { |
| 4768 |
var diffs, longtext, shorttext, i, hm, text1A, text2A, text1B, text2B, midCommon, diffsA, diffsB; |
| 4769 |
if (!text1) { |
| 4770 |
// Just add some text (speedup). |
| 4771 |
return [[DIFF_INSERT, text2]]; |
| 4772 |
} |
| 4773 |
if (!text2) { |
| 4774 |
// Just delete some text (speedup). |
| 4775 |
return [[DIFF_DELETE, text1]]; |
| 4776 |
} |
| 4777 |
longtext = text1.length > text2.length ? text1 : text2; |
| 4778 |
shorttext = text1.length > text2.length ? text2 : text1; |
| 4779 |
i = longtext.indexOf(shorttext); |
| 4780 |
if (i !== -1) { |
| 4781 |
// Shorter text is inside the longer text (speedup). |
| 4782 |
diffs = [[DIFF_INSERT, longtext.substring(0, i)], [DIFF_EQUAL, shorttext], [DIFF_INSERT, longtext.substring(i + shorttext.length)]]; |
| 4783 |
|
| 4784 |
// Swap insertions for deletions if diff is reversed. |
| 4785 |
if (text1.length > text2.length) { |
| 4786 |
diffs[0][0] = diffs[2][0] = DIFF_DELETE; |
| 4787 |
} |
| 4788 |
return diffs; |
| 4789 |
} |
| 4790 |
if (shorttext.length === 1) { |
| 4791 |
// Single character string. |
| 4792 |
// After the previous speedup, the character can't be an equality. |
| 4793 |
return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]]; |
| 4794 |
} |
| 4795 |
|
| 4796 |
// Check to see if the problem can be split in two. |
| 4797 |
hm = this.diffHalfMatch(text1, text2); |
| 4798 |
if (hm) { |
| 4799 |
// A half-match was found, sort out the return data. |
| 4800 |
text1A = hm[0]; |
| 4801 |
text1B = hm[1]; |
| 4802 |
text2A = hm[2]; |
| 4803 |
text2B = hm[3]; |
| 4804 |
midCommon = hm[4]; |
| 4805 |
|
| 4806 |
// Send both pairs off for separate processing. |
| 4807 |
diffsA = this.DiffMain(text1A, text2A, checklines, deadline); |
| 4808 |
diffsB = this.DiffMain(text1B, text2B, checklines, deadline); |
| 4809 |
|
| 4810 |
// Merge the results. |
| 4811 |
return diffsA.concat([[DIFF_EQUAL, midCommon]], diffsB); |
| 4812 |
} |
| 4813 |
if (checklines && text1.length > 100 && text2.length > 100) { |
| 4814 |
return this.diffLineMode(text1, text2, deadline); |
| 4815 |
} |
| 4816 |
return this.diffBisect(text1, text2, deadline); |
| 4817 |
}; |
| 4818 |
|
| 4819 |
/** |
| 4820 |
* Do the two texts share a substring which is at least half the length of the |
| 4821 |
* longer text? |
| 4822 |
* This speedup can produce non-minimal diffs. |
| 4823 |
* @param {string} text1 First string. |
| 4824 |
* @param {string} text2 Second string. |
| 4825 |
* @return {Array.<string>} Five element Array, containing the prefix of |
| 4826 |
* text1, the suffix of text1, the prefix of text2, the suffix of |
| 4827 |
* text2 and the common middle. Or null if there was no match. |
| 4828 |
* @private |
| 4829 |
*/ |
| 4830 |
DiffMatchPatch.prototype.diffHalfMatch = function (text1, text2) { |
| 4831 |
var longtext, shorttext, dmp, text1A, text2B, text2A, text1B, midCommon, hm1, hm2, hm; |
| 4832 |
longtext = text1.length > text2.length ? text1 : text2; |
| 4833 |
shorttext = text1.length > text2.length ? text2 : text1; |
| 4834 |
if (longtext.length < 4 || shorttext.length * 2 < longtext.length) { |
| 4835 |
return null; // Pointless. |
| 4836 |
} |
| 4837 |
dmp = this; // 'this' becomes 'window' in a closure. |
| 4838 |
|
| 4839 |
/** |
| 4840 |
* Does a substring of shorttext exist within longtext such that the substring |
| 4841 |
* is at least half the length of longtext? |
| 4842 |
* Closure, but does not reference any external variables. |
| 4843 |
* @param {string} longtext Longer string. |
| 4844 |
* @param {string} shorttext Shorter string. |
| 4845 |
* @param {number} i Start index of quarter length substring within longtext. |
| 4846 |
* @return {Array.<string>} Five element Array, containing the prefix of |
| 4847 |
* longtext, the suffix of longtext, the prefix of shorttext, the suffix |
| 4848 |
* of shorttext and the common middle. Or null if there was no match. |
| 4849 |
* @private |
| 4850 |
*/ |
| 4851 |
function diffHalfMatchI(longtext, shorttext, i) { |
| 4852 |
var seed, j, bestCommon, prefixLength, suffixLength, bestLongtextA, bestLongtextB, bestShorttextA, bestShorttextB; |
| 4853 |
|
| 4854 |
// Start with a 1/4 length substring at position i as a seed. |
| 4855 |
seed = longtext.substring(i, i + Math.floor(longtext.length / 4)); |
| 4856 |
j = -1; |
| 4857 |
bestCommon = ''; |
| 4858 |
while ((j = shorttext.indexOf(seed, j + 1)) !== -1) { |
| 4859 |
prefixLength = dmp.diffCommonPrefix(longtext.substring(i), shorttext.substring(j)); |
| 4860 |
suffixLength = dmp.diffCommonSuffix(longtext.substring(0, i), shorttext.substring(0, j)); |
| 4861 |
if (bestCommon.length < suffixLength + prefixLength) { |
| 4862 |
bestCommon = shorttext.substring(j - suffixLength, j) + shorttext.substring(j, j + prefixLength); |
| 4863 |
bestLongtextA = longtext.substring(0, i - suffixLength); |
| 4864 |
bestLongtextB = longtext.substring(i + prefixLength); |
| 4865 |
bestShorttextA = shorttext.substring(0, j - suffixLength); |
| 4866 |
bestShorttextB = shorttext.substring(j + prefixLength); |
| 4867 |
} |
| 4868 |
} |
| 4869 |
if (bestCommon.length * 2 >= longtext.length) { |
| 4870 |
return [bestLongtextA, bestLongtextB, bestShorttextA, bestShorttextB, bestCommon]; |
| 4871 |
} else { |
| 4872 |
return null; |
| 4873 |
} |
| 4874 |
} |
| 4875 |
|
| 4876 |
// First check if the second quarter is the seed for a half-match. |
| 4877 |
hm1 = diffHalfMatchI(longtext, shorttext, Math.ceil(longtext.length / 4)); |
| 4878 |
|
| 4879 |
// Check again based on the third quarter. |
| 4880 |
hm2 = diffHalfMatchI(longtext, shorttext, Math.ceil(longtext.length / 2)); |
| 4881 |
if (!hm1 && !hm2) { |
| 4882 |
return null; |
| 4883 |
} else if (!hm2) { |
| 4884 |
hm = hm1; |
| 4885 |
} else if (!hm1) { |
| 4886 |
hm = hm2; |
| 4887 |
} else { |
| 4888 |
// Both matched. Select the longest. |
| 4889 |
hm = hm1[4].length > hm2[4].length ? hm1 : hm2; |
| 4890 |
} |
| 4891 |
|
| 4892 |
// A half-match was found, sort out the return data. |
| 4893 |
if (text1.length > text2.length) { |
| 4894 |
text1A = hm[0]; |
| 4895 |
text1B = hm[1]; |
| 4896 |
text2A = hm[2]; |
| 4897 |
text2B = hm[3]; |
| 4898 |
} else { |
| 4899 |
text2A = hm[0]; |
| 4900 |
text2B = hm[1]; |
| 4901 |
text1A = hm[2]; |
| 4902 |
text1B = hm[3]; |
| 4903 |
} |
| 4904 |
midCommon = hm[4]; |
| 4905 |
return [text1A, text1B, text2A, text2B, midCommon]; |
| 4906 |
}; |
| 4907 |
|
| 4908 |
/** |
| 4909 |
* Do a quick line-level diff on both strings, then rediff the parts for |
| 4910 |
* greater accuracy. |
| 4911 |
* This speedup can produce non-minimal diffs. |
| 4912 |
* @param {string} text1 Old string to be diffed. |
| 4913 |
* @param {string} text2 New string to be diffed. |
| 4914 |
* @param {number} deadline Time when the diff should be complete by. |
| 4915 |
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. |
| 4916 |
* @private |
| 4917 |
*/ |
| 4918 |
DiffMatchPatch.prototype.diffLineMode = function (text1, text2, deadline) { |
| 4919 |
var a, diffs, linearray, pointer, countInsert, countDelete, textInsert, textDelete, j; |
| 4920 |
|
| 4921 |
// Scan the text on a line-by-line basis first. |
| 4922 |
a = this.diffLinesToChars(text1, text2); |
| 4923 |
text1 = a.chars1; |
| 4924 |
text2 = a.chars2; |
| 4925 |
linearray = a.lineArray; |
| 4926 |
diffs = this.DiffMain(text1, text2, false, deadline); |
| 4927 |
|
| 4928 |
// Convert the diff back to original text. |
| 4929 |
this.diffCharsToLines(diffs, linearray); |
| 4930 |
|
| 4931 |
// Eliminate freak matches (e.g. blank lines) |
| 4932 |
this.diffCleanupSemantic(diffs); |
| 4933 |
|
| 4934 |
// Rediff any replacement blocks, this time character-by-character. |
| 4935 |
// Add a dummy entry at the end. |
| 4936 |
diffs.push([DIFF_EQUAL, '']); |
| 4937 |
pointer = 0; |
| 4938 |
countDelete = 0; |
| 4939 |
countInsert = 0; |
| 4940 |
textDelete = ''; |
| 4941 |
textInsert = ''; |
| 4942 |
while (pointer < diffs.length) { |
| 4943 |
switch (diffs[pointer][0]) { |
| 4944 |
case DIFF_INSERT: |
| 4945 |
countInsert++; |
| 4946 |
textInsert += diffs[pointer][1]; |
| 4947 |
break; |
| 4948 |
case DIFF_DELETE: |
| 4949 |
countDelete++; |
| 4950 |
textDelete += diffs[pointer][1]; |
| 4951 |
break; |
| 4952 |
case DIFF_EQUAL: |
| 4953 |
// Upon reaching an equality, check for prior redundancies. |
| 4954 |
if (countDelete >= 1 && countInsert >= 1) { |
| 4955 |
// Delete the offending records and add the merged ones. |
| 4956 |
diffs.splice(pointer - countDelete - countInsert, countDelete + countInsert); |
| 4957 |
pointer = pointer - countDelete - countInsert; |
| 4958 |
a = this.DiffMain(textDelete, textInsert, false, deadline); |
| 4959 |
for (j = a.length - 1; j >= 0; j--) { |
| 4960 |
diffs.splice(pointer, 0, a[j]); |
| 4961 |
} |
| 4962 |
pointer = pointer + a.length; |
| 4963 |
} |
| 4964 |
countInsert = 0; |
| 4965 |
countDelete = 0; |
| 4966 |
textDelete = ''; |
| 4967 |
textInsert = ''; |
| 4968 |
break; |
| 4969 |
} |
| 4970 |
pointer++; |
| 4971 |
} |
| 4972 |
diffs.pop(); // Remove the dummy entry at the end. |
| 4973 |
|
| 4974 |
return diffs; |
| 4975 |
}; |
| 4976 |
|
| 4977 |
/** |
| 4978 |
* Find the 'middle snake' of a diff, split the problem in two |
| 4979 |
* and return the recursively constructed diff. |
| 4980 |
* See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations. |
| 4981 |
* @param {string} text1 Old string to be diffed. |
| 4982 |
* @param {string} text2 New string to be diffed. |
| 4983 |
* @param {number} deadline Time at which to bail if not yet complete. |
| 4984 |
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. |
| 4985 |
* @private |
| 4986 |
*/ |
| 4987 |
DiffMatchPatch.prototype.diffBisect = function (text1, text2, deadline) { |
| 4988 |
var text1Length, text2Length, maxD, vOffset, vLength, v1, v2, x, delta, front, k1start, k1end, k2start, k2end, k2Offset, k1Offset, x1, x2, y1, y2, d, k1, k2; |
| 4989 |
|
| 4990 |
// Cache the text lengths to prevent multiple calls. |
| 4991 |
text1Length = text1.length; |
| 4992 |
text2Length = text2.length; |
| 4993 |
maxD = Math.ceil((text1Length + text2Length) / 2); |
| 4994 |
vOffset = maxD; |
| 4995 |
vLength = 2 * maxD; |
| 4996 |
v1 = new Array(vLength); |
| 4997 |
v2 = new Array(vLength); |
| 4998 |
|
| 4999 |
// Setting all elements to -1 is faster in Chrome & Firefox than mixing |
| 5000 |
// integers and undefined. |
| 5001 |
for (x = 0; x < vLength; x++) { |
| 5002 |
v1[x] = -1; |
| 5003 |
v2[x] = -1; |
| 5004 |
} |
| 5005 |
v1[vOffset + 1] = 0; |
| 5006 |
v2[vOffset + 1] = 0; |
| 5007 |
delta = text1Length - text2Length; |
| 5008 |
|
| 5009 |
// If the total number of characters is odd, then the front path will collide |
| 5010 |
// with the reverse path. |
| 5011 |
front = delta % 2 !== 0; |
| 5012 |
|
| 5013 |
// Offsets for start and end of k loop. |
| 5014 |
// Prevents mapping of space beyond the grid. |
| 5015 |
k1start = 0; |
| 5016 |
k1end = 0; |
| 5017 |
k2start = 0; |
| 5018 |
k2end = 0; |
| 5019 |
for (d = 0; d < maxD; d++) { |
| 5020 |
// Bail out if deadline is reached. |
| 5021 |
if (Date.now() > deadline) { |
| 5022 |
break; |
| 5023 |
} |
| 5024 |
|
| 5025 |
// Walk the front path one step. |
| 5026 |
for (k1 = -d + k1start; k1 <= d - k1end; k1 += 2) { |
| 5027 |
k1Offset = vOffset + k1; |
| 5028 |
if (k1 === -d || k1 !== d && v1[k1Offset - 1] < v1[k1Offset + 1]) { |
| 5029 |
x1 = v1[k1Offset + 1]; |
| 5030 |
} else { |
| 5031 |
x1 = v1[k1Offset - 1] + 1; |
| 5032 |
} |
| 5033 |
y1 = x1 - k1; |
| 5034 |
while (x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1)) { |
| 5035 |
x1++; |
| 5036 |
y1++; |
| 5037 |
} |
| 5038 |
v1[k1Offset] = x1; |
| 5039 |
if (x1 > text1Length) { |
| 5040 |
// Ran off the right of the graph. |
| 5041 |
k1end += 2; |
| 5042 |
} else if (y1 > text2Length) { |
| 5043 |
// Ran off the bottom of the graph. |
| 5044 |
k1start += 2; |
| 5045 |
} else if (front) { |
| 5046 |
k2Offset = vOffset + delta - k1; |
| 5047 |
if (k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] !== -1) { |
| 5048 |
// Mirror x2 onto top-left coordinate system. |
| 5049 |
x2 = text1Length - v2[k2Offset]; |
| 5050 |
if (x1 >= x2) { |
| 5051 |
// Overlap detected. |
| 5052 |
return this.diffBisectSplit(text1, text2, x1, y1, deadline); |
| 5053 |
} |
| 5054 |
} |
| 5055 |
} |
| 5056 |
} |
| 5057 |
|
| 5058 |
// Walk the reverse path one step. |
| 5059 |
for (k2 = -d + k2start; k2 <= d - k2end; k2 += 2) { |
| 5060 |
k2Offset = vOffset + k2; |
| 5061 |
if (k2 === -d || k2 !== d && v2[k2Offset - 1] < v2[k2Offset + 1]) { |
| 5062 |
x2 = v2[k2Offset + 1]; |
| 5063 |
} else { |
| 5064 |
x2 = v2[k2Offset - 1] + 1; |
| 5065 |
} |
| 5066 |
y2 = x2 - k2; |
| 5067 |
while (x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1)) { |
| 5068 |
x2++; |
| 5069 |
y2++; |
| 5070 |
} |
| 5071 |
v2[k2Offset] = x2; |
| 5072 |
if (x2 > text1Length) { |
| 5073 |
// Ran off the left of the graph. |
| 5074 |
k2end += 2; |
| 5075 |
} else if (y2 > text2Length) { |
| 5076 |
// Ran off the top of the graph. |
| 5077 |
k2start += 2; |
| 5078 |
} else if (!front) { |
| 5079 |
k1Offset = vOffset + delta - k2; |
| 5080 |
if (k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] !== -1) { |
| 5081 |
x1 = v1[k1Offset]; |
| 5082 |
y1 = vOffset + x1 - k1Offset; |
| 5083 |
|
| 5084 |
// Mirror x2 onto top-left coordinate system. |
| 5085 |
x2 = text1Length - x2; |
| 5086 |
if (x1 >= x2) { |
| 5087 |
// Overlap detected. |
| 5088 |
return this.diffBisectSplit(text1, text2, x1, y1, deadline); |
| 5089 |
} |
| 5090 |
} |
| 5091 |
} |
| 5092 |
} |
| 5093 |
} |
| 5094 |
|
| 5095 |
// Diff took too long and hit the deadline or |
| 5096 |
// number of diffs equals number of characters, no commonality at all. |
| 5097 |
return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]]; |
| 5098 |
}; |
| 5099 |
|
| 5100 |
/** |
| 5101 |
* Given the location of the 'middle snake', split the diff in two parts |
| 5102 |
* and recurse. |
| 5103 |
* @param {string} text1 Old string to be diffed. |
| 5104 |
* @param {string} text2 New string to be diffed. |
| 5105 |
* @param {number} x Index of split point in text1. |
| 5106 |
* @param {number} y Index of split point in text2. |
| 5107 |
* @param {number} deadline Time at which to bail if not yet complete. |
| 5108 |
* @return {!Array.<!DiffMatchPatch.Diff>} Array of diff tuples. |
| 5109 |
* @private |
| 5110 |
*/ |
| 5111 |
DiffMatchPatch.prototype.diffBisectSplit = function (text1, text2, x, y, deadline) { |
| 5112 |
var text1a, text1b, text2a, text2b, diffs, diffsb; |
| 5113 |
text1a = text1.substring(0, x); |
| 5114 |
text2a = text2.substring(0, y); |
| 5115 |
text1b = text1.substring(x); |
| 5116 |
text2b = text2.substring(y); |
| 5117 |
|
| 5118 |
// Compute both diffs serially. |
| 5119 |
diffs = this.DiffMain(text1a, text2a, false, deadline); |
| 5120 |
diffsb = this.DiffMain(text1b, text2b, false, deadline); |
| 5121 |
return diffs.concat(diffsb); |
| 5122 |
}; |
| 5123 |
|
| 5124 |
/** |
| 5125 |
* Reduce the number of edits by eliminating semantically trivial equalities. |
| 5126 |
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. |
| 5127 |
*/ |
| 5128 |
DiffMatchPatch.prototype.diffCleanupSemantic = function (diffs) { |
| 5129 |
var changes = false; |
| 5130 |
var equalities = []; // Stack of indices where equalities are found. |
| 5131 |
var equalitiesLength = 0; // Keeping our own length var is faster in JS. |
| 5132 |
/** @type {?string} */ |
| 5133 |
var lastequality = null; |
| 5134 |
|
| 5135 |
// Always equal to diffs[equalities[equalitiesLength - 1]][1] |
| 5136 |
var pointer = 0; // Index of current position. |
| 5137 |
|
| 5138 |
// Number of characters that changed prior to the equality. |
| 5139 |
var lengthInsertions1 = 0; |
| 5140 |
var lengthDeletions1 = 0; |
| 5141 |
|
| 5142 |
// Number of characters that changed after the equality. |
| 5143 |
var lengthInsertions2 = 0; |
| 5144 |
var lengthDeletions2 = 0; |
| 5145 |
while (pointer < diffs.length) { |
| 5146 |
if (diffs[pointer][0] === DIFF_EQUAL) { |
| 5147 |
// Equality found. |
| 5148 |
equalities[equalitiesLength++] = pointer; |
| 5149 |
lengthInsertions1 = lengthInsertions2; |
| 5150 |
lengthDeletions1 = lengthDeletions2; |
| 5151 |
lengthInsertions2 = 0; |
| 5152 |
lengthDeletions2 = 0; |
| 5153 |
lastequality = diffs[pointer][1]; |
| 5154 |
} else { |
| 5155 |
// An insertion or deletion. |
| 5156 |
if (diffs[pointer][0] === DIFF_INSERT) { |
| 5157 |
lengthInsertions2 += diffs[pointer][1].length; |
| 5158 |
} else { |
| 5159 |
lengthDeletions2 += diffs[pointer][1].length; |
| 5160 |
} |
| 5161 |
|
| 5162 |
// Eliminate an equality that is smaller or equal to the edits on both |
| 5163 |
// sides of it. |
| 5164 |
if (lastequality && lastequality.length <= Math.max(lengthInsertions1, lengthDeletions1) && lastequality.length <= Math.max(lengthInsertions2, lengthDeletions2)) { |
| 5165 |
// Duplicate record. |
| 5166 |
diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastequality]); |
| 5167 |
|
| 5168 |
// Change second copy to insert. |
| 5169 |
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; |
| 5170 |
|
| 5171 |
// Throw away the equality we just deleted. |
| 5172 |
equalitiesLength--; |
| 5173 |
|
| 5174 |
// Throw away the previous equality (it needs to be reevaluated). |
| 5175 |
equalitiesLength--; |
| 5176 |
pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1; |
| 5177 |
|
| 5178 |
// Reset the counters. |
| 5179 |
lengthInsertions1 = 0; |
| 5180 |
lengthDeletions1 = 0; |
| 5181 |
lengthInsertions2 = 0; |
| 5182 |
lengthDeletions2 = 0; |
| 5183 |
lastequality = null; |
| 5184 |
changes = true; |
| 5185 |
} |
| 5186 |
} |
| 5187 |
pointer++; |
| 5188 |
} |
| 5189 |
|
| 5190 |
// Normalize the diff. |
| 5191 |
if (changes) { |
| 5192 |
this.diffCleanupMerge(diffs); |
| 5193 |
} |
| 5194 |
var deletion, insertion, overlapLength1, overlapLength2; |
| 5195 |
|
| 5196 |
// Find any overlaps between deletions and insertions. |
| 5197 |
// e.g: <del>abcxxx</del><ins>xxxdef</ins> |
| 5198 |
// -> <del>abc</del>xxx<ins>def</ins> |
| 5199 |
// e.g: <del>xxxabc</del><ins>defxxx</ins> |
| 5200 |
// -> <ins>def</ins>xxx<del>abc</del> |
| 5201 |
// Only extract an overlap if it is as big as the edit ahead or behind it. |
| 5202 |
pointer = 1; |
| 5203 |
while (pointer < diffs.length) { |
| 5204 |
if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) { |
| 5205 |
deletion = diffs[pointer - 1][1]; |
| 5206 |
insertion = diffs[pointer][1]; |
| 5207 |
overlapLength1 = this.diffCommonOverlap(deletion, insertion); |
| 5208 |
overlapLength2 = this.diffCommonOverlap(insertion, deletion); |
| 5209 |
if (overlapLength1 >= overlapLength2) { |
| 5210 |
if (overlapLength1 >= deletion.length / 2 || overlapLength1 >= insertion.length / 2) { |
| 5211 |
// Overlap found. Insert an equality and trim the surrounding edits. |
| 5212 |
diffs.splice(pointer, 0, [DIFF_EQUAL, insertion.substring(0, overlapLength1)]); |
| 5213 |
diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlapLength1); |
| 5214 |
diffs[pointer + 1][1] = insertion.substring(overlapLength1); |
| 5215 |
pointer++; |
| 5216 |
} |
| 5217 |
} else { |
| 5218 |
if (overlapLength2 >= deletion.length / 2 || overlapLength2 >= insertion.length / 2) { |
| 5219 |
// Reverse overlap found. |
| 5220 |
// Insert an equality and swap and trim the surrounding edits. |
| 5221 |
diffs.splice(pointer, 0, [DIFF_EQUAL, deletion.substring(0, overlapLength2)]); |
| 5222 |
diffs[pointer - 1][0] = DIFF_INSERT; |
| 5223 |
diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlapLength2); |
| 5224 |
diffs[pointer + 1][0] = DIFF_DELETE; |
| 5225 |
diffs[pointer + 1][1] = deletion.substring(overlapLength2); |
| 5226 |
pointer++; |
| 5227 |
} |
| 5228 |
} |
| 5229 |
pointer++; |
| 5230 |
} |
| 5231 |
pointer++; |
| 5232 |
} |
| 5233 |
}; |
| 5234 |
|
| 5235 |
/** |
| 5236 |
* Determine if the suffix of one string is the prefix of another. |
| 5237 |
* @param {string} text1 First string. |
| 5238 |
* @param {string} text2 Second string. |
| 5239 |
* @return {number} The number of characters common to the end of the first |
| 5240 |
* string and the start of the second string. |
| 5241 |
* @private |
| 5242 |
*/ |
| 5243 |
DiffMatchPatch.prototype.diffCommonOverlap = function (text1, text2) { |
| 5244 |
// Cache the text lengths to prevent multiple calls. |
| 5245 |
var text1Length = text1.length; |
| 5246 |
var text2Length = text2.length; |
| 5247 |
|
| 5248 |
// Eliminate the null case. |
| 5249 |
if (text1Length === 0 || text2Length === 0) { |
| 5250 |
return 0; |
| 5251 |
} |
| 5252 |
|
| 5253 |
// Truncate the longer string. |
| 5254 |
if (text1Length > text2Length) { |
| 5255 |
text1 = text1.substring(text1Length - text2Length); |
| 5256 |
} else if (text1Length < text2Length) { |
| 5257 |
text2 = text2.substring(0, text1Length); |
| 5258 |
} |
| 5259 |
var textLength = Math.min(text1Length, text2Length); |
| 5260 |
|
| 5261 |
// Quick check for the worst case. |
| 5262 |
if (text1 === text2) { |
| 5263 |
return textLength; |
| 5264 |
} |
| 5265 |
|
| 5266 |
// Start by looking for a single character match |
| 5267 |
// and increase length until no match is found. |
| 5268 |
// Performance analysis: https://neil.fraser.name/news/2010/11/04/ |
| 5269 |
var best = 0; |
| 5270 |
var length = 1; |
| 5271 |
while (true) { |
| 5272 |
var pattern = text1.substring(textLength - length); |
| 5273 |
var found = text2.indexOf(pattern); |
| 5274 |
if (found === -1) { |
| 5275 |
return best; |
| 5276 |
} |
| 5277 |
length += found; |
| 5278 |
if (found === 0 || text1.substring(textLength - length) === text2.substring(0, length)) { |
| 5279 |
best = length; |
| 5280 |
length++; |
| 5281 |
} |
| 5282 |
} |
| 5283 |
}; |
| 5284 |
|
| 5285 |
/** |
| 5286 |
* Split two texts into an array of strings. Reduce the texts to a string of |
| 5287 |
* hashes where each Unicode character represents one line. |
| 5288 |
* @param {string} text1 First string. |
| 5289 |
* @param {string} text2 Second string. |
| 5290 |
* @return {{chars1: string, chars2: string, lineArray: !Array.<string>}} |
| 5291 |
* An object containing the encoded text1, the encoded text2 and |
| 5292 |
* the array of unique strings. |
| 5293 |
* The zeroth element of the array of unique strings is intentionally blank. |
| 5294 |
* @private |
| 5295 |
*/ |
| 5296 |
DiffMatchPatch.prototype.diffLinesToChars = function (text1, text2) { |
| 5297 |
var lineArray = []; // E.g. lineArray[4] === 'Hello\n' |
| 5298 |
var lineHash = {}; // E.g. lineHash['Hello\n'] === 4 |
| 5299 |
|
| 5300 |
// '\x00' is a valid character, but various debuggers don't like it. |
| 5301 |
// So we'll insert a junk entry to avoid generating a null character. |
| 5302 |
lineArray[0] = ''; |
| 5303 |
|
| 5304 |
/** |
| 5305 |
* Split a text into an array of strings. Reduce the texts to a string of |
| 5306 |
* hashes where each Unicode character represents one line. |
| 5307 |
* Modifies linearray and linehash through being a closure. |
| 5308 |
* @param {string} text String to encode. |
| 5309 |
* @return {string} Encoded string. |
| 5310 |
* @private |
| 5311 |
*/ |
| 5312 |
function diffLinesToCharsMunge(text) { |
| 5313 |
var chars = ''; |
| 5314 |
|
| 5315 |
// Walk the text, pulling out a substring for each line. |
| 5316 |
// text.split('\n') would would temporarily double our memory footprint. |
| 5317 |
// Modifying text would create many large strings to garbage collect. |
| 5318 |
var lineStart = 0; |
| 5319 |
var lineEnd = -1; |
| 5320 |
|
| 5321 |
// Keeping our own length variable is faster than looking it up. |
| 5322 |
var lineArrayLength = lineArray.length; |
| 5323 |
while (lineEnd < text.length - 1) { |
| 5324 |
lineEnd = text.indexOf('\n', lineStart); |
| 5325 |
if (lineEnd === -1) { |
| 5326 |
lineEnd = text.length - 1; |
| 5327 |
} |
| 5328 |
var line = text.substring(lineStart, lineEnd + 1); |
| 5329 |
lineStart = lineEnd + 1; |
| 5330 |
if (hasOwn.call(lineHash, line)) { |
| 5331 |
chars += String.fromCharCode(lineHash[line]); |
| 5332 |
} else { |
| 5333 |
chars += String.fromCharCode(lineArrayLength); |
| 5334 |
lineHash[line] = lineArrayLength; |
| 5335 |
lineArray[lineArrayLength++] = line; |
| 5336 |
} |
| 5337 |
} |
| 5338 |
return chars; |
| 5339 |
} |
| 5340 |
var chars1 = diffLinesToCharsMunge(text1); |
| 5341 |
var chars2 = diffLinesToCharsMunge(text2); |
| 5342 |
return { |
| 5343 |
chars1: chars1, |
| 5344 |
chars2: chars2, |
| 5345 |
lineArray: lineArray |
| 5346 |
}; |
| 5347 |
}; |
| 5348 |
|
| 5349 |
/** |
| 5350 |
* Rehydrate the text in a diff from a string of line hashes to real lines of |
| 5351 |
* text. |
| 5352 |
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. |
| 5353 |
* @param {!Array.<string>} lineArray Array of unique strings. |
| 5354 |
* @private |
| 5355 |
*/ |
| 5356 |
DiffMatchPatch.prototype.diffCharsToLines = function (diffs, lineArray) { |
| 5357 |
for (var x = 0; x < diffs.length; x++) { |
| 5358 |
var chars = diffs[x][1]; |
| 5359 |
var text = []; |
| 5360 |
for (var y = 0; y < chars.length; y++) { |
| 5361 |
text[y] = lineArray[chars.charCodeAt(y)]; |
| 5362 |
} |
| 5363 |
diffs[x][1] = text.join(''); |
| 5364 |
} |
| 5365 |
}; |
| 5366 |
|
| 5367 |
/** |
| 5368 |
* Reorder and merge like edit sections. Merge equalities. |
| 5369 |
* Any edit section can move as long as it doesn't cross an equality. |
| 5370 |
* @param {!Array.<!DiffMatchPatch.Diff>} diffs Array of diff tuples. |
| 5371 |
*/ |
| 5372 |
DiffMatchPatch.prototype.diffCleanupMerge = function (diffs) { |
| 5373 |
diffs.push([DIFF_EQUAL, '']); // Add a dummy entry at the end. |
| 5374 |
var pointer = 0; |
| 5375 |
var countDelete = 0; |
| 5376 |
var countInsert = 0; |
| 5377 |
var textDelete = ''; |
| 5378 |
var textInsert = ''; |
| 5379 |
while (pointer < diffs.length) { |
| 5380 |
switch (diffs[pointer][0]) { |
| 5381 |
case DIFF_INSERT: |
| 5382 |
countInsert++; |
| 5383 |
textInsert += diffs[pointer][1]; |
| 5384 |
pointer++; |
| 5385 |
break; |
| 5386 |
case DIFF_DELETE: |
| 5387 |
countDelete++; |
| 5388 |
textDelete += diffs[pointer][1]; |
| 5389 |
pointer++; |
| 5390 |
break; |
| 5391 |
case DIFF_EQUAL: |
| 5392 |
// Upon reaching an equality, check for prior redundancies. |
| 5393 |
if (countDelete + countInsert > 1) { |
| 5394 |
if (countDelete !== 0 && countInsert !== 0) { |
| 5395 |
// Factor out any common prefixes. |
| 5396 |
var commonlength = this.diffCommonPrefix(textInsert, textDelete); |
| 5397 |
if (commonlength !== 0) { |
| 5398 |
if (pointer - countDelete - countInsert > 0 && diffs[pointer - countDelete - countInsert - 1][0] === DIFF_EQUAL) { |
| 5399 |
diffs[pointer - countDelete - countInsert - 1][1] += textInsert.substring(0, commonlength); |
| 5400 |
} else { |
| 5401 |
diffs.splice(0, 0, [DIFF_EQUAL, textInsert.substring(0, commonlength)]); |
| 5402 |
pointer++; |
| 5403 |
} |
| 5404 |
textInsert = textInsert.substring(commonlength); |
| 5405 |
textDelete = textDelete.substring(commonlength); |
| 5406 |
} |
| 5407 |
|
| 5408 |
// Factor out any common suffixies. |
| 5409 |
commonlength = this.diffCommonSuffix(textInsert, textDelete); |
| 5410 |
if (commonlength !== 0) { |
| 5411 |
diffs[pointer][1] = textInsert.substring(textInsert.length - commonlength) + diffs[pointer][1]; |
| 5412 |
textInsert = textInsert.substring(0, textInsert.length - commonlength); |
| 5413 |
textDelete = textDelete.substring(0, textDelete.length - commonlength); |
| 5414 |
} |
| 5415 |
} |
| 5416 |
|
| 5417 |
// Delete the offending records and add the merged ones. |
| 5418 |
if (countDelete === 0) { |
| 5419 |
diffs.splice(pointer - countInsert, countDelete + countInsert, [DIFF_INSERT, textInsert]); |
| 5420 |
} else if (countInsert === 0) { |
| 5421 |
diffs.splice(pointer - countDelete, countDelete + countInsert, [DIFF_DELETE, textDelete]); |
| 5422 |
} else { |
| 5423 |
diffs.splice(pointer - countDelete - countInsert, countDelete + countInsert, [DIFF_DELETE, textDelete], [DIFF_INSERT, textInsert]); |
| 5424 |
} |
| 5425 |
pointer = pointer - countDelete - countInsert + (countDelete ? 1 : 0) + (countInsert ? 1 : 0) + 1; |
| 5426 |
} else if (pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL) { |
| 5427 |
// Merge this equality with the previous one. |
| 5428 |
diffs[pointer - 1][1] += diffs[pointer][1]; |
| 5429 |
diffs.splice(pointer, 1); |
| 5430 |
} else { |
| 5431 |
pointer++; |
| 5432 |
} |
| 5433 |
countInsert = 0; |
| 5434 |
countDelete = 0; |
| 5435 |
textDelete = ''; |
| 5436 |
textInsert = ''; |
| 5437 |
break; |
| 5438 |
} |
| 5439 |
} |
| 5440 |
if (diffs[diffs.length - 1][1] === '') { |
| 5441 |
diffs.pop(); // Remove the dummy entry at the end. |
| 5442 |
} |
| 5443 |
|
| 5444 |
// Second pass: look for single edits surrounded on both sides by equalities |
| 5445 |
// which can be shifted sideways to eliminate an equality. |
| 5446 |
// e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC |
| 5447 |
var changes = false; |
| 5448 |
pointer = 1; |
| 5449 |
|
| 5450 |
// Intentionally ignore the first and last element (don't need checking). |
| 5451 |
while (pointer < diffs.length - 1) { |
| 5452 |
if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) { |
| 5453 |
var diffPointer = diffs[pointer][1]; |
| 5454 |
var position = diffPointer.substring(diffPointer.length - diffs[pointer - 1][1].length); |
| 5455 |
|
| 5456 |
// This is a single edit surrounded by equalities. |
| 5457 |
if (position === diffs[pointer - 1][1]) { |
| 5458 |
// Shift the edit over the previous equality. |
| 5459 |
diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length); |
| 5460 |
diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1]; |
| 5461 |
diffs.splice(pointer - 1, 1); |
| 5462 |
changes = true; |
| 5463 |
} else if (diffPointer.substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1]) { |
| 5464 |
// Shift the edit over the next equality. |
| 5465 |
diffs[pointer - 1][1] += diffs[pointer + 1][1]; |
| 5466 |
diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1]; |
| 5467 |
diffs.splice(pointer + 1, 1); |
| 5468 |
changes = true; |
| 5469 |
} |
| 5470 |
} |
| 5471 |
pointer++; |
| 5472 |
} |
| 5473 |
|
| 5474 |
// If shifts were made, the diff needs reordering and another shift sweep. |
| 5475 |
if (changes) { |
| 5476 |
this.diffCleanupMerge(diffs); |
| 5477 |
} |
| 5478 |
}; |
| 5479 |
function diff(o, n) { |
| 5480 |
var diff, output, text; |
| 5481 |
diff = new DiffMatchPatch(); |
| 5482 |
output = diff.DiffMain(o, n); |
| 5483 |
diff.diffCleanupEfficiency(output); |
| 5484 |
text = diff.diffPrettyHtml(output); |
| 5485 |
return text; |
| 5486 |
} |
| 5487 |
|
| 5488 |
var QUnit = {}; |
| 5489 |
|
| 5490 |
// The "currentModule" object would ideally be defined using the createModule() |
| 5491 |
// function. Since it isn't, add the missing suiteReport property to it now that |
| 5492 |
// we have loaded all source code required to do so. |
| 5493 |
// |
| 5494 |
// TODO: Consider defining currentModule in core.js or module.js in its entirely |
| 5495 |
// rather than partly in config.js and partly here. |
| 5496 |
config.currentModule.suiteReport = runSuite; |
| 5497 |
config.pq = new ProcessingQueue(test); |
| 5498 |
var globalStartCalled = false; |
| 5499 |
var runStarted = false; |
| 5500 |
|
| 5501 |
// Figure out if we're running the tests from a server or not |
| 5502 |
QUnit.isLocal = window$1 && window$1.location && window$1.location.protocol === 'file:'; |
| 5503 |
|
| 5504 |
// Expose the current QUnit version |
| 5505 |
QUnit.version = '2.24.3'; |
| 5506 |
extend(QUnit, { |
| 5507 |
config: config, |
| 5508 |
diff: diff, |
| 5509 |
dump: dump, |
| 5510 |
equiv: equiv, |
| 5511 |
reporters: reporters, |
| 5512 |
hooks: hooks, |
| 5513 |
is: is, |
| 5514 |
objectType: objectType, |
| 5515 |
on: on, |
| 5516 |
onError: onWindowError, |
| 5517 |
onUncaughtException: onUncaughtException, |
| 5518 |
pushFailure: pushFailure, |
| 5519 |
assert: Assert.prototype, |
| 5520 |
module: module$1, |
| 5521 |
test: test, |
| 5522 |
// alias other test flavors for easy access |
| 5523 |
todo: test.todo, |
| 5524 |
skip: test.skip, |
| 5525 |
only: test.only, |
| 5526 |
start: function start(count) { |
| 5527 |
if (config.current) { |
| 5528 |
throw new Error('QUnit.start cannot be called inside a test context.'); |
| 5529 |
} |
| 5530 |
var globalStartAlreadyCalled = globalStartCalled; |
| 5531 |
globalStartCalled = true; |
| 5532 |
if (runStarted) { |
| 5533 |
throw new Error('Called start() while test already started running'); |
| 5534 |
} |
| 5535 |
if (globalStartAlreadyCalled || count > 1) { |
| 5536 |
throw new Error('Called start() outside of a test context too many times'); |
| 5537 |
} |
| 5538 |
if (config.autostart) { |
| 5539 |
throw new Error('Called start() outside of a test context when ' + 'QUnit.config.autostart was true'); |
| 5540 |
} |
| 5541 |
|
| 5542 |
// Until we remove QUnit.load() in QUnit 3, we keep `pageLoaded`. |
| 5543 |
// It no longer serves any purpose other than to support old test runners |
| 5544 |
// that still call only QUnit.load(), or that call both it and QUnit.start(). |
| 5545 |
if (!config.pageLoaded) { |
| 5546 |
// If the test runner used `autostart = false` and is calling QUnit.start() |
| 5547 |
// to tell is their resources are ready, but the browser isn't ready yet, |
| 5548 |
// then enable autostart now, and we'll let the tests really start after |
| 5549 |
// the browser's "load" event handler calls autostart(). |
| 5550 |
config.autostart = true; |
| 5551 |
|
| 5552 |
// If we're in Node or another non-browser environment, we start now as there |
| 5553 |
// won't be any "load" event. We return early either way since autostart |
| 5554 |
// is responsible for calling scheduleBegin (avoid "beginning" twice). |
| 5555 |
if (!document) { |
| 5556 |
QUnit.autostart(); |
| 5557 |
} |
| 5558 |
return; |
| 5559 |
} |
| 5560 |
scheduleBegin(); |
| 5561 |
}, |
| 5562 |
onUnhandledRejection: function onUnhandledRejection(reason) { |
| 5563 |
Logger.warn('QUnit.onUnhandledRejection is deprecated and will be removed in QUnit 3.0.' + ' Please use QUnit.onUncaughtException instead.'); |
| 5564 |
onUncaughtException(reason); |
| 5565 |
}, |
| 5566 |
extend: function extend$1() { |
| 5567 |
Logger.warn('QUnit.extend is deprecated and will be removed in QUnit 3.0.' + ' Please use Object.assign instead.'); |
| 5568 |
|
| 5569 |
// delegate to utility implementation, which does not warn and can be used elsewhere internally |
| 5570 |
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
| 5571 |
args[_key] = arguments[_key]; |
| 5572 |
} |
| 5573 |
return extend.apply(this, args); |
| 5574 |
}, |
| 5575 |
load: function load() { |
| 5576 |
Logger.warn('QUnit.load is deprecated and will be removed in QUnit 3.0.' + ' https://qunitjs.com/api/QUnit/load/'); |
| 5577 |
QUnit.autostart(); |
| 5578 |
}, |
| 5579 |
/** |
| 5580 |
* @internal |
| 5581 |
*/ |
| 5582 |
autostart: function autostart() { |
| 5583 |
config.pageLoaded = true; |
| 5584 |
|
| 5585 |
// Initialize the configuration options |
| 5586 |
// TODO: Move this to config.js in QUnit 3. |
| 5587 |
extend(config, { |
| 5588 |
started: 0, |
| 5589 |
updateRate: 1000, |
| 5590 |
autostart: true, |
| 5591 |
filter: '' |
| 5592 |
}, true); |
| 5593 |
if (!runStarted) { |
| 5594 |
config.blocking = false; |
| 5595 |
if (config.autostart) { |
| 5596 |
scheduleBegin(); |
| 5597 |
} |
| 5598 |
} |
| 5599 |
}, |
| 5600 |
stack: function stack(offset) { |
| 5601 |
offset = (offset || 0) + 2; |
| 5602 |
// Support Safari: Use temp variable to avoid TCO for consistent cross-browser result |
| 5603 |
// https://bugs.webkit.org/show_bug.cgi?id=276187 |
| 5604 |
var source = sourceFromStacktrace(offset); |
| 5605 |
return source; |
| 5606 |
} |
| 5607 |
}); |
| 5608 |
registerLoggingCallbacks(QUnit); |
| 5609 |
function scheduleBegin() { |
| 5610 |
runStarted = true; |
| 5611 |
|
| 5612 |
// Add a slight delay to allow definition of more modules and tests. |
| 5613 |
if (setTimeout$1) { |
| 5614 |
setTimeout$1(function () { |
| 5615 |
begin(); |
| 5616 |
}); |
| 5617 |
} else { |
| 5618 |
begin(); |
| 5619 |
} |
| 5620 |
} |
| 5621 |
function unblockAndAdvanceQueue() { |
| 5622 |
config.blocking = false; |
| 5623 |
config.pq.advance(); |
| 5624 |
} |
| 5625 |
function begin() { |
| 5626 |
if (config.started) { |
| 5627 |
unblockAndAdvanceQueue(); |
| 5628 |
return; |
| 5629 |
} |
| 5630 |
|
| 5631 |
// QUnit.config.reporters is considered writable between qunit.js and QUnit.start(). |
| 5632 |
// Now that QUnit.start() has been called, it is time to decide which built-in reporters |
| 5633 |
// to load. |
| 5634 |
if (config.reporters.console) { |
| 5635 |
reporters.console.init(QUnit); |
| 5636 |
} |
| 5637 |
if (config.reporters.tap) { |
| 5638 |
reporters.tap.init(QUnit); |
| 5639 |
} |
| 5640 |
|
| 5641 |
// The test run hasn't officially begun yet |
| 5642 |
// Record the time of the test run's beginning |
| 5643 |
config.started = performance.now(); |
| 5644 |
|
| 5645 |
// Delete the loose unnamed module if unused. |
| 5646 |
if (config.modules[0].name === '' && config.modules[0].tests.length === 0) { |
| 5647 |
config.modules.shift(); |
| 5648 |
} |
| 5649 |
var modulesLog = []; |
| 5650 |
for (var i = 0; i < config.modules.length; i++) { |
| 5651 |
// Don't expose the unnamed global test module to plugins. |
| 5652 |
if (config.modules[i].name !== '') { |
| 5653 |
modulesLog.push({ |
| 5654 |
name: config.modules[i].name, |
| 5655 |
moduleId: config.modules[i].moduleId, |
| 5656 |
// Added in QUnit 1.16.0 for internal use by html-reporter, |
| 5657 |
// but no longer used since QUnit 2.7.0. |
| 5658 |
// @deprecated Kept unofficially to be removed in QUnit 3.0. |
| 5659 |
tests: config.modules[i].tests |
| 5660 |
}); |
| 5661 |
} |
| 5662 |
} |
| 5663 |
|
| 5664 |
// The test run is officially beginning now |
| 5665 |
emit('runStart', runSuite.start(true)); |
| 5666 |
runLoggingCallbacks('begin', { |
| 5667 |
totalTests: Test.count, |
| 5668 |
modules: modulesLog |
| 5669 |
}).then(unblockAndAdvanceQueue); |
| 5670 |
} |
| 5671 |
exportQUnit(QUnit); |
| 5672 |
|
| 5673 |
(function () { |
| 5674 |
if (!window$1 || !document) { |
| 5675 |
return; |
| 5676 |
} |
| 5677 |
var config = QUnit.config; |
| 5678 |
var hasOwn = Object.prototype.hasOwnProperty; |
| 5679 |
|
| 5680 |
// Stores fixture HTML for resetting later |
| 5681 |
function storeFixture() { |
| 5682 |
// Avoid overwriting user-defined values |
| 5683 |
// TODO: Change to negative null/undefined check once declared in /src/config.js |
| 5684 |
if (hasOwn.call(config, 'fixture')) { |
| 5685 |
return; |
| 5686 |
} |
| 5687 |
var fixture = document.getElementById('qunit-fixture'); |
| 5688 |
if (fixture) { |
| 5689 |
config.fixture = fixture.cloneNode(true); |
| 5690 |
} |
| 5691 |
} |
| 5692 |
QUnit.begin(storeFixture); |
| 5693 |
|
| 5694 |
// Resets the fixture DOM element if available. |
| 5695 |
function resetFixture() { |
| 5696 |
if (config.fixture == null) { |
| 5697 |
return; |
| 5698 |
} |
| 5699 |
var fixture = document.getElementById('qunit-fixture'); |
| 5700 |
var resetFixtureType = _typeof(config.fixture); |
| 5701 |
if (resetFixtureType === 'string') { |
| 5702 |
// support user defined values for `config.fixture` |
| 5703 |
var newFixture = document.createElement('div'); |
| 5704 |
newFixture.setAttribute('id', 'qunit-fixture'); |
| 5705 |
newFixture.innerHTML = config.fixture; |
| 5706 |
fixture.parentNode.replaceChild(newFixture, fixture); |
| 5707 |
} else { |
| 5708 |
var clonedFixture = config.fixture.cloneNode(true); |
| 5709 |
fixture.parentNode.replaceChild(clonedFixture, fixture); |
| 5710 |
} |
| 5711 |
} |
| 5712 |
QUnit.testStart(resetFixture); |
| 5713 |
})(); |
| 5714 |
|
| 5715 |
(function () { |
| 5716 |
// Only interact with URLs via window.location |
| 5717 |
var location = typeof window$1 !== 'undefined' && window$1.location; |
| 5718 |
if (!location) { |
| 5719 |
return; |
| 5720 |
} |
| 5721 |
var urlParams = getUrlParams(); |
| 5722 |
|
| 5723 |
// TODO: Move to /src/core/ in QUnit 3 |
| 5724 |
// TODO: Document this as public API (read-only) |
| 5725 |
QUnit.urlParams = urlParams; |
| 5726 |
|
| 5727 |
// TODO: Move to /src/core/config.js in QUnit 3, |
| 5728 |
// in accordance with /docs/api/config.index.md#order |
| 5729 |
QUnit.config.filter = urlParams.filter; |
| 5730 |
// NOTE: Based on readFlatPreconfigNumber from QUnit 3. |
| 5731 |
if (/^[0-9]+$/.test(urlParams.maxDepth)) { |
| 5732 |
QUnit.config.maxDepth = QUnit.dump.maxDepth = +urlParams.maxDepth; |
| 5733 |
} |
| 5734 |
QUnit.config.module = urlParams.module; |
| 5735 |
QUnit.config.moduleId = [].concat(urlParams.moduleId || []); |
| 5736 |
QUnit.config.testId = [].concat(urlParams.testId || []); |
| 5737 |
|
| 5738 |
// Test order randomization |
| 5739 |
// Generate a random seed if `?seed` is specified without a value (boolean true), |
| 5740 |
// or when set to the string "true". |
| 5741 |
if (urlParams.seed === 'true' || urlParams.seed === true) { |
| 5742 |
// NOTE: This duplicates logic from /src/core/config.js. Consolidated in QUnit 3. |
| 5743 |
QUnit.config.seed = (Math.random().toString(36) + '0000000000').slice(2, 12); |
| 5744 |
} else if (urlParams.seed) { |
| 5745 |
QUnit.config.seed = urlParams.seed; |
| 5746 |
} |
| 5747 |
|
| 5748 |
// Add URL-parameter-mapped config values with UI form rendering data |
| 5749 |
QUnit.config.urlConfig.push({ |
| 5750 |
id: 'hidepassed', |
| 5751 |
label: 'Hide passed tests', |
| 5752 |
tooltip: 'Only show tests and assertions that fail. Stored as query-strings.' |
| 5753 |
}, { |
| 5754 |
id: 'noglobals', |
| 5755 |
label: 'Check for Globals', |
| 5756 |
tooltip: 'Enabling this will test if any test introduces new properties on the ' + 'global object (`window` in Browsers). Stored as query-strings.' |
| 5757 |
}, { |
| 5758 |
id: 'notrycatch', |
| 5759 |
label: 'No try-catch', |
| 5760 |
tooltip: 'Enabling this will run tests outside of a try-catch block. Makes debugging ' + 'exceptions in IE reasonable. Stored as query-strings.' |
| 5761 |
}); |
| 5762 |
QUnit.begin(function () { |
| 5763 |
var urlConfig = QUnit.config.urlConfig; |
| 5764 |
for (var i = 0; i < urlConfig.length; i++) { |
| 5765 |
// Options can be either strings or objects with nonempty "id" properties |
| 5766 |
var option = QUnit.config.urlConfig[i]; |
| 5767 |
if (typeof option !== 'string') { |
| 5768 |
option = option.id; |
| 5769 |
} |
| 5770 |
if (QUnit.config[option] === undefined) { |
| 5771 |
QUnit.config[option] = urlParams[option]; |
| 5772 |
} |
| 5773 |
} |
| 5774 |
}); |
| 5775 |
function getUrlParams() { |
| 5776 |
var urlParams = Object.create(null); |
| 5777 |
var params = location.search.slice(1).split('&'); |
| 5778 |
var length = params.length; |
| 5779 |
for (var i = 0; i < length; i++) { |
| 5780 |
if (params[i]) { |
| 5781 |
var param = params[i].split('='); |
| 5782 |
var name = decodeQueryParam(param[0]); |
| 5783 |
|
| 5784 |
// Allow just a key to turn on a flag, e.g., test.html?noglobals |
| 5785 |
var value = param.length === 1 || decodeQueryParam(param.slice(1).join('=')); |
| 5786 |
if (name in urlParams) { |
| 5787 |
urlParams[name] = [].concat(urlParams[name], value); |
| 5788 |
} else { |
| 5789 |
urlParams[name] = value; |
| 5790 |
} |
| 5791 |
} |
| 5792 |
} |
| 5793 |
return urlParams; |
| 5794 |
} |
| 5795 |
function decodeQueryParam(param) { |
| 5796 |
return decodeURIComponent(param.replace(/\+/g, '%20')); |
| 5797 |
} |
| 5798 |
})(); |
| 5799 |
|
| 5800 |
var fuzzysort$1 = {exports: {}}; |
| 5801 |
|
| 5802 |
(function (module) { |
| 5803 |
(function (root, UMD) { |
| 5804 |
if (module.exports) module.exports = UMD();else root.fuzzysort = UMD(); |
| 5805 |
})(commonjsGlobal, function UMD() { |
| 5806 |
function fuzzysortNew(instanceOptions) { |
| 5807 |
var fuzzysort = { |
| 5808 |
single: function single(search, target, options) { |
| 5809 |
if (search == 'farzher') return { |
| 5810 |
target: "farzher was here (^-^*)/", |
| 5811 |
score: 0, |
| 5812 |
indexes: [0, 1, 2, 3, 4, 5, 6] |
| 5813 |
}; |
| 5814 |
if (!search) return null; |
| 5815 |
if (!isObj(search)) search = fuzzysort.getPreparedSearch(search); |
| 5816 |
if (!target) return null; |
| 5817 |
if (!isObj(target)) target = fuzzysort.getPrepared(target); |
| 5818 |
var allowTypo = options && options.allowTypo !== undefined ? options.allowTypo : instanceOptions && instanceOptions.allowTypo !== undefined ? instanceOptions.allowTypo : true; |
| 5819 |
var algorithm = allowTypo ? fuzzysort.algorithm : fuzzysort.algorithmNoTypo; |
| 5820 |
return algorithm(search, target, search[0]); |
| 5821 |
}, |
| 5822 |
go: function go(search, targets, options) { |
| 5823 |
if (search == 'farzher') return [{ |
| 5824 |
target: "farzher was here (^-^*)/", |
| 5825 |
score: 0, |
| 5826 |
indexes: [0, 1, 2, 3, 4, 5, 6], |
| 5827 |
obj: targets ? targets[0] : null |
| 5828 |
}]; |
| 5829 |
if (!search) return noResults; |
| 5830 |
search = fuzzysort.prepareSearch(search); |
| 5831 |
var searchLowerCode = search[0]; |
| 5832 |
var threshold = options && options.threshold || instanceOptions && instanceOptions.threshold || -9007199254740991; |
| 5833 |
var limit = options && options.limit || instanceOptions && instanceOptions.limit || 9007199254740991; |
| 5834 |
var allowTypo = options && options.allowTypo !== undefined ? options.allowTypo : instanceOptions && instanceOptions.allowTypo !== undefined ? instanceOptions.allowTypo : true; |
| 5835 |
var algorithm = allowTypo ? fuzzysort.algorithm : fuzzysort.algorithmNoTypo; |
| 5836 |
var resultsLen = 0; |
| 5837 |
var limitedCount = 0; |
| 5838 |
var targetsLen = targets.length; |
| 5839 |
|
| 5840 |
// This code is copy/pasted 3 times for performance reasons [options.keys, options.key, no keys] |
| 5841 |
|
| 5842 |
// options.keys |
| 5843 |
if (options && options.keys) { |
| 5844 |
var scoreFn = options.scoreFn || defaultScoreFn; |
| 5845 |
var keys = options.keys; |
| 5846 |
var keysLen = keys.length; |
| 5847 |
for (var i = targetsLen - 1; i >= 0; --i) { |
| 5848 |
var obj = targets[i]; |
| 5849 |
var objResults = new Array(keysLen); |
| 5850 |
for (var keyI = keysLen - 1; keyI >= 0; --keyI) { |
| 5851 |
var key = keys[keyI]; |
| 5852 |
var target = getValue(obj, key); |
| 5853 |
if (!target) { |
| 5854 |
objResults[keyI] = null; |
| 5855 |
continue; |
| 5856 |
} |
| 5857 |
if (!isObj(target)) target = fuzzysort.getPrepared(target); |
| 5858 |
objResults[keyI] = algorithm(search, target, searchLowerCode); |
| 5859 |
} |
| 5860 |
objResults.obj = obj; // before scoreFn so scoreFn can use it |
| 5861 |
var score = scoreFn(objResults); |
| 5862 |
if (score === null) continue; |
| 5863 |
if (score < threshold) continue; |
| 5864 |
objResults.score = score; |
| 5865 |
if (resultsLen < limit) { |
| 5866 |
q.add(objResults); |
| 5867 |
++resultsLen; |
| 5868 |
} else { |
| 5869 |
++limitedCount; |
| 5870 |
if (score > q.peek().score) q.replaceTop(objResults); |
| 5871 |
} |
| 5872 |
} |
| 5873 |
|
| 5874 |
// options.key |
| 5875 |
} else if (options && options.key) { |
| 5876 |
var key = options.key; |
| 5877 |
for (var i = targetsLen - 1; i >= 0; --i) { |
| 5878 |
var obj = targets[i]; |
| 5879 |
var target = getValue(obj, key); |
| 5880 |
if (!target) continue; |
| 5881 |
if (!isObj(target)) target = fuzzysort.getPrepared(target); |
| 5882 |
var result = algorithm(search, target, searchLowerCode); |
| 5883 |
if (result === null) continue; |
| 5884 |
if (result.score < threshold) continue; |
| 5885 |
|
| 5886 |
// have to clone result so duplicate targets from different obj can each reference the correct obj |
| 5887 |
result = { |
| 5888 |
target: result.target, |
| 5889 |
_targetLowerCodes: null, |
| 5890 |
_nextBeginningIndexes: null, |
| 5891 |
score: result.score, |
| 5892 |
indexes: result.indexes, |
| 5893 |
obj: obj |
| 5894 |
}; // hidden |
| 5895 |
|
| 5896 |
if (resultsLen < limit) { |
| 5897 |
q.add(result); |
| 5898 |
++resultsLen; |
| 5899 |
} else { |
| 5900 |
++limitedCount; |
| 5901 |
if (result.score > q.peek().score) q.replaceTop(result); |
| 5902 |
} |
| 5903 |
} |
| 5904 |
|
| 5905 |
// no keys |
| 5906 |
} else { |
| 5907 |
for (var i = targetsLen - 1; i >= 0; --i) { |
| 5908 |
var target = targets[i]; |
| 5909 |
if (!target) continue; |
| 5910 |
if (!isObj(target)) target = fuzzysort.getPrepared(target); |
| 5911 |
var result = algorithm(search, target, searchLowerCode); |
| 5912 |
if (result === null) continue; |
| 5913 |
if (result.score < threshold) continue; |
| 5914 |
if (resultsLen < limit) { |
| 5915 |
q.add(result); |
| 5916 |
++resultsLen; |
| 5917 |
} else { |
| 5918 |
++limitedCount; |
| 5919 |
if (result.score > q.peek().score) q.replaceTop(result); |
| 5920 |
} |
| 5921 |
} |
| 5922 |
} |
| 5923 |
if (resultsLen === 0) return noResults; |
| 5924 |
var results = new Array(resultsLen); |
| 5925 |
for (var i = resultsLen - 1; i >= 0; --i) results[i] = q.poll(); |
| 5926 |
results.total = resultsLen + limitedCount; |
| 5927 |
return results; |
| 5928 |
}, |
| 5929 |
goAsync: function goAsync(search, targets, options) { |
| 5930 |
var canceled = false; |
| 5931 |
var p = new Promise(function (resolve, reject) { |
| 5932 |
if (search == 'farzher') return resolve([{ |
| 5933 |
target: "farzher was here (^-^*)/", |
| 5934 |
score: 0, |
| 5935 |
indexes: [0, 1, 2, 3, 4, 5, 6], |
| 5936 |
obj: targets ? targets[0] : null |
| 5937 |
}]); |
| 5938 |
if (!search) return resolve(noResults); |
| 5939 |
search = fuzzysort.prepareSearch(search); |
| 5940 |
var searchLowerCode = search[0]; |
| 5941 |
var q = fastpriorityqueue(); |
| 5942 |
var iCurrent = targets.length - 1; |
| 5943 |
var threshold = options && options.threshold || instanceOptions && instanceOptions.threshold || -9007199254740991; |
| 5944 |
var limit = options && options.limit || instanceOptions && instanceOptions.limit || 9007199254740991; |
| 5945 |
var allowTypo = options && options.allowTypo !== undefined ? options.allowTypo : instanceOptions && instanceOptions.allowTypo !== undefined ? instanceOptions.allowTypo : true; |
| 5946 |
var algorithm = allowTypo ? fuzzysort.algorithm : fuzzysort.algorithmNoTypo; |
| 5947 |
var resultsLen = 0; |
| 5948 |
var limitedCount = 0; |
| 5949 |
function step() { |
| 5950 |
if (canceled) return reject('canceled'); |
| 5951 |
var startMs = Date.now(); |
| 5952 |
|
| 5953 |
// This code is copy/pasted 3 times for performance reasons [options.keys, options.key, no keys] |
| 5954 |
|
| 5955 |
// options.keys |
| 5956 |
if (options && options.keys) { |
| 5957 |
var scoreFn = options.scoreFn || defaultScoreFn; |
| 5958 |
var keys = options.keys; |
| 5959 |
var keysLen = keys.length; |
| 5960 |
for (; iCurrent >= 0; --iCurrent) { |
| 5961 |
if (iCurrent % 1000 /*itemsPerCheck*/ === 0) { |
| 5962 |
if (Date.now() - startMs >= 10 /*asyncInterval*/) { |
| 5963 |
isNode ? setImmediate(step) : setTimeout(step); |
| 5964 |
return; |
| 5965 |
} |
| 5966 |
} |
| 5967 |
var obj = targets[iCurrent]; |
| 5968 |
var objResults = new Array(keysLen); |
| 5969 |
for (var keyI = keysLen - 1; keyI >= 0; --keyI) { |
| 5970 |
var key = keys[keyI]; |
| 5971 |
var target = getValue(obj, key); |
| 5972 |
if (!target) { |
| 5973 |
objResults[keyI] = null; |
| 5974 |
continue; |
| 5975 |
} |
| 5976 |
if (!isObj(target)) target = fuzzysort.getPrepared(target); |
| 5977 |
objResults[keyI] = algorithm(search, target, searchLowerCode); |
| 5978 |
} |
| 5979 |
objResults.obj = obj; // before scoreFn so scoreFn can use it |
| 5980 |
var score = scoreFn(objResults); |
| 5981 |
if (score === null) continue; |
| 5982 |
if (score < threshold) continue; |
| 5983 |
objResults.score = score; |
| 5984 |
if (resultsLen < limit) { |
| 5985 |
q.add(objResults); |
| 5986 |
++resultsLen; |
| 5987 |
} else { |
| 5988 |
++limitedCount; |
| 5989 |
if (score > q.peek().score) q.replaceTop(objResults); |
| 5990 |
} |
| 5991 |
} |
| 5992 |
|
| 5993 |
// options.key |
| 5994 |
} else if (options && options.key) { |
| 5995 |
var key = options.key; |
| 5996 |
for (; iCurrent >= 0; --iCurrent) { |
| 5997 |
if (iCurrent % 1000 /*itemsPerCheck*/ === 0) { |
| 5998 |
if (Date.now() - startMs >= 10 /*asyncInterval*/) { |
| 5999 |
isNode ? setImmediate(step) : setTimeout(step); |
| 6000 |
return; |
| 6001 |
} |
| 6002 |
} |
| 6003 |
var obj = targets[iCurrent]; |
| 6004 |
var target = getValue(obj, key); |
| 6005 |
if (!target) continue; |
| 6006 |
if (!isObj(target)) target = fuzzysort.getPrepared(target); |
| 6007 |
var result = algorithm(search, target, searchLowerCode); |
| 6008 |
if (result === null) continue; |
| 6009 |
if (result.score < threshold) continue; |
| 6010 |
|
| 6011 |
// have to clone result so duplicate targets from different obj can each reference the correct obj |
| 6012 |
result = { |
| 6013 |
target: result.target, |
| 6014 |
_targetLowerCodes: null, |
| 6015 |
_nextBeginningIndexes: null, |
| 6016 |
score: result.score, |
| 6017 |
indexes: result.indexes, |
| 6018 |
obj: obj |
| 6019 |
}; // hidden |
| 6020 |
|
| 6021 |
if (resultsLen < limit) { |
| 6022 |
q.add(result); |
| 6023 |
++resultsLen; |
| 6024 |
} else { |
| 6025 |
++limitedCount; |
| 6026 |
if (result.score > q.peek().score) q.replaceTop(result); |
| 6027 |
} |
| 6028 |
} |
| 6029 |
|
| 6030 |
// no keys |
| 6031 |
} else { |
| 6032 |
for (; iCurrent >= 0; --iCurrent) { |
| 6033 |
if (iCurrent % 1000 /*itemsPerCheck*/ === 0) { |
| 6034 |
if (Date.now() - startMs >= 10 /*asyncInterval*/) { |
| 6035 |
isNode ? setImmediate(step) : setTimeout(step); |
| 6036 |
return; |
| 6037 |
} |
| 6038 |
} |
| 6039 |
var target = targets[iCurrent]; |
| 6040 |
if (!target) continue; |
| 6041 |
if (!isObj(target)) target = fuzzysort.getPrepared(target); |
| 6042 |
var result = algorithm(search, target, searchLowerCode); |
| 6043 |
if (result === null) continue; |
| 6044 |
if (result.score < threshold) continue; |
| 6045 |
if (resultsLen < limit) { |
| 6046 |
q.add(result); |
| 6047 |
++resultsLen; |
| 6048 |
} else { |
| 6049 |
++limitedCount; |
| 6050 |
if (result.score > q.peek().score) q.replaceTop(result); |
| 6051 |
} |
| 6052 |
} |
| 6053 |
} |
| 6054 |
if (resultsLen === 0) return resolve(noResults); |
| 6055 |
var results = new Array(resultsLen); |
| 6056 |
for (var i = resultsLen - 1; i >= 0; --i) results[i] = q.poll(); |
| 6057 |
results.total = resultsLen + limitedCount; |
| 6058 |
resolve(results); |
| 6059 |
} |
| 6060 |
isNode ? setImmediate(step) : step(); //setTimeout here is too slow |
| 6061 |
}); |
| 6062 |
p.cancel = function () { |
| 6063 |
canceled = true; |
| 6064 |
}; |
| 6065 |
return p; |
| 6066 |
}, |
| 6067 |
highlight: function highlight(result, hOpen, hClose) { |
| 6068 |
if (typeof hOpen == 'function') return fuzzysort.highlightCallback(result, hOpen); |
| 6069 |
if (result === null) return null; |
| 6070 |
if (hOpen === undefined) hOpen = '<b>'; |
| 6071 |
if (hClose === undefined) hClose = '</b>'; |
| 6072 |
var highlighted = ''; |
| 6073 |
var matchesIndex = 0; |
| 6074 |
var opened = false; |
| 6075 |
var target = result.target; |
| 6076 |
var targetLen = target.length; |
| 6077 |
var matchesBest = result.indexes; |
| 6078 |
for (var i = 0; i < targetLen; ++i) { |
| 6079 |
var char = target[i]; |
| 6080 |
if (matchesBest[matchesIndex] === i) { |
| 6081 |
++matchesIndex; |
| 6082 |
if (!opened) { |
| 6083 |
opened = true; |
| 6084 |
highlighted += hOpen; |
| 6085 |
} |
| 6086 |
if (matchesIndex === matchesBest.length) { |
| 6087 |
highlighted += char + hClose + target.substr(i + 1); |
| 6088 |
break; |
| 6089 |
} |
| 6090 |
} else { |
| 6091 |
if (opened) { |
| 6092 |
opened = false; |
| 6093 |
highlighted += hClose; |
| 6094 |
} |
| 6095 |
} |
| 6096 |
highlighted += char; |
| 6097 |
} |
| 6098 |
return highlighted; |
| 6099 |
}, |
| 6100 |
highlightCallback: function highlightCallback(result, cb) { |
| 6101 |
if (result === null) return null; |
| 6102 |
var target = result.target; |
| 6103 |
var targetLen = target.length; |
| 6104 |
var indexes = result.indexes; |
| 6105 |
var highlighted = ''; |
| 6106 |
var matchI = 0; |
| 6107 |
var indexesI = 0; |
| 6108 |
var opened = false; |
| 6109 |
var result = []; |
| 6110 |
for (var i = 0; i < targetLen; ++i) { |
| 6111 |
var char = target[i]; |
| 6112 |
if (indexes[indexesI] === i) { |
| 6113 |
++indexesI; |
| 6114 |
if (!opened) { |
| 6115 |
opened = true; |
| 6116 |
result.push(highlighted); |
| 6117 |
highlighted = ''; |
| 6118 |
} |
| 6119 |
if (indexesI === indexes.length) { |
| 6120 |
highlighted += char; |
| 6121 |
result.push(cb(highlighted, matchI++)); |
| 6122 |
highlighted = ''; |
| 6123 |
result.push(target.substr(i + 1)); |
| 6124 |
break; |
| 6125 |
} |
| 6126 |
} else { |
| 6127 |
if (opened) { |
| 6128 |
opened = false; |
| 6129 |
result.push(cb(highlighted, matchI++)); |
| 6130 |
highlighted = ''; |
| 6131 |
} |
| 6132 |
} |
| 6133 |
highlighted += char; |
| 6134 |
} |
| 6135 |
return result; |
| 6136 |
}, |
| 6137 |
prepare: function prepare(target) { |
| 6138 |
if (!target) return { |
| 6139 |
target: '', |
| 6140 |
_targetLowerCodes: [0 /*this 0 doesn't make sense. here because an empty array causes the algorithm to deoptimize and run 50% slower!*/], |
| 6141 |
_nextBeginningIndexes: null, |
| 6142 |
score: null, |
| 6143 |
indexes: null, |
| 6144 |
obj: null |
| 6145 |
}; // hidden |
| 6146 |
return { |
| 6147 |
target: target, |
| 6148 |
_targetLowerCodes: fuzzysort.prepareLowerCodes(target), |
| 6149 |
_nextBeginningIndexes: null, |
| 6150 |
score: null, |
| 6151 |
indexes: null, |
| 6152 |
obj: null |
| 6153 |
}; // hidden |
| 6154 |
}, |
| 6155 |
prepareSlow: function prepareSlow(target) { |
| 6156 |
if (!target) return { |
| 6157 |
target: '', |
| 6158 |
_targetLowerCodes: [0 /*this 0 doesn't make sense. here because an empty array causes the algorithm to deoptimize and run 50% slower!*/], |
| 6159 |
_nextBeginningIndexes: null, |
| 6160 |
score: null, |
| 6161 |
indexes: null, |
| 6162 |
obj: null |
| 6163 |
}; // hidden |
| 6164 |
return { |
| 6165 |
target: target, |
| 6166 |
_targetLowerCodes: fuzzysort.prepareLowerCodes(target), |
| 6167 |
_nextBeginningIndexes: fuzzysort.prepareNextBeginningIndexes(target), |
| 6168 |
score: null, |
| 6169 |
indexes: null, |
| 6170 |
obj: null |
| 6171 |
}; // hidden |
| 6172 |
}, |
| 6173 |
prepareSearch: function prepareSearch(search) { |
| 6174 |
if (!search) search = ''; |
| 6175 |
return fuzzysort.prepareLowerCodes(search); |
| 6176 |
}, |
| 6177 |
// Below this point is only internal code |
| 6178 |
// Below this point is only internal code |
| 6179 |
// Below this point is only internal code |
| 6180 |
// Below this point is only internal code |
| 6181 |
|
| 6182 |
getPrepared: function getPrepared(target) { |
| 6183 |
if (target.length > 999) return fuzzysort.prepare(target); // don't cache huge targets |
| 6184 |
var targetPrepared = preparedCache.get(target); |
| 6185 |
if (targetPrepared !== undefined) return targetPrepared; |
| 6186 |
targetPrepared = fuzzysort.prepare(target); |
| 6187 |
preparedCache.set(target, targetPrepared); |
| 6188 |
return targetPrepared; |
| 6189 |
}, |
| 6190 |
getPreparedSearch: function getPreparedSearch(search) { |
| 6191 |
if (search.length > 999) return fuzzysort.prepareSearch(search); // don't cache huge searches |
| 6192 |
var searchPrepared = preparedSearchCache.get(search); |
| 6193 |
if (searchPrepared !== undefined) return searchPrepared; |
| 6194 |
searchPrepared = fuzzysort.prepareSearch(search); |
| 6195 |
preparedSearchCache.set(search, searchPrepared); |
| 6196 |
return searchPrepared; |
| 6197 |
}, |
| 6198 |
algorithm: function algorithm(searchLowerCodes, prepared, searchLowerCode) { |
| 6199 |
var targetLowerCodes = prepared._targetLowerCodes; |
| 6200 |
var searchLen = searchLowerCodes.length; |
| 6201 |
var targetLen = targetLowerCodes.length; |
| 6202 |
var searchI = 0; // where we at |
| 6203 |
var targetI = 0; // where you at |
| 6204 |
var typoSimpleI = 0; |
| 6205 |
var matchesSimpleLen = 0; |
| 6206 |
|
| 6207 |
// very basic fuzzy match; to remove non-matching targets ASAP! |
| 6208 |
// walk through target. find sequential matches. |
| 6209 |
// if all chars aren't found then exit |
| 6210 |
for (;;) { |
| 6211 |
var isMatch = searchLowerCode === targetLowerCodes[targetI]; |
| 6212 |
if (isMatch) { |
| 6213 |
matchesSimple[matchesSimpleLen++] = targetI; |
| 6214 |
++searchI; |
| 6215 |
if (searchI === searchLen) break; |
| 6216 |
searchLowerCode = searchLowerCodes[typoSimpleI === 0 ? searchI : typoSimpleI === searchI ? searchI + 1 : typoSimpleI === searchI - 1 ? searchI - 1 : searchI]; |
| 6217 |
} |
| 6218 |
++targetI; |
| 6219 |
if (targetI >= targetLen) { |
| 6220 |
// Failed to find searchI |
| 6221 |
// Check for typo or exit |
| 6222 |
// we go as far as possible before trying to transpose |
| 6223 |
// then we transpose backwards until we reach the beginning |
| 6224 |
for (;;) { |
| 6225 |
if (searchI <= 1) return null; // not allowed to transpose first char |
| 6226 |
if (typoSimpleI === 0) { |
| 6227 |
// we haven't tried to transpose yet |
| 6228 |
--searchI; |
| 6229 |
var searchLowerCodeNew = searchLowerCodes[searchI]; |
| 6230 |
if (searchLowerCode === searchLowerCodeNew) continue; // doesn't make sense to transpose a repeat char |
| 6231 |
typoSimpleI = searchI; |
| 6232 |
} else { |
| 6233 |
if (typoSimpleI === 1) return null; // reached the end of the line for transposing |
| 6234 |
--typoSimpleI; |
| 6235 |
searchI = typoSimpleI; |
| 6236 |
searchLowerCode = searchLowerCodes[searchI + 1]; |
| 6237 |
var searchLowerCodeNew = searchLowerCodes[searchI]; |
| 6238 |
if (searchLowerCode === searchLowerCodeNew) continue; // doesn't make sense to transpose a repeat char |
| 6239 |
} |
| 6240 |
matchesSimpleLen = searchI; |
| 6241 |
targetI = matchesSimple[matchesSimpleLen - 1] + 1; |
| 6242 |
break; |
| 6243 |
} |
| 6244 |
} |
| 6245 |
} |
| 6246 |
var searchI = 0; |
| 6247 |
var typoStrictI = 0; |
| 6248 |
var successStrict = false; |
| 6249 |
var matchesStrictLen = 0; |
| 6250 |
var nextBeginningIndexes = prepared._nextBeginningIndexes; |
| 6251 |
if (nextBeginningIndexes === null) nextBeginningIndexes = prepared._nextBeginningIndexes = fuzzysort.prepareNextBeginningIndexes(prepared.target); |
| 6252 |
var firstPossibleI = targetI = matchesSimple[0] === 0 ? 0 : nextBeginningIndexes[matchesSimple[0] - 1]; |
| 6253 |
|
| 6254 |
// Our target string successfully matched all characters in sequence! |
| 6255 |
// Let's try a more advanced and strict test to improve the score |
| 6256 |
// only count it as a match if it's consecutive or a beginning character! |
| 6257 |
if (targetI !== targetLen) for (;;) { |
| 6258 |
if (targetI >= targetLen) { |
| 6259 |
// We failed to find a good spot for this search char, go back to the previous search char and force it forward |
| 6260 |
if (searchI <= 0) { |
| 6261 |
// We failed to push chars forward for a better match |
| 6262 |
// transpose, starting from the beginning |
| 6263 |
++typoStrictI; |
| 6264 |
if (typoStrictI > searchLen - 2) break; |
| 6265 |
if (searchLowerCodes[typoStrictI] === searchLowerCodes[typoStrictI + 1]) continue; // doesn't make sense to transpose a repeat char |
| 6266 |
targetI = firstPossibleI; |
| 6267 |
continue; |
| 6268 |
} |
| 6269 |
--searchI; |
| 6270 |
var lastMatch = matchesStrict[--matchesStrictLen]; |
| 6271 |
targetI = nextBeginningIndexes[lastMatch]; |
| 6272 |
} else { |
| 6273 |
var isMatch = searchLowerCodes[typoStrictI === 0 ? searchI : typoStrictI === searchI ? searchI + 1 : typoStrictI === searchI - 1 ? searchI - 1 : searchI] === targetLowerCodes[targetI]; |
| 6274 |
if (isMatch) { |
| 6275 |
matchesStrict[matchesStrictLen++] = targetI; |
| 6276 |
++searchI; |
| 6277 |
if (searchI === searchLen) { |
| 6278 |
successStrict = true; |
| 6279 |
break; |
| 6280 |
} |
| 6281 |
++targetI; |
| 6282 |
} else { |
| 6283 |
targetI = nextBeginningIndexes[targetI]; |
| 6284 |
} |
| 6285 |
} |
| 6286 |
} |
| 6287 |
{ |
| 6288 |
// tally up the score & keep track of matches for highlighting later |
| 6289 |
if (successStrict) { |
| 6290 |
var matchesBest = matchesStrict; |
| 6291 |
var matchesBestLen = matchesStrictLen; |
| 6292 |
} else { |
| 6293 |
var matchesBest = matchesSimple; |
| 6294 |
var matchesBestLen = matchesSimpleLen; |
| 6295 |
} |
| 6296 |
var score = 0; |
| 6297 |
var lastTargetI = -1; |
| 6298 |
for (var i = 0; i < searchLen; ++i) { |
| 6299 |
var targetI = matchesBest[i]; |
| 6300 |
// score only goes down if they're not consecutive |
| 6301 |
if (lastTargetI !== targetI - 1) score -= targetI; |
| 6302 |
lastTargetI = targetI; |
| 6303 |
} |
| 6304 |
if (!successStrict) { |
| 6305 |
score *= 1000; |
| 6306 |
if (typoSimpleI !== 0) score += -20; /*typoPenalty*/ |
| 6307 |
} else { |
| 6308 |
if (typoStrictI !== 0) score += -20; /*typoPenalty*/ |
| 6309 |
} |
| 6310 |
score -= targetLen - searchLen; |
| 6311 |
prepared.score = score; |
| 6312 |
prepared.indexes = new Array(matchesBestLen); |
| 6313 |
for (var i = matchesBestLen - 1; i >= 0; --i) prepared.indexes[i] = matchesBest[i]; |
| 6314 |
return prepared; |
| 6315 |
} |
| 6316 |
}, |
| 6317 |
algorithmNoTypo: function algorithmNoTypo(searchLowerCodes, prepared, searchLowerCode) { |
| 6318 |
var targetLowerCodes = prepared._targetLowerCodes; |
| 6319 |
var searchLen = searchLowerCodes.length; |
| 6320 |
var targetLen = targetLowerCodes.length; |
| 6321 |
var searchI = 0; // where we at |
| 6322 |
var targetI = 0; // where you at |
| 6323 |
var matchesSimpleLen = 0; |
| 6324 |
|
| 6325 |
// very basic fuzzy match; to remove non-matching targets ASAP! |
| 6326 |
// walk through target. find sequential matches. |
| 6327 |
// if all chars aren't found then exit |
| 6328 |
for (;;) { |
| 6329 |
var isMatch = searchLowerCode === targetLowerCodes[targetI]; |
| 6330 |
if (isMatch) { |
| 6331 |
matchesSimple[matchesSimpleLen++] = targetI; |
| 6332 |
++searchI; |
| 6333 |
if (searchI === searchLen) break; |
| 6334 |
searchLowerCode = searchLowerCodes[searchI]; |
| 6335 |
} |
| 6336 |
++targetI; |
| 6337 |
if (targetI >= targetLen) return null; // Failed to find searchI |
| 6338 |
} |
| 6339 |
var searchI = 0; |
| 6340 |
var successStrict = false; |
| 6341 |
var matchesStrictLen = 0; |
| 6342 |
var nextBeginningIndexes = prepared._nextBeginningIndexes; |
| 6343 |
if (nextBeginningIndexes === null) nextBeginningIndexes = prepared._nextBeginningIndexes = fuzzysort.prepareNextBeginningIndexes(prepared.target); |
| 6344 |
targetI = matchesSimple[0] === 0 ? 0 : nextBeginningIndexes[matchesSimple[0] - 1]; |
| 6345 |
|
| 6346 |
// Our target string successfully matched all characters in sequence! |
| 6347 |
// Let's try a more advanced and strict test to improve the score |
| 6348 |
// only count it as a match if it's consecutive or a beginning character! |
| 6349 |
if (targetI !== targetLen) for (;;) { |
| 6350 |
if (targetI >= targetLen) { |
| 6351 |
// We failed to find a good spot for this search char, go back to the previous search char and force it forward |
| 6352 |
if (searchI <= 0) break; // We failed to push chars forward for a better match |
| 6353 |
|
| 6354 |
--searchI; |
| 6355 |
var lastMatch = matchesStrict[--matchesStrictLen]; |
| 6356 |
targetI = nextBeginningIndexes[lastMatch]; |
| 6357 |
} else { |
| 6358 |
var isMatch = searchLowerCodes[searchI] === targetLowerCodes[targetI]; |
| 6359 |
if (isMatch) { |
| 6360 |
matchesStrict[matchesStrictLen++] = targetI; |
| 6361 |
++searchI; |
| 6362 |
if (searchI === searchLen) { |
| 6363 |
successStrict = true; |
| 6364 |
break; |
| 6365 |
} |
| 6366 |
++targetI; |
| 6367 |
} else { |
| 6368 |
targetI = nextBeginningIndexes[targetI]; |
| 6369 |
} |
| 6370 |
} |
| 6371 |
} |
| 6372 |
{ |
| 6373 |
// tally up the score & keep track of matches for highlighting later |
| 6374 |
if (successStrict) { |
| 6375 |
var matchesBest = matchesStrict; |
| 6376 |
var matchesBestLen = matchesStrictLen; |
| 6377 |
} else { |
| 6378 |
var matchesBest = matchesSimple; |
| 6379 |
var matchesBestLen = matchesSimpleLen; |
| 6380 |
} |
| 6381 |
var score = 0; |
| 6382 |
var lastTargetI = -1; |
| 6383 |
for (var i = 0; i < searchLen; ++i) { |
| 6384 |
var targetI = matchesBest[i]; |
| 6385 |
// score only goes down if they're not consecutive |
| 6386 |
if (lastTargetI !== targetI - 1) score -= targetI; |
| 6387 |
lastTargetI = targetI; |
| 6388 |
} |
| 6389 |
if (!successStrict) score *= 1000; |
| 6390 |
score -= targetLen - searchLen; |
| 6391 |
prepared.score = score; |
| 6392 |
prepared.indexes = new Array(matchesBestLen); |
| 6393 |
for (var i = matchesBestLen - 1; i >= 0; --i) prepared.indexes[i] = matchesBest[i]; |
| 6394 |
return prepared; |
| 6395 |
} |
| 6396 |
}, |
| 6397 |
prepareLowerCodes: function prepareLowerCodes(str) { |
| 6398 |
var strLen = str.length; |
| 6399 |
var lowerCodes = []; // new Array(strLen) sparse array is too slow |
| 6400 |
var lower = str.toLowerCase(); |
| 6401 |
for (var i = 0; i < strLen; ++i) lowerCodes[i] = lower.charCodeAt(i); |
| 6402 |
return lowerCodes; |
| 6403 |
}, |
| 6404 |
prepareBeginningIndexes: function prepareBeginningIndexes(target) { |
| 6405 |
var targetLen = target.length; |
| 6406 |
var beginningIndexes = []; |
| 6407 |
var beginningIndexesLen = 0; |
| 6408 |
var wasUpper = false; |
| 6409 |
var wasAlphanum = false; |
| 6410 |
for (var i = 0; i < targetLen; ++i) { |
| 6411 |
var targetCode = target.charCodeAt(i); |
| 6412 |
var isUpper = targetCode >= 65 && targetCode <= 90; |
| 6413 |
var isAlphanum = isUpper || targetCode >= 97 && targetCode <= 122 || targetCode >= 48 && targetCode <= 57; |
| 6414 |
var isBeginning = isUpper && !wasUpper || !wasAlphanum || !isAlphanum; |
| 6415 |
wasUpper = isUpper; |
| 6416 |
wasAlphanum = isAlphanum; |
| 6417 |
if (isBeginning) beginningIndexes[beginningIndexesLen++] = i; |
| 6418 |
} |
| 6419 |
return beginningIndexes; |
| 6420 |
}, |
| 6421 |
prepareNextBeginningIndexes: function prepareNextBeginningIndexes(target) { |
| 6422 |
var targetLen = target.length; |
| 6423 |
var beginningIndexes = fuzzysort.prepareBeginningIndexes(target); |
| 6424 |
var nextBeginningIndexes = []; // new Array(targetLen) sparse array is too slow |
| 6425 |
var lastIsBeginning = beginningIndexes[0]; |
| 6426 |
var lastIsBeginningI = 0; |
| 6427 |
for (var i = 0; i < targetLen; ++i) { |
| 6428 |
if (lastIsBeginning > i) { |
| 6429 |
nextBeginningIndexes[i] = lastIsBeginning; |
| 6430 |
} else { |
| 6431 |
lastIsBeginning = beginningIndexes[++lastIsBeginningI]; |
| 6432 |
nextBeginningIndexes[i] = lastIsBeginning === undefined ? targetLen : lastIsBeginning; |
| 6433 |
} |
| 6434 |
} |
| 6435 |
return nextBeginningIndexes; |
| 6436 |
}, |
| 6437 |
cleanup: cleanup, |
| 6438 |
new: fuzzysortNew |
| 6439 |
}; |
| 6440 |
return fuzzysort; |
| 6441 |
} // fuzzysortNew |
| 6442 |
|
| 6443 |
// This stuff is outside fuzzysortNew, because it's shared with instances of fuzzysort.new() |
| 6444 |
var isNode = typeof commonjsRequire !== 'undefined' && typeof window === 'undefined'; |
| 6445 |
var MyMap = typeof Map === 'function' ? Map : function () { |
| 6446 |
var s = Object.create(null); |
| 6447 |
this.get = function (k) { |
| 6448 |
return s[k]; |
| 6449 |
}; |
| 6450 |
this.set = function (k, val) { |
| 6451 |
s[k] = val; |
| 6452 |
return this; |
| 6453 |
}; |
| 6454 |
this.clear = function () { |
| 6455 |
s = Object.create(null); |
| 6456 |
}; |
| 6457 |
}; |
| 6458 |
var preparedCache = new MyMap(); |
| 6459 |
var preparedSearchCache = new MyMap(); |
| 6460 |
var noResults = []; |
| 6461 |
noResults.total = 0; |
| 6462 |
var matchesSimple = []; |
| 6463 |
var matchesStrict = []; |
| 6464 |
function cleanup() { |
| 6465 |
preparedCache.clear(); |
| 6466 |
preparedSearchCache.clear(); |
| 6467 |
matchesSimple = []; |
| 6468 |
matchesStrict = []; |
| 6469 |
} |
| 6470 |
function defaultScoreFn(a) { |
| 6471 |
var max = -9007199254740991; |
| 6472 |
for (var i = a.length - 1; i >= 0; --i) { |
| 6473 |
var result = a[i]; |
| 6474 |
if (result === null) continue; |
| 6475 |
var score = result.score; |
| 6476 |
if (score > max) max = score; |
| 6477 |
} |
| 6478 |
if (max === -9007199254740991) return null; |
| 6479 |
return max; |
| 6480 |
} |
| 6481 |
|
| 6482 |
// prop = 'key' 2.5ms optimized for this case, seems to be about as fast as direct obj[prop] |
| 6483 |
// prop = 'key1.key2' 10ms |
| 6484 |
// prop = ['key1', 'key2'] 27ms |
| 6485 |
function getValue(obj, prop) { |
| 6486 |
var tmp = obj[prop]; |
| 6487 |
if (tmp !== undefined) return tmp; |
| 6488 |
var segs = prop; |
| 6489 |
if (!Array.isArray(prop)) segs = prop.split('.'); |
| 6490 |
var len = segs.length; |
| 6491 |
var i = -1; |
| 6492 |
while (obj && ++i < len) obj = obj[segs[i]]; |
| 6493 |
return obj; |
| 6494 |
} |
| 6495 |
function isObj(x) { |
| 6496 |
return _typeof(x) === 'object'; |
| 6497 |
} // faster as a function |
| 6498 |
|
| 6499 |
// Hacked version of https://github.com/lemire/FastPriorityQueue.js |
| 6500 |
var fastpriorityqueue = function fastpriorityqueue() { |
| 6501 |
var r = [], |
| 6502 |
o = 0, |
| 6503 |
e = {}; |
| 6504 |
function n() { |
| 6505 |
for (var e = 0, n = r[e], c = 1; c < o;) { |
| 6506 |
var f = c + 1; |
| 6507 |
e = c, f < o && r[f].score < r[c].score && (e = f), r[e - 1 >> 1] = r[e], c = 1 + (e << 1); |
| 6508 |
} |
| 6509 |
for (var a = e - 1 >> 1; e > 0 && n.score < r[a].score; a = (e = a) - 1 >> 1) r[e] = r[a]; |
| 6510 |
r[e] = n; |
| 6511 |
} |
| 6512 |
return e.add = function (e) { |
| 6513 |
var n = o; |
| 6514 |
r[o++] = e; |
| 6515 |
for (var c = n - 1 >> 1; n > 0 && e.score < r[c].score; c = (n = c) - 1 >> 1) r[n] = r[c]; |
| 6516 |
r[n] = e; |
| 6517 |
}, e.poll = function () { |
| 6518 |
if (0 !== o) { |
| 6519 |
var e = r[0]; |
| 6520 |
return r[0] = r[--o], n(), e; |
| 6521 |
} |
| 6522 |
}, e.peek = function (e) { |
| 6523 |
if (0 !== o) return r[0]; |
| 6524 |
}, e.replaceTop = function (o) { |
| 6525 |
r[0] = o, n(); |
| 6526 |
}, e; |
| 6527 |
}; |
| 6528 |
var q = fastpriorityqueue(); // reuse this, except for async, it needs to make its own |
| 6529 |
|
| 6530 |
return fuzzysortNew(); |
| 6531 |
}); // UMD |
| 6532 |
|
| 6533 |
// TODO: (performance) wasm version!? |
| 6534 |
// TODO: (performance) threads? |
| 6535 |
// TODO: (performance) avoid cache misses |
| 6536 |
// TODO: (performance) preparedCache is a memory leak |
| 6537 |
// TODO: (like sublime) backslash === forwardslash |
| 6538 |
// TODO: (like sublime) spaces: "a b" should do 2 searches 1 for a and 1 for b |
| 6539 |
// TODO: (scoring) garbage in targets that allows most searches to strict match need a penality |
| 6540 |
// TODO: (performance) idk if allowTypo is optimized |
| 6541 |
})(fuzzysort$1); |
| 6542 |
var fuzzysort = fuzzysort$1.exports; |
| 6543 |
|
| 6544 |
var stats = { |
| 6545 |
failedTests: [], |
| 6546 |
defined: 0, |
| 6547 |
completed: 0 |
| 6548 |
}; |
| 6549 |
(function () { |
| 6550 |
// Don't load the HTML Reporter on non-browser environments |
| 6551 |
if (!window$1 || !document) { |
| 6552 |
return; |
| 6553 |
} |
| 6554 |
QUnit.reporters.perf.init(QUnit); |
| 6555 |
var config = QUnit.config; |
| 6556 |
var hiddenTests = []; |
| 6557 |
var collapseNext = false; |
| 6558 |
var hasOwn = Object.prototype.hasOwnProperty; |
| 6559 |
var unfilteredUrl = setUrl({ |
| 6560 |
filter: undefined, |
| 6561 |
module: undefined, |
| 6562 |
moduleId: undefined, |
| 6563 |
testId: undefined |
| 6564 |
}); |
| 6565 |
var dropdownData = null; |
| 6566 |
function trim(string) { |
| 6567 |
if (typeof string.trim === 'function') { |
| 6568 |
return string.trim(); |
| 6569 |
} else { |
| 6570 |
return string.replace(/^\s+|\s+$/g, ''); |
| 6571 |
} |
| 6572 |
} |
| 6573 |
function addEvent(elem, type, fn) { |
| 6574 |
elem.addEventListener(type, fn, false); |
| 6575 |
} |
| 6576 |
function removeEvent(elem, type, fn) { |
| 6577 |
elem.removeEventListener(type, fn, false); |
| 6578 |
} |
| 6579 |
function addEvents(elems, type, fn) { |
| 6580 |
var i = elems.length; |
| 6581 |
while (i--) { |
| 6582 |
addEvent(elems[i], type, fn); |
| 6583 |
} |
| 6584 |
} |
| 6585 |
function hasClass(elem, name) { |
| 6586 |
return (' ' + elem.className + ' ').indexOf(' ' + name + ' ') >= 0; |
| 6587 |
} |
| 6588 |
function addClass(elem, name) { |
| 6589 |
if (!hasClass(elem, name)) { |
| 6590 |
elem.className += (elem.className ? ' ' : '') + name; |
| 6591 |
} |
| 6592 |
} |
| 6593 |
function toggleClass(elem, name, force) { |
| 6594 |
if (force || typeof force === 'undefined' && !hasClass(elem, name)) { |
| 6595 |
addClass(elem, name); |
| 6596 |
} else { |
| 6597 |
removeClass(elem, name); |
| 6598 |
} |
| 6599 |
} |
| 6600 |
function removeClass(elem, name) { |
| 6601 |
var set = ' ' + elem.className + ' '; |
| 6602 |
|
| 6603 |
// Class name may appear multiple times |
| 6604 |
while (set.indexOf(' ' + name + ' ') >= 0) { |
| 6605 |
set = set.replace(' ' + name + ' ', ' '); |
| 6606 |
} |
| 6607 |
|
| 6608 |
// Trim for prettiness |
| 6609 |
elem.className = trim(set); |
| 6610 |
} |
| 6611 |
function id(name) { |
| 6612 |
return document.getElementById && document.getElementById(name); |
| 6613 |
} |
| 6614 |
function abortTests() { |
| 6615 |
var abortButton = id('qunit-abort-tests-button'); |
| 6616 |
if (abortButton) { |
| 6617 |
abortButton.disabled = true; |
| 6618 |
abortButton.innerHTML = 'Aborting...'; |
| 6619 |
} |
| 6620 |
QUnit.config.queue.length = 0; |
| 6621 |
return false; |
| 6622 |
} |
| 6623 |
function interceptNavigation(ev) { |
| 6624 |
// Trim potential accidental whitespace so that QUnit doesn't throw an error about no tests matching the filter. |
| 6625 |
var filterInputElem = id('qunit-filter-input'); |
| 6626 |
filterInputElem.value = trim(filterInputElem.value); |
| 6627 |
applyUrlParams(); |
| 6628 |
if (ev && ev.preventDefault) { |
| 6629 |
ev.preventDefault(); |
| 6630 |
} |
| 6631 |
return false; |
| 6632 |
} |
| 6633 |
function getUrlConfigHtml() { |
| 6634 |
var selection = false; |
| 6635 |
var urlConfig = config.urlConfig; |
| 6636 |
var urlConfigHtml = ''; |
| 6637 |
for (var i = 0; i < urlConfig.length; i++) { |
| 6638 |
// Options can be either strings or objects with nonempty "id" properties |
| 6639 |
var val = config.urlConfig[i]; |
| 6640 |
if (typeof val === 'string') { |
| 6641 |
val = { |
| 6642 |
id: val, |
| 6643 |
label: val |
| 6644 |
}; |
| 6645 |
} |
| 6646 |
var escaped = escapeText(val.id); |
| 6647 |
var escapedTooltip = escapeText(val.tooltip); |
| 6648 |
if (!val.value || typeof val.value === 'string') { |
| 6649 |
urlConfigHtml += "<label for='qunit-urlconfig-" + escaped + "' title='" + escapedTooltip + "'><input id='qunit-urlconfig-" + escaped + "' name='" + escaped + "' type='checkbox'" + (val.value ? " value='" + escapeText(val.value) + "'" : '') + (config[val.id] ? " checked='checked'" : '') + " title='" + escapedTooltip + "' />" + escapeText(val.label) + '</label>'; |
| 6650 |
} else { |
| 6651 |
urlConfigHtml += "<label for='qunit-urlconfig-" + escaped + "' title='" + escapedTooltip + "'>" + escapeText(val.label) + ": <select id='qunit-urlconfig-" + escaped + "' name='" + escaped + "' title='" + escapedTooltip + "'><option></option>"; |
| 6652 |
if (Array.isArray(val.value)) { |
| 6653 |
for (var j = 0; j < val.value.length; j++) { |
| 6654 |
escaped = escapeText(val.value[j]); |
| 6655 |
urlConfigHtml += "<option value='" + escaped + "'" + (config[val.id] === val.value[j] ? (selection = true) && " selected='selected'" : '') + '>' + escaped + '</option>'; |
| 6656 |
} |
| 6657 |
} else { |
| 6658 |
for (var _j in val.value) { |
| 6659 |
if (hasOwn.call(val.value, _j)) { |
| 6660 |
urlConfigHtml += "<option value='" + escapeText(_j) + "'" + (config[val.id] === _j ? (selection = true) && " selected='selected'" : '') + '>' + escapeText(val.value[_j]) + '</option>'; |
| 6661 |
} |
| 6662 |
} |
| 6663 |
} |
| 6664 |
if (config[val.id] && !selection) { |
| 6665 |
escaped = escapeText(config[val.id]); |
| 6666 |
urlConfigHtml += "<option value='" + escaped + "' selected='selected' disabled='disabled'>" + escaped + '</option>'; |
| 6667 |
} |
| 6668 |
urlConfigHtml += '</select></label>'; |
| 6669 |
} |
| 6670 |
} |
| 6671 |
return urlConfigHtml; |
| 6672 |
} |
| 6673 |
|
| 6674 |
// Handle "click" events on toolbar checkboxes and "change" for select menus. |
| 6675 |
// Updates the URL with the new state of `config.urlConfig` values. |
| 6676 |
function toolbarChanged() { |
| 6677 |
var field = this; |
| 6678 |
var params = {}; |
| 6679 |
|
| 6680 |
// Detect if field is a select menu or a checkbox |
| 6681 |
var value; |
| 6682 |
if ('selectedIndex' in field) { |
| 6683 |
value = field.options[field.selectedIndex].value || undefined; |
| 6684 |
} else { |
| 6685 |
value = field.checked ? field.defaultValue || true : undefined; |
| 6686 |
} |
| 6687 |
params[field.name] = value; |
| 6688 |
var updatedUrl = setUrl(params); |
| 6689 |
|
| 6690 |
// Check if we can apply the change without a page refresh |
| 6691 |
if (field.name === 'hidepassed' && 'replaceState' in window$1.history) { |
| 6692 |
QUnit.urlParams[field.name] = value; |
| 6693 |
config[field.name] = value || false; |
| 6694 |
var tests = id('qunit-tests'); |
| 6695 |
if (tests) { |
| 6696 |
if (field.checked) { |
| 6697 |
var length = tests.children.length; |
| 6698 |
var children = tests.children; |
| 6699 |
for (var i = 0; i < length; i++) { |
| 6700 |
var test = children[i]; |
| 6701 |
var className = test ? test.className : ''; |
| 6702 |
var classNameHasPass = className.indexOf('pass') > -1; |
| 6703 |
var classNameHasSkipped = className.indexOf('skipped') > -1; |
| 6704 |
if (classNameHasPass || classNameHasSkipped) { |
| 6705 |
hiddenTests.push(test); |
| 6706 |
} |
| 6707 |
} |
| 6708 |
|
| 6709 |
// Optimization: Avoid `for-of` iterator overhead. |
| 6710 |
for (var _i = 0; _i < hiddenTests.length; _i++) { |
| 6711 |
tests.removeChild(hiddenTests[_i]); |
| 6712 |
} |
| 6713 |
} else { |
| 6714 |
// Optimization: Avoid `while (arr.length) arr.shift()` which would mutate the array many times. |
| 6715 |
// As of Chrome 126, HTMLElement.append(...hiddenTests) is still slower than |
| 6716 |
// calling appendChild in a loop. |
| 6717 |
for (var _i2 = 0; _i2 < hiddenTests.length; _i2++) { |
| 6718 |
tests.appendChild(hiddenTests[_i2]); |
| 6719 |
} |
| 6720 |
hiddenTests.length = 0; |
| 6721 |
} |
| 6722 |
} |
| 6723 |
window$1.history.replaceState(null, '', updatedUrl); |
| 6724 |
} else { |
| 6725 |
window$1.location = updatedUrl; |
| 6726 |
} |
| 6727 |
} |
| 6728 |
function setUrl(params) { |
| 6729 |
var querystring = '?'; |
| 6730 |
var location = window$1.location; |
| 6731 |
params = extend(extend({}, QUnit.urlParams), params); |
| 6732 |
for (var key in params) { |
| 6733 |
// Skip inherited or undefined properties |
| 6734 |
if (hasOwn.call(params, key) && params[key] !== undefined) { |
| 6735 |
// Output a parameter for each value of this key |
| 6736 |
// (but usually just one) |
| 6737 |
var arrValue = [].concat(params[key]); |
| 6738 |
for (var i = 0; i < arrValue.length; i++) { |
| 6739 |
querystring += encodeURIComponent(key); |
| 6740 |
if (arrValue[i] !== true) { |
| 6741 |
querystring += '=' + encodeURIComponent(arrValue[i]); |
| 6742 |
} |
| 6743 |
querystring += '&'; |
| 6744 |
} |
| 6745 |
} |
| 6746 |
} |
| 6747 |
return location.protocol + '//' + location.host + location.pathname + querystring.slice(0, -1); |
| 6748 |
} |
| 6749 |
function applyUrlParams() { |
| 6750 |
var filter = id('qunit-filter-input').value; |
| 6751 |
window$1.location = setUrl({ |
| 6752 |
filter: filter === '' ? undefined : filter, |
| 6753 |
moduleId: _toConsumableArray(dropdownData.selectedMap.keys()), |
| 6754 |
// Remove module and testId filter |
| 6755 |
module: undefined, |
| 6756 |
testId: undefined |
| 6757 |
}); |
| 6758 |
} |
| 6759 |
function toolbarUrlConfigContainer() { |
| 6760 |
var urlConfigContainer = document.createElement('span'); |
| 6761 |
urlConfigContainer.innerHTML = getUrlConfigHtml(); |
| 6762 |
addClass(urlConfigContainer, 'qunit-url-config'); |
| 6763 |
addEvents(urlConfigContainer.getElementsByTagName('input'), 'change', toolbarChanged); |
| 6764 |
addEvents(urlConfigContainer.getElementsByTagName('select'), 'change', toolbarChanged); |
| 6765 |
return urlConfigContainer; |
| 6766 |
} |
| 6767 |
function abortTestsButton() { |
| 6768 |
var button = document.createElement('button'); |
| 6769 |
button.id = 'qunit-abort-tests-button'; |
| 6770 |
button.innerHTML = 'Abort'; |
| 6771 |
addEvent(button, 'click', abortTests); |
| 6772 |
return button; |
| 6773 |
} |
| 6774 |
function toolbarLooseFilter() { |
| 6775 |
var filter = document.createElement('form'); |
| 6776 |
var label = document.createElement('label'); |
| 6777 |
var input = document.createElement('input'); |
| 6778 |
var button = document.createElement('button'); |
| 6779 |
addClass(filter, 'qunit-filter'); |
| 6780 |
label.innerHTML = 'Filter: '; |
| 6781 |
input.type = 'text'; |
| 6782 |
input.value = config.filter || ''; |
| 6783 |
input.name = 'filter'; |
| 6784 |
input.id = 'qunit-filter-input'; |
| 6785 |
button.innerHTML = 'Go'; |
| 6786 |
label.appendChild(input); |
| 6787 |
filter.appendChild(label); |
| 6788 |
filter.appendChild(document.createTextNode(' ')); |
| 6789 |
filter.appendChild(button); |
| 6790 |
addEvent(filter, 'submit', interceptNavigation); |
| 6791 |
return filter; |
| 6792 |
} |
| 6793 |
function createModuleListItem(moduleId, name, checked) { |
| 6794 |
return '<li><label class="clickable' + (checked ? ' checked' : '') + '"><input type="checkbox" ' + 'value="' + escapeText(moduleId) + '"' + (checked ? ' checked="checked"' : '') + ' />' + escapeText(name) + '</label></li>'; |
| 6795 |
} |
| 6796 |
|
| 6797 |
/** |
| 6798 |
* @param {Array} Results from fuzzysort |
| 6799 |
* @return {string} HTML |
| 6800 |
*/ |
| 6801 |
function moduleListHtml(results) { |
| 6802 |
var html = ''; |
| 6803 |
|
| 6804 |
// Hoist the already selected items, and show them always |
| 6805 |
// even if not matched by the current search. |
| 6806 |
dropdownData.selectedMap.forEach(function (name, moduleId) { |
| 6807 |
html += createModuleListItem(moduleId, name, true); |
| 6808 |
}); |
| 6809 |
for (var i = 0; i < results.length; i++) { |
| 6810 |
var mod = results[i].obj; |
| 6811 |
if (!dropdownData.selectedMap.has(mod.moduleId)) { |
| 6812 |
html += createModuleListItem(mod.moduleId, mod.name, false); |
| 6813 |
} |
| 6814 |
} |
| 6815 |
return html; |
| 6816 |
} |
| 6817 |
function toolbarModuleFilter(beginDetails) { |
| 6818 |
var initialSelected = null; |
| 6819 |
dropdownData = { |
| 6820 |
options: beginDetails.modules.slice(), |
| 6821 |
selectedMap: new StringMap(), |
| 6822 |
isDirty: function isDirty() { |
| 6823 |
return _toConsumableArray(dropdownData.selectedMap.keys()).sort().join(',') !== _toConsumableArray(initialSelected.keys()).sort().join(','); |
| 6824 |
} |
| 6825 |
}; |
| 6826 |
if (config.moduleId.length) { |
| 6827 |
// The module dropdown is seeded with the runtime configuration of the last run. |
| 6828 |
// |
| 6829 |
// We don't reference `config.moduleId` directly after this and keep our own |
| 6830 |
// copy because: |
| 6831 |
// 1. This naturally filters out unknown moduleIds. |
| 6832 |
// 2. Gives us a place to manage and remember unsubmitted checkbox changes. |
| 6833 |
// 3. Gives us an efficient way to map a selected moduleId to module name |
| 6834 |
// during rendering. |
| 6835 |
for (var i = 0; i < beginDetails.modules.length; i++) { |
| 6836 |
var mod = beginDetails.modules[i]; |
| 6837 |
if (config.moduleId.indexOf(mod.moduleId) !== -1) { |
| 6838 |
dropdownData.selectedMap.set(mod.moduleId, mod.name); |
| 6839 |
} |
| 6840 |
} |
| 6841 |
} |
| 6842 |
initialSelected = new StringMap(dropdownData.selectedMap); |
| 6843 |
var moduleSearch = document.createElement('input'); |
| 6844 |
moduleSearch.id = 'qunit-modulefilter-search'; |
| 6845 |
moduleSearch.autocomplete = 'off'; |
| 6846 |
addEvent(moduleSearch, 'input', searchInput); |
| 6847 |
addEvent(moduleSearch, 'input', searchFocus); |
| 6848 |
addEvent(moduleSearch, 'focus', searchFocus); |
| 6849 |
addEvent(moduleSearch, 'click', searchFocus); |
| 6850 |
var label = document.createElement('label'); |
| 6851 |
label.htmlFor = 'qunit-modulefilter-search'; |
| 6852 |
label.textContent = 'Module:'; |
| 6853 |
var searchContainer = document.createElement('span'); |
| 6854 |
searchContainer.id = 'qunit-modulefilter-search-container'; |
| 6855 |
searchContainer.appendChild(moduleSearch); |
| 6856 |
var applyButton = document.createElement('button'); |
| 6857 |
applyButton.textContent = 'Apply'; |
| 6858 |
applyButton.title = 'Re-run the selected test modules'; |
| 6859 |
addEvent(applyButton, 'click', applyUrlParams); |
| 6860 |
var resetButton = document.createElement('button'); |
| 6861 |
resetButton.textContent = 'Reset'; |
| 6862 |
resetButton.type = 'reset'; |
| 6863 |
resetButton.title = 'Restore the previous module selection'; |
| 6864 |
var clearButton = document.createElement('button'); |
| 6865 |
clearButton.textContent = 'Select none'; |
| 6866 |
clearButton.type = 'button'; |
| 6867 |
clearButton.title = 'Clear the current module selection'; |
| 6868 |
addEvent(clearButton, 'click', function () { |
| 6869 |
dropdownData.selectedMap.clear(); |
| 6870 |
selectionChange(); |
| 6871 |
searchInput(); |
| 6872 |
}); |
| 6873 |
var actions = document.createElement('span'); |
| 6874 |
actions.id = 'qunit-modulefilter-actions'; |
| 6875 |
actions.appendChild(applyButton); |
| 6876 |
actions.appendChild(resetButton); |
| 6877 |
if (initialSelected.size) { |
| 6878 |
// Only show clear button if functionally different from reset |
| 6879 |
actions.appendChild(clearButton); |
| 6880 |
} |
| 6881 |
var dropDownList = document.createElement('ul'); |
| 6882 |
dropDownList.id = 'qunit-modulefilter-dropdown-list'; |
| 6883 |
var dropDown = document.createElement('div'); |
| 6884 |
dropDown.id = 'qunit-modulefilter-dropdown'; |
| 6885 |
dropDown.style.display = 'none'; |
| 6886 |
dropDown.appendChild(actions); |
| 6887 |
dropDown.appendChild(dropDownList); |
| 6888 |
addEvent(dropDown, 'change', selectionChange); |
| 6889 |
searchContainer.appendChild(dropDown); |
| 6890 |
// Set initial moduleSearch.placeholder and clearButton/resetButton. |
| 6891 |
selectionChange(); |
| 6892 |
var moduleFilter = document.createElement('form'); |
| 6893 |
moduleFilter.id = 'qunit-modulefilter'; |
| 6894 |
moduleFilter.appendChild(label); |
| 6895 |
moduleFilter.appendChild(document.createTextNode(' ')); |
| 6896 |
moduleFilter.appendChild(searchContainer); |
| 6897 |
addEvent(moduleFilter, 'submit', interceptNavigation); |
| 6898 |
addEvent(moduleFilter, 'reset', function () { |
| 6899 |
dropdownData.selectedMap = new StringMap(initialSelected); |
| 6900 |
// Set moduleSearch.placeholder and reflect non-dirty state |
| 6901 |
selectionChange(); |
| 6902 |
searchInput(); |
| 6903 |
}); |
| 6904 |
|
| 6905 |
// Enables show/hide for the dropdown |
| 6906 |
function searchFocus() { |
| 6907 |
if (dropDown.style.display !== 'none') { |
| 6908 |
return; |
| 6909 |
} |
| 6910 |
|
| 6911 |
// Optimization: Defer rendering options until focussed. |
| 6912 |
// https://github.com/qunitjs/qunit/issues/1664 |
| 6913 |
searchInput(); |
| 6914 |
dropDown.style.display = 'block'; |
| 6915 |
|
| 6916 |
// Hide on Escape keydown or on click outside the container |
| 6917 |
addEvent(document, 'click', hideHandler); |
| 6918 |
addEvent(document, 'keydown', hideHandler); |
| 6919 |
function hideHandler(e) { |
| 6920 |
var inContainer = moduleFilter.contains(e.target); |
| 6921 |
if (e.keyCode === 27 || !inContainer) { |
| 6922 |
if (e.keyCode === 27 && inContainer) { |
| 6923 |
moduleSearch.focus(); |
| 6924 |
} |
| 6925 |
dropDown.style.display = 'none'; |
| 6926 |
removeEvent(document, 'click', hideHandler); |
| 6927 |
removeEvent(document, 'keydown', hideHandler); |
| 6928 |
moduleSearch.value = ''; |
| 6929 |
searchInput(); |
| 6930 |
} |
| 6931 |
} |
| 6932 |
} |
| 6933 |
|
| 6934 |
/** |
| 6935 |
* @param {string} searchText |
| 6936 |
* @return {string} HTML |
| 6937 |
*/ |
| 6938 |
function filterModules(searchText) { |
| 6939 |
var results; |
| 6940 |
if (searchText === '') { |
| 6941 |
// Improve on-boarding experience by having an immediate display of |
| 6942 |
// module names, indicating how the interface works. This also makes |
| 6943 |
// for a quicker interaction in the common case of small projects. |
| 6944 |
// Don't mandate typing just to get the menu. |
| 6945 |
results = dropdownData.options.slice(0, 20).map(function (obj) { |
| 6946 |
// Fake empty results. https://github.com/farzher/fuzzysort/issues/41 |
| 6947 |
return { |
| 6948 |
obj: obj |
| 6949 |
}; |
| 6950 |
}); |
| 6951 |
} else { |
| 6952 |
results = fuzzysort.go(searchText, dropdownData.options, { |
| 6953 |
limit: 20, |
| 6954 |
key: 'name', |
| 6955 |
allowTypo: true |
| 6956 |
}); |
| 6957 |
} |
| 6958 |
return moduleListHtml(results); |
| 6959 |
} |
| 6960 |
|
| 6961 |
// Processes module search box input |
| 6962 |
var searchInputTimeout; |
| 6963 |
function searchInput() { |
| 6964 |
// Use a debounce with a ~0ms timeout. This is effectively instantaneous, |
| 6965 |
// but is better than undebounced because it avoids an ever-growing |
| 6966 |
// backlog of unprocessed now-outdated input events if fuzzysearch or |
| 6967 |
// drodown DOM is slow (e.g. very large test suite). |
| 6968 |
window$1.clearTimeout(searchInputTimeout); |
| 6969 |
searchInputTimeout = window$1.setTimeout(function () { |
| 6970 |
dropDownList.innerHTML = filterModules(moduleSearch.value); |
| 6971 |
}); |
| 6972 |
} |
| 6973 |
|
| 6974 |
// Processes checkbox change, or a generic render (initial render, or after reset event) |
| 6975 |
// Avoid any dropdown rendering here as this is used by toolbarModuleFilter() |
| 6976 |
// during the initial render, which should not delay test execution. |
| 6977 |
function selectionChange(evt) { |
| 6978 |
var checkbox = evt && evt.target || null; |
| 6979 |
if (checkbox) { |
| 6980 |
// Update internal state |
| 6981 |
if (checkbox.checked) { |
| 6982 |
dropdownData.selectedMap.set(checkbox.value, checkbox.parentNode.textContent); |
| 6983 |
} else { |
| 6984 |
dropdownData.selectedMap.delete(checkbox.value); |
| 6985 |
} |
| 6986 |
|
| 6987 |
// Update UI state |
| 6988 |
toggleClass(checkbox.parentNode, 'checked', checkbox.checked); |
| 6989 |
} |
| 6990 |
var textForm = dropdownData.selectedMap.size ? dropdownData.selectedMap.size + ' ' + (dropdownData.selectedMap.size === 1 ? 'module' : 'modules') : 'All modules'; |
| 6991 |
moduleSearch.placeholder = textForm; |
| 6992 |
moduleSearch.title = 'Type to search through and reduce the list.'; |
| 6993 |
resetButton.disabled = !dropdownData.isDirty(); |
| 6994 |
clearButton.style.display = dropdownData.selectedMap.size ? '' : 'none'; |
| 6995 |
} |
| 6996 |
return moduleFilter; |
| 6997 |
} |
| 6998 |
function appendToolbar(beginDetails) { |
| 6999 |
var toolbar = id('qunit-testrunner-toolbar'); |
| 7000 |
if (toolbar) { |
| 7001 |
toolbar.appendChild(toolbarUrlConfigContainer()); |
| 7002 |
var toolbarFilters = document.createElement('span'); |
| 7003 |
toolbarFilters.id = 'qunit-toolbar-filters'; |
| 7004 |
toolbarFilters.appendChild(toolbarLooseFilter()); |
| 7005 |
toolbarFilters.appendChild(toolbarModuleFilter(beginDetails)); |
| 7006 |
var clearfix = document.createElement('div'); |
| 7007 |
clearfix.className = 'clearfix'; |
| 7008 |
toolbar.appendChild(toolbarFilters); |
| 7009 |
toolbar.appendChild(clearfix); |
| 7010 |
} |
| 7011 |
} |
| 7012 |
function appendHeader() { |
| 7013 |
var header = id('qunit-header'); |
| 7014 |
if (header) { |
| 7015 |
header.innerHTML = "<a href='" + escapeText(unfilteredUrl) + "'>" + header.innerHTML + '</a> '; |
| 7016 |
} |
| 7017 |
} |
| 7018 |
function appendBanner() { |
| 7019 |
var banner = id('qunit-banner'); |
| 7020 |
if (banner) { |
| 7021 |
banner.className = ''; |
| 7022 |
} |
| 7023 |
} |
| 7024 |
function appendTestResults() { |
| 7025 |
var tests = id('qunit-tests'); |
| 7026 |
var result = id('qunit-testresult'); |
| 7027 |
var controls; |
| 7028 |
if (result) { |
| 7029 |
result.parentNode.removeChild(result); |
| 7030 |
} |
| 7031 |
if (tests) { |
| 7032 |
tests.innerHTML = ''; |
| 7033 |
result = document.createElement('p'); |
| 7034 |
result.id = 'qunit-testresult'; |
| 7035 |
result.className = 'result'; |
| 7036 |
tests.parentNode.insertBefore(result, tests); |
| 7037 |
result.innerHTML = '<div id="qunit-testresult-display">Running...<br /> </div>' + '<div id="qunit-testresult-controls"></div>' + '<div class="clearfix"></div>'; |
| 7038 |
controls = id('qunit-testresult-controls'); |
| 7039 |
} |
| 7040 |
if (controls) { |
| 7041 |
controls.appendChild(abortTestsButton()); |
| 7042 |
} |
| 7043 |
} |
| 7044 |
function appendFilteredTest() { |
| 7045 |
var testId = QUnit.config.testId; |
| 7046 |
if (!testId || testId.length <= 0) { |
| 7047 |
return ''; |
| 7048 |
} |
| 7049 |
return "<div id='qunit-filteredTest'>Rerunning selected tests: " + escapeText(testId.join(', ')) + " <a id='qunit-clearFilter' href='" + escapeText(unfilteredUrl) + "'>Run all tests</a></div>"; |
| 7050 |
} |
| 7051 |
function appendUserAgent() { |
| 7052 |
var userAgent = id('qunit-userAgent'); |
| 7053 |
if (userAgent) { |
| 7054 |
userAgent.innerHTML = ''; |
| 7055 |
userAgent.appendChild(document.createTextNode('QUnit ' + QUnit.version + '; ' + navigator.userAgent)); |
| 7056 |
} |
| 7057 |
} |
| 7058 |
function appendInterface(beginDetails) { |
| 7059 |
var qunit = id('qunit'); |
| 7060 |
|
| 7061 |
// For compat with QUnit 1.2, and to support fully custom theme HTML, |
| 7062 |
// we will use any existing elements if no id="qunit" element exists. |
| 7063 |
// |
| 7064 |
// Note that we don't fail or fallback to creating it ourselves, |
| 7065 |
// because not having id="qunit" (and not having the below elements) |
| 7066 |
// simply means QUnit acts headless, allowing users to use their own |
| 7067 |
// reporters, or for a test runner to listen for events directly without |
| 7068 |
// having the HTML reporter actively render anything. |
| 7069 |
if (qunit) { |
| 7070 |
qunit.setAttribute('role', 'main'); |
| 7071 |
|
| 7072 |
// Since QUnit 1.3, these are created automatically if the page |
| 7073 |
// contains id="qunit". |
| 7074 |
qunit.innerHTML = "<h1 id='qunit-header'>" + escapeText(document.title) + '</h1>' + "<h2 id='qunit-banner'></h2>" + "<div id='qunit-testrunner-toolbar' role='navigation'></div>" + appendFilteredTest() + "<h2 id='qunit-userAgent'></h2>" + "<ol id='qunit-tests'></ol>"; |
| 7075 |
} |
| 7076 |
appendHeader(); |
| 7077 |
appendBanner(); |
| 7078 |
appendTestResults(); |
| 7079 |
appendUserAgent(); |
| 7080 |
appendToolbar(beginDetails); |
| 7081 |
} |
| 7082 |
function appendTest(name, testId, moduleName) { |
| 7083 |
var tests = id('qunit-tests'); |
| 7084 |
if (!tests) { |
| 7085 |
return; |
| 7086 |
} |
| 7087 |
var title = document.createElement('strong'); |
| 7088 |
title.className = 'qunit-test-name'; |
| 7089 |
title.innerHTML = getNameHtml(name, moduleName); |
| 7090 |
var testBlock = document.createElement('li'); |
| 7091 |
testBlock.appendChild(title); |
| 7092 |
|
| 7093 |
// No ID or rerun link for "global failure" blocks |
| 7094 |
if (testId !== undefined) { |
| 7095 |
var rerunTrigger = document.createElement('a'); |
| 7096 |
rerunTrigger.innerHTML = 'Rerun'; |
| 7097 |
rerunTrigger.href = setUrl({ |
| 7098 |
testId: testId |
| 7099 |
}); |
| 7100 |
testBlock.id = 'qunit-test-output-' + testId; |
| 7101 |
testBlock.appendChild(rerunTrigger); |
| 7102 |
} |
| 7103 |
var assertList = document.createElement('ol'); |
| 7104 |
assertList.className = 'qunit-assert-list'; |
| 7105 |
testBlock.appendChild(assertList); |
| 7106 |
tests.appendChild(testBlock); |
| 7107 |
return testBlock; |
| 7108 |
} |
| 7109 |
|
| 7110 |
// HTML Reporter initialization and load |
| 7111 |
QUnit.on('runStart', function (runStart) { |
| 7112 |
stats.defined = runStart.testCounts.total; |
| 7113 |
}); |
| 7114 |
QUnit.begin(function (beginDetails) { |
| 7115 |
// Initialize QUnit elements |
| 7116 |
// This is done from begin() instead of runStart, because |
| 7117 |
// urlparams.js uses begin(), which we need to wait for. |
| 7118 |
// urlparams.js in turn uses begin() to allow plugins to |
| 7119 |
// add entries to QUnit.config.urlConfig, which may be done |
| 7120 |
// asynchronously. |
| 7121 |
// <https://github.com/qunitjs/qunit/issues/1657> |
| 7122 |
appendInterface(beginDetails); |
| 7123 |
}); |
| 7124 |
function getRerunFailedHtml(failedTests) { |
| 7125 |
if (failedTests.length === 0) { |
| 7126 |
return ''; |
| 7127 |
} |
| 7128 |
var href = setUrl({ |
| 7129 |
testId: failedTests |
| 7130 |
}); |
| 7131 |
return ["<br /><a href='" + escapeText(href) + "'>", failedTests.length === 1 ? 'Rerun 1 failed test' : 'Rerun ' + failedTests.length + ' failed tests', '</a>'].join(''); |
| 7132 |
} |
| 7133 |
QUnit.on('runEnd', function (runEnd) { |
| 7134 |
var banner = id('qunit-banner'); |
| 7135 |
var tests = id('qunit-tests'); |
| 7136 |
var abortButton = id('qunit-abort-tests-button'); |
| 7137 |
var assertPassed = config.stats.all - config.stats.bad; |
| 7138 |
var html = [runEnd.testCounts.total, ' tests completed in ', runEnd.runtime, ' milliseconds, with ', runEnd.testCounts.failed, ' failed, ', runEnd.testCounts.skipped, ' skipped, and ', runEnd.testCounts.todo, ' todo.<br />', "<span class='passed'>", assertPassed, "</span> assertions of <span class='total'>", config.stats.all, "</span> passed, <span class='failed'>", config.stats.bad, '</span> failed.', getRerunFailedHtml(stats.failedTests)].join(''); |
| 7139 |
var test; |
| 7140 |
var assertLi; |
| 7141 |
var assertList; |
| 7142 |
|
| 7143 |
// Update remaining tests to aborted |
| 7144 |
if (abortButton && abortButton.disabled) { |
| 7145 |
html = 'Tests aborted after ' + runEnd.runtime + ' milliseconds.'; |
| 7146 |
for (var i = 0; i < tests.children.length; i++) { |
| 7147 |
test = tests.children[i]; |
| 7148 |
if (test.className === '' || test.className === 'running') { |
| 7149 |
test.className = 'aborted'; |
| 7150 |
assertList = test.getElementsByTagName('ol')[0]; |
| 7151 |
assertLi = document.createElement('li'); |
| 7152 |
assertLi.className = 'fail'; |
| 7153 |
assertLi.innerHTML = 'Test aborted.'; |
| 7154 |
assertList.appendChild(assertLi); |
| 7155 |
} |
| 7156 |
} |
| 7157 |
} |
| 7158 |
if (banner && (!abortButton || abortButton.disabled === false)) { |
| 7159 |
banner.className = runEnd.status === 'failed' ? 'qunit-fail' : 'qunit-pass'; |
| 7160 |
} |
| 7161 |
if (abortButton) { |
| 7162 |
abortButton.parentNode.removeChild(abortButton); |
| 7163 |
} |
| 7164 |
if (tests) { |
| 7165 |
id('qunit-testresult-display').innerHTML = html; |
| 7166 |
} |
| 7167 |
if (config.altertitle && document.title) { |
| 7168 |
// Show ✖ for good, ✔ for bad suite result in title |
| 7169 |
// use escape sequences in case file gets loaded with non-utf-8 |
| 7170 |
// charset |
| 7171 |
document.title = [runEnd.status === 'failed' ? "\u2716" : "\u2714", document.title.replace(/^[\u2714\u2716] /i, '')].join(' '); |
| 7172 |
} |
| 7173 |
|
| 7174 |
// Scroll back to top to show results |
| 7175 |
if (config.scrolltop && window$1.scrollTo) { |
| 7176 |
window$1.scrollTo(0, 0); |
| 7177 |
} |
| 7178 |
}); |
| 7179 |
function getNameHtml(name, module) { |
| 7180 |
var nameHtml = ''; |
| 7181 |
if (module) { |
| 7182 |
nameHtml = "<span class='module-name'>" + escapeText(module) + '</span>: '; |
| 7183 |
} |
| 7184 |
nameHtml += "<span class='test-name'>" + escapeText(name) + '</span>'; |
| 7185 |
return nameHtml; |
| 7186 |
} |
| 7187 |
function getProgressHtml(stats) { |
| 7188 |
return [stats.completed, ' / ', stats.defined, ' tests completed.<br />'].join(''); |
| 7189 |
} |
| 7190 |
QUnit.testStart(function (details) { |
| 7191 |
var running, bad; |
| 7192 |
appendTest(details.name, details.testId, details.module); |
| 7193 |
running = id('qunit-testresult-display'); |
| 7194 |
if (running) { |
| 7195 |
addClass(running, 'running'); |
| 7196 |
bad = QUnit.config.reorder && details.previousFailure; |
| 7197 |
running.innerHTML = [getProgressHtml(stats), bad ? 'Rerunning previously failed test: <br />' : 'Running: ', getNameHtml(details.name, details.module), getRerunFailedHtml(stats.failedTests)].join(''); |
| 7198 |
} |
| 7199 |
}); |
| 7200 |
function stripHtml(string) { |
| 7201 |
// Strip tags, html entity and whitespaces |
| 7202 |
return string.replace(/<\/?[^>]+(>|$)/g, '').replace(/"/g, '').replace(/\s+/g, ''); |
| 7203 |
} |
| 7204 |
QUnit.log(function (details) { |
| 7205 |
var testItem = id('qunit-test-output-' + details.testId); |
| 7206 |
if (!testItem) { |
| 7207 |
return; |
| 7208 |
} |
| 7209 |
var message = escapeText(details.message) || (details.result ? 'okay' : 'failed'); |
| 7210 |
message = "<span class='test-message'>" + message + '</span>'; |
| 7211 |
message += "<span class='runtime'>@ " + details.runtime + ' ms</span>'; |
| 7212 |
var expected; |
| 7213 |
var actual; |
| 7214 |
var diff; |
| 7215 |
var showDiff = false; |
| 7216 |
|
| 7217 |
// When pushFailure() is called, it is implied that no expected value |
| 7218 |
// or diff should be shown, because both expected and actual as undefined. |
| 7219 |
// |
| 7220 |
// This must check details.expected existence. If it exists as undefined, |
| 7221 |
// that's a regular assertion for which to render actual/expected and a diff. |
| 7222 |
var showAnyValues = !details.result && (details.expected !== undefined || details.actual !== undefined); |
| 7223 |
if (showAnyValues) { |
| 7224 |
if (details.negative) { |
| 7225 |
expected = 'NOT ' + QUnit.dump.parse(details.expected); |
| 7226 |
} else { |
| 7227 |
expected = QUnit.dump.parse(details.expected); |
| 7228 |
} |
| 7229 |
actual = QUnit.dump.parse(details.actual); |
| 7230 |
message += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + escapeText(expected) + '</pre></td></tr>'; |
| 7231 |
if (actual !== expected) { |
| 7232 |
message += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeText(actual) + '</pre></td></tr>'; |
| 7233 |
if (typeof details.actual === 'number' && typeof details.expected === 'number') { |
| 7234 |
if (!isNaN(details.actual) && !isNaN(details.expected)) { |
| 7235 |
showDiff = true; |
| 7236 |
diff = details.actual - details.expected; |
| 7237 |
diff = (diff > 0 ? '+' : '') + diff; |
| 7238 |
} |
| 7239 |
} else if (typeof details.actual !== 'boolean' && typeof details.expected !== 'boolean') { |
| 7240 |
diff = QUnit.diff(expected, actual); |
| 7241 |
|
| 7242 |
// don't show diff if there is zero overlap |
| 7243 |
showDiff = stripHtml(diff).length !== stripHtml(expected).length + stripHtml(actual).length; |
| 7244 |
} |
| 7245 |
if (showDiff) { |
| 7246 |
message += "<tr class='test-diff'><th>Diff: </th><td><pre>" + diff + '</pre></td></tr>'; |
| 7247 |
} |
| 7248 |
} else if (expected.indexOf('[object Array]') !== -1 || expected.indexOf('[object Object]') !== -1) { |
| 7249 |
message += "<tr class='test-message'><th>Message: </th><td>" + 'Diff suppressed as the depth of object is more than current max depth (' + QUnit.dump.maxDepth + ').<p>Hint: Use <code>QUnit.dump.maxDepth</code> to ' + " run with a higher max depth or <a href='" + escapeText(setUrl({ |
| 7250 |
maxDepth: 0 |
| 7251 |
})) + "'>" + 'Rerun without max depth</a>.</p></td></tr>'; |
| 7252 |
} else { |
| 7253 |
message += "<tr class='test-message'><th>Message: </th><td>" + 'Diff suppressed as the expected and actual results have an equivalent' + ' serialization</td></tr>'; |
| 7254 |
} |
| 7255 |
if (details.source) { |
| 7256 |
message += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText(details.source) + '</pre></td></tr>'; |
| 7257 |
} |
| 7258 |
message += '</table>'; |
| 7259 |
|
| 7260 |
// This occurs when pushFailure is set and we have an extracted stack trace |
| 7261 |
} else if (!details.result && details.source) { |
| 7262 |
message += '<table>' + "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText(details.source) + '</pre></td></tr>' + '</table>'; |
| 7263 |
} |
| 7264 |
var assertList = testItem.getElementsByTagName('ol')[0]; |
| 7265 |
var assertLi = document.createElement('li'); |
| 7266 |
assertLi.className = details.result ? 'pass' : 'fail'; |
| 7267 |
assertLi.innerHTML = message; |
| 7268 |
assertList.appendChild(assertLi); |
| 7269 |
}); |
| 7270 |
QUnit.testDone(function (details) { |
| 7271 |
var tests = id('qunit-tests'); |
| 7272 |
var testItem = id('qunit-test-output-' + details.testId); |
| 7273 |
if (!tests || !testItem) { |
| 7274 |
return; |
| 7275 |
} |
| 7276 |
removeClass(testItem, 'running'); |
| 7277 |
var status; |
| 7278 |
if (details.failed > 0) { |
| 7279 |
status = 'failed'; |
| 7280 |
} else if (details.todo) { |
| 7281 |
status = 'todo'; |
| 7282 |
} else { |
| 7283 |
status = details.skipped ? 'skipped' : 'passed'; |
| 7284 |
} |
| 7285 |
var assertList = testItem.getElementsByTagName('ol')[0]; |
| 7286 |
var good = details.passed; |
| 7287 |
var bad = details.failed; |
| 7288 |
|
| 7289 |
// This test passed if it has no unexpected failed assertions |
| 7290 |
var testPassed = details.failed > 0 ? details.todo : !details.todo; |
| 7291 |
if (testPassed) { |
| 7292 |
// Collapse the passing tests |
| 7293 |
addClass(assertList, 'qunit-collapsed'); |
| 7294 |
} else { |
| 7295 |
stats.failedTests.push(details.testId); |
| 7296 |
if (config.collapse) { |
| 7297 |
if (!collapseNext) { |
| 7298 |
// Skip collapsing the first failing test |
| 7299 |
collapseNext = true; |
| 7300 |
} else { |
| 7301 |
// Collapse remaining tests |
| 7302 |
addClass(assertList, 'qunit-collapsed'); |
| 7303 |
} |
| 7304 |
} |
| 7305 |
} |
| 7306 |
|
| 7307 |
// The testItem.firstChild is the test name |
| 7308 |
var testTitle = testItem.firstChild; |
| 7309 |
var testCounts = bad ? "<b class='failed'>" + bad + '</b>, ' + "<b class='passed'>" + good + '</b>, ' : ''; |
| 7310 |
testTitle.innerHTML += " <b class='counts'>(" + testCounts + details.assertions.length + ')</b>'; |
| 7311 |
stats.completed++; |
| 7312 |
if (details.skipped) { |
| 7313 |
testItem.className = 'skipped'; |
| 7314 |
var skipped = document.createElement('em'); |
| 7315 |
skipped.className = 'qunit-skipped-label'; |
| 7316 |
skipped.innerHTML = 'skipped'; |
| 7317 |
testItem.insertBefore(skipped, testTitle); |
| 7318 |
} else { |
| 7319 |
addEvent(testTitle, 'click', function () { |
| 7320 |
toggleClass(assertList, 'qunit-collapsed'); |
| 7321 |
}); |
| 7322 |
testItem.className = testPassed ? 'pass' : 'fail'; |
| 7323 |
if (details.todo) { |
| 7324 |
var todoLabel = document.createElement('em'); |
| 7325 |
todoLabel.className = 'qunit-todo-label'; |
| 7326 |
todoLabel.innerHTML = 'todo'; |
| 7327 |
testItem.className += ' todo'; |
| 7328 |
testItem.insertBefore(todoLabel, testTitle); |
| 7329 |
} |
| 7330 |
var time = document.createElement('span'); |
| 7331 |
time.className = 'runtime'; |
| 7332 |
time.innerHTML = details.runtime + ' ms'; |
| 7333 |
testItem.insertBefore(time, assertList); |
| 7334 |
} |
| 7335 |
|
| 7336 |
// Show the source of the test when showing assertions |
| 7337 |
if (details.source) { |
| 7338 |
var sourceName = document.createElement('p'); |
| 7339 |
sourceName.innerHTML = '<strong>Source: </strong>' + escapeText(details.source); |
| 7340 |
addClass(sourceName, 'qunit-source'); |
| 7341 |
if (testPassed) { |
| 7342 |
addClass(sourceName, 'qunit-collapsed'); |
| 7343 |
} |
| 7344 |
addEvent(testTitle, 'click', function () { |
| 7345 |
toggleClass(sourceName, 'qunit-collapsed'); |
| 7346 |
}); |
| 7347 |
testItem.appendChild(sourceName); |
| 7348 |
} |
| 7349 |
if (config.hidepassed && (status === 'passed' || details.skipped)) { |
| 7350 |
// use removeChild instead of remove because of support |
| 7351 |
hiddenTests.push(testItem); |
| 7352 |
tests.removeChild(testItem); |
| 7353 |
} |
| 7354 |
}); |
| 7355 |
QUnit.on('error', function (error) { |
| 7356 |
var testItem = appendTest('global failure'); |
| 7357 |
if (!testItem) { |
| 7358 |
// HTML Reporter is probably disabled or not yet initialized. |
| 7359 |
return; |
| 7360 |
} |
| 7361 |
|
| 7362 |
// Render similar to a failed assertion (see above QUnit.log callback) |
| 7363 |
var message = escapeText(errorString(error)); |
| 7364 |
message = "<span class='test-message'>" + message + '</span>'; |
| 7365 |
if (error && error.stack) { |
| 7366 |
message += '<table>' + "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText(error.stack) + '</pre></td></tr>' + '</table>'; |
| 7367 |
} |
| 7368 |
var assertList = testItem.getElementsByTagName('ol')[0]; |
| 7369 |
var assertLi = document.createElement('li'); |
| 7370 |
assertLi.className = 'fail'; |
| 7371 |
assertLi.innerHTML = message; |
| 7372 |
assertList.appendChild(assertLi); |
| 7373 |
|
| 7374 |
// Make it visible |
| 7375 |
testItem.className = 'fail'; |
| 7376 |
}); |
| 7377 |
|
| 7378 |
// Avoid readyState issue with phantomjs |
| 7379 |
// Ref: #818 |
| 7380 |
var usingPhantom = function (p) { |
| 7381 |
return p && p.version && p.version.major > 0; |
| 7382 |
}(window$1.phantom); |
| 7383 |
if (usingPhantom) { |
| 7384 |
console$1.warn('Support for PhantomJS is deprecated and will be removed in QUnit 3.0.'); |
| 7385 |
} |
| 7386 |
if (!usingPhantom && document.readyState === 'complete') { |
| 7387 |
QUnit.autostart(); |
| 7388 |
} else { |
| 7389 |
addEvent(window$1, 'load', QUnit.autostart); |
| 7390 |
} |
| 7391 |
|
| 7392 |
// Wrap window.onerror. We will call the original window.onerror to see if |
| 7393 |
// the existing handler fully handles the error; if not, we will call the |
| 7394 |
// QUnit.onError function. |
| 7395 |
var originalWindowOnError = window$1.onerror; |
| 7396 |
|
| 7397 |
// Cover uncaught exceptions |
| 7398 |
// Returning true will suppress the default browser handler, |
| 7399 |
// returning false will let it run. |
| 7400 |
window$1.onerror = function (message, fileName, lineNumber, columnNumber, errorObj) { |
| 7401 |
var ret = false; |
| 7402 |
if (originalWindowOnError) { |
| 7403 |
for (var _len = arguments.length, args = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++) { |
| 7404 |
args[_key - 5] = arguments[_key]; |
| 7405 |
} |
| 7406 |
ret = originalWindowOnError.call.apply(originalWindowOnError, [this, message, fileName, lineNumber, columnNumber, errorObj].concat(args)); |
| 7407 |
} |
| 7408 |
|
| 7409 |
// Treat return value as window.onerror itself does, |
| 7410 |
// Only do our handling if not suppressed. |
| 7411 |
if (ret !== true) { |
| 7412 |
// If there is a current test that sets the internal `ignoreGlobalErrors` field |
| 7413 |
// (such as during `assert.throws()`), then the error is ignored and native |
| 7414 |
// error reporting is suppressed as well. This is because in browsers, an error |
| 7415 |
// can sometimes end up in `window.onerror` instead of in the local try/catch. |
| 7416 |
// This ignoring of errors does not apply to our general onUncaughtException |
| 7417 |
// method, nor to our `unhandledRejection` handlers, as those are not meant |
| 7418 |
// to receive an "expected" error during `assert.throws()`. |
| 7419 |
if (config.current && config.current.ignoreGlobalErrors) { |
| 7420 |
return true; |
| 7421 |
} |
| 7422 |
|
| 7423 |
// According to |
| 7424 |
// https://blog.sentry.io/2016/01/04/client-javascript-reporting-window-onerror, |
| 7425 |
// most modern browsers support an errorObj argument; use that to |
| 7426 |
// get a full stack trace if it's available. |
| 7427 |
var error = errorObj || new Error(message); |
| 7428 |
if (!error.stack && fileName && lineNumber) { |
| 7429 |
error.stack = "".concat(fileName, ":").concat(lineNumber); |
| 7430 |
} |
| 7431 |
QUnit.onUncaughtException(error); |
| 7432 |
} |
| 7433 |
return ret; |
| 7434 |
}; |
| 7435 |
window$1.addEventListener('unhandledrejection', function (event) { |
| 7436 |
QUnit.onUncaughtException(event.reason); |
| 7437 |
}); |
| 7438 |
})(); |
| 7439 |
|
| 7440 |
})(); |