spectrum-colorpicker
Version:
Spectrum: the no hassle jQuery colorpicker
1,527 lines (1,228 loc) • 236 kB
JavaScript
/*!
* QUnit 2.10.0
* https://qunitjs.com/
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2020-05-02T22:51Z
*/
(function (global$1) {
'use strict';
global$1 = global$1 && global$1.hasOwnProperty('default') ? global$1['default'] : global$1;
var window$1 = global$1.window;
var self$1 = global$1.self;
var console = global$1.console;
var setTimeout$1 = global$1.setTimeout;
var clearTimeout = global$1.clearTimeout;
var document$1 = window$1 && window$1.document;
var navigator = window$1 && window$1.navigator;
var localSessionStorage = function () {
var x = "qunit-test-string";
try {
global$1.sessionStorage.setItem(x, x);
global$1.sessionStorage.removeItem(x);
return global$1.sessionStorage;
} catch (e) {
return undefined;
}
}();
/**
* Returns a function that proxies to the given method name on the globals
* console object. The proxy will also detect if the console doesn't exist and
* will appropriately no-op. This allows support for IE9, which doesn't have a
* console if the developer tools are not open.
*/
function consoleProxy(method) {
return function () {
if (console) {
console[method].apply(console, arguments);
}
};
}
var Logger = {
warn: consoleProxy("warn")
};
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
} else {
return Array.from(arr);
}
};
var toString = Object.prototype.toString;
var hasOwn = Object.prototype.hasOwnProperty;
var now = Date.now || function () {
return new Date().getTime();
};
var hasPerformanceApi = detectPerformanceApi();
var performance = hasPerformanceApi ? window$1.performance : undefined;
var performanceNow = hasPerformanceApi ? performance.now.bind(performance) : now;
function detectPerformanceApi() {
return window$1 && typeof window$1.performance !== "undefined" && typeof window$1.performance.mark === "function" && typeof window$1.performance.measure === "function";
}
function measure(comment, startMark, endMark) {
// `performance.measure` may fail if the mark could not be found.
// reasons a specific mark could not be found include: outside code invoking `performance.clearMarks()`
try {
performance.measure(comment, startMark, endMark);
} catch (ex) {
Logger.warn("performance.measure could not be executed because of ", ex.message);
}
}
var defined = {
document: window$1 && window$1.document !== undefined,
setTimeout: setTimeout$1 !== undefined
};
// Returns a new Array with the elements that are in a but not in b
function diff(a, b) {
var i,
j,
result = a.slice();
for (i = 0; i < result.length; i++) {
for (j = 0; j < b.length; j++) {
if (result[i] === b[j]) {
result.splice(i, 1);
i--;
break;
}
}
}
return result;
}
/**
* Determines whether an element exists in a given array or not.
*
* @method inArray
* @param {Any} elem
* @param {Array} array
* @return {Boolean}
*/
function inArray(elem, array) {
return array.indexOf(elem) !== -1;
}
/**
* Makes a clone of an object using only Array or Object as base,
* and copies over the own enumerable properties.
*
* @param {Object} obj
* @return {Object} New object with only the own properties (recursively).
*/
function objectValues(obj) {
var key,
val,
vals = is("array", obj) ? [] : {};
for (key in obj) {
if (hasOwn.call(obj, key)) {
val = obj[key];
vals[key] = val === Object(val) ? objectValues(val) : val;
}
}
return vals;
}
function extend(a, b, undefOnly) {
for (var prop in b) {
if (hasOwn.call(b, prop)) {
if (b[prop] === undefined) {
delete a[prop];
} else if (!(undefOnly && typeof a[prop] !== "undefined")) {
a[prop] = b[prop];
}
}
}
return a;
}
function objectType(obj) {
if (typeof obj === "undefined") {
return "undefined";
}
// Consider: typeof null === object
if (obj === null) {
return "null";
}
var match = toString.call(obj).match(/^\[object\s(.*)\]$/),
type = match && match[1];
switch (type) {
case "Number":
if (isNaN(obj)) {
return "nan";
}
return "number";
case "String":
case "Boolean":
case "Array":
case "Set":
case "Map":
case "Date":
case "RegExp":
case "Function":
case "Symbol":
return type.toLowerCase();
default:
return typeof obj === "undefined" ? "undefined" : _typeof(obj);
}
}
// Safe object type checking
function is(type, obj) {
return objectType(obj) === type;
}
// Based on Java's String.hashCode, a simple but not
// rigorously collision resistant hashing function
function generateHash(module, testName) {
var str = module + "\x1C" + testName;
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = (hash << 5) - hash + str.charCodeAt(i);
hash |= 0;
}
// Convert the possibly negative integer hash code into an 8 character hex string, which isn't
// strictly necessary but increases user understanding that the id is a SHA-like hash
var hex = (0x100000000 + hash).toString(16);
if (hex.length < 8) {
hex = "0000000" + hex;
}
return hex.slice(-8);
}
// Test for equality any JavaScript type.
// Authors: Philippe Rathé <prathe@gmail.com>, David Chan <david@troi.org>
var equiv = (function () {
// Value pairs queued for comparison. Used for breadth-first processing order, recursion
// detection and avoiding repeated comparison (see below for details).
// Elements are { a: val, b: val }.
var pairs = [];
var getProto = Object.getPrototypeOf || function (obj) {
return obj.__proto__;
};
function useStrictEquality(a, b) {
// This only gets called if a and b are not strict equal, and is used to compare on
// the primitive values inside object wrappers. For example:
// `var i = 1;`
// `var j = new Number(1);`
// Neither a nor b can be null, as a !== b and they have the same type.
if ((typeof a === "undefined" ? "undefined" : _typeof(a)) === "object") {
a = a.valueOf();
}
if ((typeof b === "undefined" ? "undefined" : _typeof(b)) === "object") {
b = b.valueOf();
}
return a === b;
}
function compareConstructors(a, b) {
var protoA = getProto(a);
var protoB = getProto(b);
// Comparing constructors is more strict than using `instanceof`
if (a.constructor === b.constructor) {
return true;
}
// Ref #851
// If the obj prototype descends from a null constructor, treat it
// as a null prototype.
if (protoA && protoA.constructor === null) {
protoA = null;
}
if (protoB && protoB.constructor === null) {
protoB = null;
}
// Allow objects with no prototype to be equivalent to
// objects with Object as their constructor.
if (protoA === null && protoB === Object.prototype || protoB === null && protoA === Object.prototype) {
return true;
}
return false;
}
function getRegExpFlags(regexp) {
return "flags" in regexp ? regexp.flags : regexp.toString().match(/[gimuy]*$/)[0];
}
function isContainer(val) {
return ["object", "array", "map", "set"].indexOf(objectType(val)) !== -1;
}
function breadthFirstCompareChild(a, b) {
// If a is a container not reference-equal to b, postpone the comparison to the
// end of the pairs queue -- unless (a, b) has been seen before, in which case skip
// over the pair.
if (a === b) {
return true;
}
if (!isContainer(a)) {
return typeEquiv(a, b);
}
if (pairs.every(function (pair) {
return pair.a !== a || pair.b !== b;
})) {
// Not yet started comparing this pair
pairs.push({ a: a, b: b });
}
return true;
}
var callbacks = {
"string": useStrictEquality,
"boolean": useStrictEquality,
"number": useStrictEquality,
"null": useStrictEquality,
"undefined": useStrictEquality,
"symbol": useStrictEquality,
"date": useStrictEquality,
"nan": function nan() {
return true;
},
"regexp": function regexp(a, b) {
return a.source === b.source &&
// Include flags in the comparison
getRegExpFlags(a) === getRegExpFlags(b);
},
// abort (identical references / instance methods were skipped earlier)
"function": function _function() {
return false;
},
"array": function array(a, b) {
var i, len;
len = a.length;
if (len !== b.length) {
// Safe and faster
return false;
}
for (i = 0; i < len; i++) {
// Compare non-containers; queue non-reference-equal containers
if (!breadthFirstCompareChild(a[i], b[i])) {
return false;
}
}
return true;
},
// Define sets a and b to be equivalent if for each element aVal in a, there
// is some element bVal in b such that aVal and bVal are equivalent. Element
// repetitions are not counted, so these are equivalent:
// a = new Set( [ {}, [], [] ] );
// b = new Set( [ {}, {}, [] ] );
"set": function set$$1(a, b) {
var innerEq,
outerEq = true;
if (a.size !== b.size) {
// This optimization has certain quirks because of the lack of
// repetition counting. For instance, adding the same
// (reference-identical) element to two equivalent sets can
// make them non-equivalent.
return false;
}
a.forEach(function (aVal) {
// Short-circuit if the result is already known. (Using for...of
// with a break clause would be cleaner here, but it would cause
// a syntax error on older Javascript implementations even if
// Set is unused)
if (!outerEq) {
return;
}
innerEq = false;
b.forEach(function (bVal) {
var parentPairs;
// Likewise, short-circuit if the result is already known
if (innerEq) {
return;
}
// Swap out the global pairs list, as the nested call to
// innerEquiv will clobber its contents
parentPairs = pairs;
if (innerEquiv(bVal, aVal)) {
innerEq = true;
}
// Replace the global pairs list
pairs = parentPairs;
});
if (!innerEq) {
outerEq = false;
}
});
return outerEq;
},
// Define maps a and b to be equivalent if for each key-value pair (aKey, aVal)
// in a, there is some key-value pair (bKey, bVal) in b such that
// [ aKey, aVal ] and [ bKey, bVal ] are equivalent. Key repetitions are not
// counted, so these are equivalent:
// a = new Map( [ [ {}, 1 ], [ {}, 1 ], [ [], 1 ] ] );
// b = new Map( [ [ {}, 1 ], [ [], 1 ], [ [], 1 ] ] );
"map": function map(a, b) {
var innerEq,
outerEq = true;
if (a.size !== b.size) {
// This optimization has certain quirks because of the lack of
// repetition counting. For instance, adding the same
// (reference-identical) key-value pair to two equivalent maps
// can make them non-equivalent.
return false;
}
a.forEach(function (aVal, aKey) {
// Short-circuit if the result is already known. (Using for...of
// with a break clause would be cleaner here, but it would cause
// a syntax error on older Javascript implementations even if
// Map is unused)
if (!outerEq) {
return;
}
innerEq = false;
b.forEach(function (bVal, bKey) {
var parentPairs;
// Likewise, short-circuit if the result is already known
if (innerEq) {
return;
}
// Swap out the global pairs list, as the nested call to
// innerEquiv will clobber its contents
parentPairs = pairs;
if (innerEquiv([bVal, bKey], [aVal, aKey])) {
innerEq = true;
}
// Replace the global pairs list
pairs = parentPairs;
});
if (!innerEq) {
outerEq = false;
}
});
return outerEq;
},
"object": function object(a, b) {
var i,
aProperties = [],
bProperties = [];
if (compareConstructors(a, b) === false) {
return false;
}
// Be strict: don't ensure hasOwnProperty and go deep
for (i in a) {
// Collect a's properties
aProperties.push(i);
// Skip OOP methods that look the same
if (a.constructor !== Object && typeof a.constructor !== "undefined" && typeof a[i] === "function" && typeof b[i] === "function" && a[i].toString() === b[i].toString()) {
continue;
}
// Compare non-containers; queue non-reference-equal containers
if (!breadthFirstCompareChild(a[i], b[i])) {
return false;
}
}
for (i in b) {
// Collect b's properties
bProperties.push(i);
}
// Ensures identical properties name
return typeEquiv(aProperties.sort(), bProperties.sort());
}
};
function typeEquiv(a, b) {
var type = objectType(a);
// Callbacks for containers will append to the pairs queue to achieve breadth-first
// search order. The pairs queue is also used to avoid reprocessing any pair of
// containers that are reference-equal to a previously visited pair (a special case
// this being recursion detection).
//
// Because of this approach, once typeEquiv returns a false value, it should not be
// called again without clearing the pair queue else it may wrongly report a visited
// pair as being equivalent.
return objectType(b) === type && callbacks[type](a, b);
}
function innerEquiv(a, b) {
var i, pair;
// We're done when there's nothing more to compare
if (arguments.length < 2) {
return true;
}
// Clear the global pair queue and add the top-level values being compared
pairs = [{ a: a, b: b }];
for (i = 0; i < pairs.length; i++) {
pair = pairs[i];
// Perform type-specific comparison on any pairs that are not strictly
// equal. For container types, that comparison will postpone comparison
// of any sub-container pair to the end of the pair queue. This gives
// breadth-first search order. It also avoids the reprocessing of
// reference-equal siblings, cousins etc, which can have a significant speed
// impact when comparing a container of small objects each of which has a
// reference to the same (singleton) large object.
if (pair.a !== pair.b && !typeEquiv(pair.a, pair.b)) {
return false;
}
}
// ...across all consecutive argument pairs
return arguments.length === 2 || innerEquiv.apply(this, [].slice.call(arguments, 1));
}
return function () {
var result = innerEquiv.apply(undefined, arguments);
// Release any retained objects
pairs.length = 0;
return result;
};
})();
/**
* Config object: Maintain internal state
* Later exposed as QUnit.config
* `config` initialized at top of scope
*/
var config = {
// The queue of tests to run
queue: [],
// Block until document ready
blocking: true,
// By default, run previously failed tests first
// very useful in combination with "Hide passed tests" checked
reorder: true,
// By default, modify document.title when suite is done
altertitle: true,
// HTML Reporter: collapse every test except the first failing test
// If false, all failing tests will be expanded
collapse: true,
// By default, scroll to top of the page when suite is done
scrolltop: true,
// Depth up-to which object will be dumped
maxDepth: 5,
// When enabled, all tests must call expect()
requireExpects: false,
// Placeholder for user-configurable form-exposed URL parameters
urlConfig: [],
// Set of all modules.
modules: [],
// The first unnamed module
currentModule: {
name: "",
tests: [],
childModules: [],
testsRun: 0,
unskippedTestsRun: 0,
hooks: {
before: [],
beforeEach: [],
afterEach: [],
after: []
}
},
callbacks: {},
// The storage module to use for reordering tests
storage: localSessionStorage
};
// take a predefined QUnit.config and extend the defaults
var globalConfig = window$1 && window$1.QUnit && window$1.QUnit.config;
// only extend the global config if there is no QUnit overload
if (window$1 && window$1.QUnit && !window$1.QUnit.version) {
extend(config, globalConfig);
}
// Push a loose unnamed module to the modules collection
config.modules.push(config.currentModule);
// Based on jsDump by Ariel Flesler
// http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html
var dump = (function () {
function quote(str) {
return "\"" + str.toString().replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\"";
}
function literal(o) {
return o + "";
}
function join(pre, arr, post) {
var s = dump.separator(),
base = dump.indent(),
inner = dump.indent(1);
if (arr.join) {
arr = arr.join("," + s + inner);
}
if (!arr) {
return pre + post;
}
return [pre, inner + arr, base + post].join(s);
}
function array(arr, stack) {
var i = arr.length,
ret = new Array(i);
if (dump.maxDepth && dump.depth > dump.maxDepth) {
return "[object Array]";
}
this.up();
while (i--) {
ret[i] = this.parse(arr[i], undefined, stack);
}
this.down();
return join("[", ret, "]");
}
function isArray(obj) {
return (
//Native Arrays
toString.call(obj) === "[object Array]" ||
// NodeList objects
typeof obj.length === "number" && obj.item !== undefined && (obj.length ? obj.item(0) === obj[0] : obj.item(0) === null && obj[0] === undefined)
);
}
var reName = /^function (\w+)/,
dump = {
// The objType is used mostly internally, you can fix a (custom) type in advance
parse: function parse(obj, objType, stack) {
stack = stack || [];
var res,
parser,
parserType,
objIndex = stack.indexOf(obj);
if (objIndex !== -1) {
return "recursion(" + (objIndex - stack.length) + ")";
}
objType = objType || this.typeOf(obj);
parser = this.parsers[objType];
parserType = typeof parser === "undefined" ? "undefined" : _typeof(parser);
if (parserType === "function") {
stack.push(obj);
res = parser.call(this, obj, stack);
stack.pop();
return res;
}
return parserType === "string" ? parser : this.parsers.error;
},
typeOf: function typeOf(obj) {
var type;
if (obj === null) {
type = "null";
} else if (typeof obj === "undefined") {
type = "undefined";
} else if (is("regexp", obj)) {
type = "regexp";
} else if (is("date", obj)) {
type = "date";
} else if (is("function", obj)) {
type = "function";
} else if (obj.setInterval !== undefined && obj.document !== undefined && obj.nodeType === undefined) {
type = "window";
} else if (obj.nodeType === 9) {
type = "document";
} else if (obj.nodeType) {
type = "node";
} else if (isArray(obj)) {
type = "array";
} else if (obj.constructor === Error.prototype.constructor) {
type = "error";
} else {
type = typeof obj === "undefined" ? "undefined" : _typeof(obj);
}
return type;
},
separator: function separator() {
if (this.multiline) {
return this.HTML ? "<br />" : "\n";
} else {
return this.HTML ? " " : " ";
}
},
// Extra can be a number, shortcut for increasing-calling-decreasing
indent: function indent(extra) {
if (!this.multiline) {
return "";
}
var chr = this.indentChar;
if (this.HTML) {
chr = chr.replace(/\t/g, " ").replace(/ /g, " ");
}
return new Array(this.depth + (extra || 0)).join(chr);
},
up: function up(a) {
this.depth += a || 1;
},
down: function down(a) {
this.depth -= a || 1;
},
setParser: function setParser(name, parser) {
this.parsers[name] = parser;
},
// The next 3 are exposed so you can use them
quote: quote,
literal: literal,
join: join,
depth: 1,
maxDepth: config.maxDepth,
// This is the list of parsers, to modify them, use dump.setParser
parsers: {
window: "[Window]",
document: "[Document]",
error: function error(_error) {
return "Error(\"" + _error.message + "\")";
},
unknown: "[Unknown]",
"null": "null",
"undefined": "undefined",
"function": function _function(fn) {
var ret = "function",
// Functions never have name in IE
name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];
if (name) {
ret += " " + name;
}
ret += "(";
ret = [ret, dump.parse(fn, "functionArgs"), "){"].join("");
return join(ret, dump.parse(fn, "functionCode"), "}");
},
array: array,
nodelist: array,
"arguments": array,
object: function object(map, stack) {
var keys,
key,
val,
i,
nonEnumerableProperties,
ret = [];
if (dump.maxDepth && dump.depth > dump.maxDepth) {
return "[object Object]";
}
dump.up();
keys = [];
for (key in map) {
keys.push(key);
}
// Some properties are not always enumerable on Error objects.
nonEnumerableProperties = ["message", "name"];
for (i in nonEnumerableProperties) {
key = nonEnumerableProperties[i];
if (key in map && !inArray(key, keys)) {
keys.push(key);
}
}
keys.sort();
for (i = 0; i < keys.length; i++) {
key = keys[i];
val = map[key];
ret.push(dump.parse(key, "key") + ": " + dump.parse(val, undefined, stack));
}
dump.down();
return join("{", ret, "}");
},
node: function node(_node) {
var len,
i,
val,
open = dump.HTML ? "<" : "<",
close = dump.HTML ? ">" : ">",
tag = _node.nodeName.toLowerCase(),
ret = open + tag,
attrs = _node.attributes;
if (attrs) {
for (i = 0, len = attrs.length; i < len; i++) {
val = attrs[i].nodeValue;
// IE6 includes all attributes in .attributes, even ones not explicitly
// set. Those have values like undefined, null, 0, false, "" or
// "inherit".
if (val && val !== "inherit") {
ret += " " + attrs[i].nodeName + "=" + dump.parse(val, "attribute");
}
}
}
ret += close;
// Show content of TextNode or CDATASection
if (_node.nodeType === 3 || _node.nodeType === 4) {
ret += _node.nodeValue;
}
return ret + open + "/" + tag + close;
},
// Function calls it internally, it's the arguments part of the function
functionArgs: function functionArgs(fn) {
var args,
l = fn.length;
if (!l) {
return "";
}
args = new Array(l);
while (l--) {
// 97 is 'a'
args[l] = String.fromCharCode(97 + l);
}
return " " + args.join(", ") + " ";
},
// Object calls it internally, the key part of an item in a map
key: quote,
// Function calls it internally, it's the content of the function
functionCode: "[code]",
// Node calls it internally, it's a html attribute value
attribute: quote,
string: quote,
date: quote,
regexp: literal,
number: literal,
"boolean": literal,
symbol: function symbol(sym) {
return sym.toString();
}
},
// If true, entities are escaped ( <, >, \t, space and \n )
HTML: false,
// Indentation unit
indentChar: " ",
// If true, items in a collection, are separated by a \n, else just a space.
multiline: true
};
return dump;
})();
var SuiteReport = function () {
function SuiteReport(name, parentSuite) {
classCallCheck(this, SuiteReport);
this.name = name;
this.fullName = parentSuite ? parentSuite.fullName.concat(name) : [];
this.tests = [];
this.childSuites = [];
if (parentSuite) {
parentSuite.pushChildSuite(this);
}
}
createClass(SuiteReport, [{
key: "start",
value: function start(recordTime) {
if (recordTime) {
this._startTime = performanceNow();
if (performance) {
var suiteLevel = this.fullName.length;
performance.mark("qunit_suite_" + suiteLevel + "_start");
}
}
return {
name: this.name,
fullName: this.fullName.slice(),
tests: this.tests.map(function (test) {
return test.start();
}),
childSuites: this.childSuites.map(function (suite) {
return suite.start();
}),
testCounts: {
total: this.getTestCounts().total
}
};
}
}, {
key: "end",
value: function end(recordTime) {
if (recordTime) {
this._endTime = performanceNow();
if (performance) {
var suiteLevel = this.fullName.length;
performance.mark("qunit_suite_" + suiteLevel + "_end");
var suiteName = this.fullName.join(" – ");
measure(suiteLevel === 0 ? "QUnit Test Run" : "QUnit Test Suite: " + suiteName, "qunit_suite_" + suiteLevel + "_start", "qunit_suite_" + suiteLevel + "_end");
}
}
return {
name: this.name,
fullName: this.fullName.slice(),
tests: this.tests.map(function (test) {
return test.end();
}),
childSuites: this.childSuites.map(function (suite) {
return suite.end();
}),
testCounts: this.getTestCounts(),
runtime: this.getRuntime(),
status: this.getStatus()
};
}
}, {
key: "pushChildSuite",
value: function pushChildSuite(suite) {
this.childSuites.push(suite);
}
}, {
key: "pushTest",
value: function pushTest(test) {
this.tests.push(test);
}
}, {
key: "getRuntime",
value: function getRuntime() {
return this._endTime - this._startTime;
}
}, {
key: "getTestCounts",
value: function getTestCounts() {
var counts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { passed: 0, failed: 0, skipped: 0, todo: 0, total: 0 };
counts = this.tests.reduce(function (counts, test) {
if (test.valid) {
counts[test.getStatus()]++;
counts.total++;
}
return counts;
}, counts);
return this.childSuites.reduce(function (counts, suite) {
return suite.getTestCounts(counts);
}, counts);
}
}, {
key: "getStatus",
value: function getStatus() {
var _getTestCounts = this.getTestCounts(),
total = _getTestCounts.total,
failed = _getTestCounts.failed,
skipped = _getTestCounts.skipped,
todo = _getTestCounts.todo;
if (failed) {
return "failed";
} else {
if (skipped === total) {
return "skipped";
} else if (todo === total) {
return "todo";
} else {
return "passed";
}
}
}
}]);
return SuiteReport;
}();
var focused = false;
var moduleStack = [];
function isParentModuleInQueue() {
var modulesInQueue = config.modules.map(function (module) {
return module.moduleId;
});
return moduleStack.some(function (module) {
return modulesInQueue.includes(module.moduleId);
});
}
function createModule(name, testEnvironment, modifiers) {
var parentModule = moduleStack.length ? moduleStack.slice(-1)[0] : null;
var moduleName = parentModule !== null ? [parentModule.name, name].join(" > ") : name;
var parentSuite = parentModule ? parentModule.suiteReport : globalSuite;
var skip = parentModule !== null && parentModule.skip || modifiers.skip;
var todo = parentModule !== null && parentModule.todo || modifiers.todo;
var module = {
name: moduleName,
parentModule: parentModule,
tests: [],
moduleId: generateHash(moduleName),
testsRun: 0,
unskippedTestsRun: 0,
childModules: [],
suiteReport: new SuiteReport(name, parentSuite),
// Pass along `skip` and `todo` properties from parent module, in case
// there is one, to childs. And use own otherwise.
// This property will be used to mark own tests and tests of child suites
// as either `skipped` or `todo`.
skip: skip,
todo: skip ? false : todo
};
var env = {};
if (parentModule) {
parentModule.childModules.push(module);
extend(env, parentModule.testEnvironment);
}
extend(env, testEnvironment);
module.testEnvironment = env;
config.modules.push(module);
return module;
}
function processModule(name, options, executeNow) {
var modifiers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
if (objectType(options) === "function") {
executeNow = options;
options = undefined;
}
var module = createModule(name, options, modifiers);
// Move any hooks to a 'hooks' object
var testEnvironment = module.testEnvironment;
var hooks = module.hooks = {};
setHookFromEnvironment(hooks, testEnvironment, "before");
setHookFromEnvironment(hooks, testEnvironment, "beforeEach");
setHookFromEnvironment(hooks, testEnvironment, "afterEach");
setHookFromEnvironment(hooks, testEnvironment, "after");
var moduleFns = {
before: setHookFunction(module, "before"),
beforeEach: setHookFunction(module, "beforeEach"),
afterEach: setHookFunction(module, "afterEach"),
after: setHookFunction(module, "after")
};
var currentModule = config.currentModule;
if (objectType(executeNow) === "function") {
moduleStack.push(module);
config.currentModule = module;
executeNow.call(module.testEnvironment, moduleFns);
moduleStack.pop();
module = module.parentModule || currentModule;
}
config.currentModule = module;
function setHookFromEnvironment(hooks, environment, name) {
var potentialHook = environment[name];
hooks[name] = typeof potentialHook === "function" ? [potentialHook] : [];
delete environment[name];
}
function setHookFunction(module, hookName) {
return function setHook(callback) {
module.hooks[hookName].push(callback);
};
}
}
function module$1(name, options, executeNow) {
if (focused && !isParentModuleInQueue()) {
return;
}
processModule(name, options, executeNow);
}
module$1.only = function () {
if (!focused) {
config.modules.length = 0;
config.queue.length = 0;
}
processModule.apply(undefined, arguments);
focused = true;
};
module$1.skip = function (name, options, executeNow) {
if (focused) {
return;
}
processModule(name, options, executeNow, { skip: true });
};
module$1.todo = function (name, options, executeNow) {
if (focused) {
return;
}
processModule(name, options, executeNow, { todo: true });
};
var LISTENERS = Object.create(null);
var SUPPORTED_EVENTS = ["runStart", "suiteStart", "testStart", "assertion", "testEnd", "suiteEnd", "runEnd"];
/**
* Emits an event with the specified data to all currently registered listeners.
* Callbacks will fire in the order in which they are registered (FIFO). This
* function is not exposed publicly; it is used by QUnit internals to emit
* logging events.
*
* @private
* @method emit
* @param {String} eventName
* @param {Object} data
* @return {Void}
*/
function emit(eventName, data) {
if (objectType(eventName) !== "string") {
throw new TypeError("eventName must be a string when emitting an event");
}
// Clone the callbacks in case one of them registers a new callback
var originalCallbacks = LISTENERS[eventName];
var callbacks = originalCallbacks ? [].concat(toConsumableArray(originalCallbacks)) : [];
for (var i = 0; i < callbacks.length; i++) {
callbacks[i](data);
}
}
/**
* Registers a callback as a listener to the specified event.
*
* @public
* @method on
* @param {String} eventName
* @param {Function} callback
* @return {Void}
*/
function on(eventName, callback) {
if (objectType(eventName) !== "string") {
throw new TypeError("eventName must be a string when registering a listener");
} else if (!inArray(eventName, SUPPORTED_EVENTS)) {
var events = SUPPORTED_EVENTS.join(", ");
throw new Error("\"" + eventName + "\" is not a valid event; must be one of: " + events + ".");
} else if (objectType(callback) !== "function") {
throw new TypeError("callback must be a function when registering a listener");
}
if (!LISTENERS[eventName]) {
LISTENERS[eventName] = [];
}
// Don't register the same callback more than once
if (!inArray(callback, LISTENERS[eventName])) {
LISTENERS[eventName].push(callback);
}
}
function objectOrFunction(x) {
var type = typeof x === 'undefined' ? 'undefined' : _typeof(x);
return x !== null && (type === 'object' || type === 'function');
}
function isFunction(x) {
return typeof x === 'function';
}
var _isArray = void 0;
if (Array.isArray) {
_isArray = Array.isArray;
} else {
_isArray = function _isArray(x) {
return Object.prototype.toString.call(x) === '[object Array]';
};
}
var isArray = _isArray;
var len = 0;
var vertxNext = void 0;
var customSchedulerFn = void 0;
var asap = function asap(callback, arg) {
queue[len] = callback;
queue[len + 1] = arg;
len += 2;
if (len === 2) {
// If len is 2, that means that we need to schedule an async flush.
// If additional callbacks are queued before the queue is flushed, they
// will be processed by this flush that we are scheduling.
if (customSchedulerFn) {
customSchedulerFn(flush);
} else {
scheduleFlush();
}
}
};
function setScheduler(scheduleFn) {
customSchedulerFn = scheduleFn;
}
function setAsap(asapFn) {
asap = asapFn;
}
var browserWindow = typeof window !== 'undefined' ? window : undefined;
var browserGlobal = browserWindow || {};
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
// test for web worker but not in IE10
var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
// node
function useNextTick() {
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
// see https://github.com/cujojs/when/issues/410 for details
return function () {
return process.nextTick(flush);
};
}
// vertx
function useVertxTimer() {
if (typeof vertxNext !== 'undefined') {
return function () {
vertxNext(flush);
};
}
return useSetTimeout();
}
function useMutationObserver() {
var iterations = 0;
var observer = new BrowserMutationObserver(flush);
var node = document.createTextNode('');
observer.observe(node, { characterData: true });
return function () {
node.data = iterations = ++iterations % 2;
};
}
// web worker
function useMessageChannel() {
var channel = new MessageChannel();
channel.port1.onmessage = flush;
return function () {
return channel.port2.postMessage(0);
};
}
function useSetTimeout() {
// Store setTimeout reference so es6-promise will be unaffected by
// other code modifying setTimeout (like sinon.useFakeTimers())
var globalSetTimeout = setTimeout;
return function () {
return globalSetTimeout(flush, 1);
};
}
var queue = new Array(1000);
function flush() {
for (var i = 0; i < len; i += 2) {
var callback = queue[i];
var arg = queue[i + 1];
callback(arg);
queue[i] = undefined;
queue[i + 1] = undefined;
}
len = 0;
}
function attemptVertx() {
try {
var vertx = Function('return this')().require('vertx');
vertxNext = vertx.runOnLoop || vertx.runOnContext;
return useVertxTimer();
} catch (e) {
return useSetTimeout();
}
}
var scheduleFlush = void 0;
// Decide what async method to use to triggering processing of queued callbacks:
if (isNode) {
scheduleFlush = useNextTick();
} else if (BrowserMutationObserver) {
scheduleFlush = useMutationObserver();
} else if (isWorker) {
scheduleFlush = useMessageChannel();
} else if (browserWindow === undefined && typeof require === 'function') {
scheduleFlush = attemptVertx();
} else {
scheduleFlush = useSetTimeout();
}
function then(onFulfillment, onRejection) {
var parent = this;
var child = new this.constructor(noop);
if (child[PROMISE_ID] === undefined) {
makePromise(child);
}
var _state = parent._state;
if (_state) {
var callback = arguments[_state - 1];
asap(function () {
return invokeCallback(_state, child, callback, parent._result);
});
} else {
subscribe(parent, child, onFulfillment, onRejection);
}
return child;
}
/**
`Promise.resolve` returns a promise that will become resolved with the
passed `value`. It is shorthand for the following:
```javascript
let promise = new Promise(function(resolve, reject){
resolve(1);
});
promise.then(function(value){
// value === 1
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
let promise = Promise.resolve(1);
promise.then(function(value){
// value === 1
});
```
@method resolve
@static
@param {Any} value value that the returned promise will be resolved with
Useful for tooling.
@return {Promise} a promise that will become fulfilled with the given
`value`
*/
function resolve$1(object) {
/*jshint validthis:true */
var Constructor = this;
if (object && (typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object' && object.constructor === Constructor) {
return object;
}
var promise = new Constructor(noop);
resolve(promise, object);
return promise;
}
var PROMIS