vexflow
Version:
A JavaScript library for rendering music notation and guitar tablature.
1,349 lines (1,348 loc) • 245 kB
JavaScript
"use strict";
(function () {
'use strict';
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a 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);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps)
_defineProperties(Constructor.prototype, protoProps);
if (staticProps)
_defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr))
return _arrayLikeToArray(arr);
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr))
return arr;
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
return Array.from(iter);
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null)
return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i)
break;
}
}
catch (err) {
_d = true;
_e = err;
}
finally {
try {
if (!_n && _i["return"] != null)
_i["return"]();
}
finally {
if (_d)
throw _e;
}
}
return _arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o)
return;
if (typeof o === "string")
return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor)
n = o.constructor.name;
if (n === "Map" || n === "Set")
return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length)
len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++)
arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _createForOfIteratorHelper(o, allowArrayLike) {
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (!it) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it)
o = it;
var i = 0;
var F = function () { };
return {
s: F,
n: function () {
if (i >= o.length)
return {
done: true
};
return {
done: false,
value: o[i++]
};
},
e: function (e) {
throw e;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var normalCompletion = true, didErr = false, err;
return {
s: function () {
it = it.call(o);
},
n: function () {
var step = it.next();
normalCompletion = step.done;
return step;
},
e: function (e) {
didErr = true;
err = e;
},
f: function () {
try {
if (!normalCompletion && it.return != null)
it.return();
}
finally {
if (didErr)
throw err;
}
}
};
}
function getGlobalThis() {
if (typeof globalThis !== 'undefined') {
return globalThis;
}
if (typeof self !== 'undefined') {
return self;
}
if (typeof window$1 !== 'undefined') {
return window$1;
}
if (typeof global !== 'undefined') {
return global;
}
throw new Error('Unable to locate global object');
}
var g = getGlobalThis();
var window$1 = g.window;
var console$1 = g.console;
var setTimeout$1 = g.setTimeout;
var clearTimeout = g.clearTimeout;
var document = window$1 && window$1.document;
var navigator = window$1 && window$1.navigator;
var localSessionStorage = function () {
var x = 'qunit-test-string';
try {
g.sessionStorage.setItem(x, x);
g.sessionStorage.removeItem(x);
return g.sessionStorage;
}
catch (e) {
return undefined;
}
}();
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) {
var _this = this;
var store = Object.create(null);
var hasOwn = Object.prototype.hasOwnProperty;
this.has = function (strKey) {
return hasOwn.call(store, strKey);
};
this.get = function (strKey) {
return store[strKey];
};
this.set = function (strKey, val) {
if (!hasOwn.call(store, strKey)) {
this.size++;
}
store[strKey] = val;
return this;
};
this.delete = function (strKey) {
if (hasOwn.call(store, strKey)) {
delete store[strKey];
this.size--;
}
};
this.forEach = function (callback) {
for (var strKey in store) {
callback(store[strKey], strKey);
}
};
this.keys = function () {
return Object.keys(store);
};
this.clear = function () {
store = Object.create(null);
this.size = 0;
};
this.size = 0;
if (input) {
input.forEach(function (val, strKey) {
_this.set(strKey, val);
});
}
};
var StringSet = typeof g.Set === 'function' && typeof g.Set.prototype.values === 'function' ? g.Set : function (input) {
var set = Object.create(null);
if (Array.isArray(input)) {
input.forEach(function (item) {
set[item] = true;
});
}
return {
add: function add(value) {
set[value] = true;
},
has: function has(value) {
return value in set;
},
get size() {
return Object.keys(set).length;
}
};
};
var toString = Object.prototype.toString;
var hasOwn$1 = Object.prototype.hasOwnProperty;
var performance = {
now: window$1 && window$1.performance && window$1.performance.now ? window$1.performance.now.bind(window$1.performance) : Date.now
};
function diff(a, b) {
return a.filter(function (a) {
return b.indexOf(a) === -1;
});
}
var inArray = Array.prototype.includes ? function (elem, array) {
return array.includes(elem);
} : function (elem, array) {
return array.indexOf(elem) !== -1;
};
function objectValues(obj) {
var allowArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var vals = allowArray && is('array', obj) ? [] : {};
for (var key in obj) {
if (hasOwn$1.call(obj, key)) {
var val = obj[key];
vals[key] = val === Object(val) ? objectValues(val, allowArray) : val;
}
}
return vals;
}
function objectValuesSubset(obj, model) {
if (obj !== Object(obj)) {
return obj;
}
var subset = {};
for (var key in model) {
if (hasOwn$1.call(model, key) && hasOwn$1.call(obj, key)) {
subset[key] = objectValuesSubset(obj[key], model[key]);
}
}
return subset;
}
function extend(a, b, undefOnly) {
for (var prop in b) {
if (hasOwn$1.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';
}
if (obj === null) {
return 'null';
}
var match = toString.call(obj).match(/^\[object\s(.*)\]$/);
var 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);
}
}
function is(type, obj) {
return objectType(obj) === type;
}
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;
}
var hex = (0x100000000 + hash).toString(16);
if (hex.length < 8) {
hex = '0000000' + hex;
}
return hex.slice(-8);
}
function errorString(error) {
var resultErrorString = String(error);
if (resultErrorString.slice(0, 7) === '[object') {
return (error.name || 'Error') + (error.message ? ": ".concat(error.message) : '');
}
else {
return resultErrorString;
}
}
var BOXABLE_TYPES = new StringSet(['boolean', 'number', 'string']);
var memory = [];
function useStrictEquality(a, b) {
return a === b;
}
function useObjectValueEquality(a, b) {
return a === b || a.valueOf() === b.valueOf();
}
function compareConstructors(a, b) {
return getConstructor(a) === getConstructor(b);
}
function getConstructor(obj) {
var proto = Object.getPrototypeOf(obj);
return !proto || proto.constructor === null ? Object : obj.constructor;
}
function getRegExpFlags(regexp) {
return 'flags' in regexp ? regexp.flags : regexp.toString().match(/[gimuy]*$/)[0];
}
var objTypeCallbacks = {
undefined: useStrictEquality,
null: useStrictEquality,
boolean: useObjectValueEquality,
number: function number(a, b) {
return a === b || a.valueOf() === b.valueOf() || isNaN(a.valueOf()) && isNaN(b.valueOf());
},
string: useObjectValueEquality,
symbol: useStrictEquality,
date: useObjectValueEquality,
nan: function nan() {
return true;
},
regexp: function regexp(a, b) {
return a.source === b.source &&
getRegExpFlags(a) === getRegExpFlags(b);
},
function: useStrictEquality,
array: function array(a, b) {
if (a.length !== b.length) {
return false;
}
for (var i = 0; i < a.length; i++) {
if (!typeEquiv(a[i], b[i])) {
return false;
}
}
return true;
},
set: function set(a, b) {
if (a.size !== b.size) {
return false;
}
var outerEq = true;
a.forEach(function (aVal) {
if (!outerEq) {
return;
}
var innerEq = false;
b.forEach(function (bVal) {
if (innerEq) {
return;
}
var originalMemory = memory;
memory = [];
if (typeEquiv(bVal, aVal)) {
innerEq = true;
}
memory = originalMemory;
});
if (!innerEq) {
outerEq = false;
}
});
return outerEq;
},
map: function map(a, b) {
if (a.size !== b.size) {
return false;
}
var outerEq = true;
a.forEach(function (aVal, aKey) {
if (!outerEq) {
return;
}
var innerEq = false;
b.forEach(function (bVal, bKey) {
if (innerEq) {
return;
}
var originalMemory = memory;
memory = [];
if (objTypeCallbacks.array([bVal, bKey], [aVal, aKey])) {
innerEq = true;
}
memory = originalMemory;
});
if (!innerEq) {
outerEq = false;
}
});
return outerEq;
}
};
var entryTypeCallbacks = {
undefined: useStrictEquality,
null: useStrictEquality,
boolean: useStrictEquality,
number: function number(a, b) {
return a === b || isNaN(a) && isNaN(b);
},
string: useStrictEquality,
symbol: useStrictEquality,
function: useStrictEquality,
object: function object(a, b) {
if (memory.some(function (pair) {
return pair.a === a && pair.b === b;
})) {
return true;
}
memory.push({
a: a,
b: b
});
var aObjType = objectType(a);
var bObjType = objectType(b);
if (aObjType !== 'object' || bObjType !== 'object') {
return aObjType === bObjType && objTypeCallbacks[aObjType](a, b);
}
if (compareConstructors(a, b) === false) {
return false;
}
var aProperties = [];
var bProperties = [];
for (var i in a) {
aProperties.push(i);
if (a.constructor !== Object && typeof a.constructor !== 'undefined' && typeof a[i] === 'function' && typeof b[i] === 'function' && a[i].toString() === b[i].toString()) {
continue;
}
if (!typeEquiv(a[i], b[i])) {
return false;
}
}
for (var _i in b) {
bProperties.push(_i);
}
return objTypeCallbacks.array(aProperties.sort(), bProperties.sort());
}
};
function typeEquiv(a, b) {
if (a === b) {
return true;
}
var aType = _typeof(a);
var bType = _typeof(b);
if (aType !== bType) {
return (aType === 'object' && BOXABLE_TYPES.has(objectType(a)) ? a.valueOf() : a) === (bType === 'object' && BOXABLE_TYPES.has(objectType(b)) ? b.valueOf() : b);
}
return entryTypeCallbacks[aType](a, b);
}
function innerEquiv(a, b) {
var res = typeEquiv(a, b);
memory = [];
return res;
}
function equiv(a, b) {
if (arguments.length === 2) {
return a === b || innerEquiv(a, b);
}
var i = arguments.length - 1;
while (i > 0) {
if (!innerEquiv(arguments[i - 1], arguments[i])) {
return false;
}
i--;
}
return true;
}
var config = {
altertitle: true,
collapse: true,
failOnZeroTests: true,
filter: undefined,
maxDepth: 5,
module: undefined,
moduleId: undefined,
reorder: true,
requireExpects: false,
scrolltop: true,
storage: localSessionStorage,
testId: undefined,
urlConfig: [],
currentModule: {
name: '',
tests: [],
childModules: [],
testsRun: 0,
testsIgnored: 0,
hooks: {
before: [],
beforeEach: [],
afterEach: [],
after: []
}
},
globalHooks: {},
blocking: true,
callbacks: {},
modules: [],
queue: [],
stats: {
all: 0,
bad: 0,
testCount: 0
}
};
var preConfig = g && g.QUnit && !g.QUnit.version && g.QUnit.config;
if (preConfig) {
extend(config, preConfig);
}
config.modules.push(config.currentModule);
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();
var inner = dump.indent(1);
if (arr.join) {
arr = arr.join(',' + s + inner);
}
if (!arr) {
return pre + post;
}
var base = dump.indent();
return [pre, inner + arr, base + post].join(s);
}
function array(arr, stack) {
if (dump.maxDepth && dump.depth > dump.maxDepth) {
return '[object Array]';
}
this.up();
var i = arr.length;
var ret = new Array(i);
while (i--) {
ret[i] = this.parse(arr[i], undefined, stack);
}
this.down();
return join('[', ret, ']');
}
function isArray(obj) {
return (toString.call(obj) === '[object Array]' ||
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+)/;
var dump = {
parse: function parse(obj, objType, stack) {
stack = stack || [];
var objIndex = stack.indexOf(obj);
if (objIndex !== -1) {
return "recursion(".concat(objIndex - stack.length, ")");
}
objType = objType || this.typeOf(obj);
var parser = this.parsers[objType];
var parserType = _typeof(parser);
if (parserType === 'function') {
stack.push(obj);
var res = parser.call(this, obj, stack);
stack.pop();
return res;
}
if (parserType === 'string') {
return parser;
}
return '[ERROR: Missing QUnit.dump formatter for type ' + objType + ']';
},
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);
}
return type;
},
separator: function separator() {
if (this.multiline) {
return this.HTML ? '<br />' : '\n';
}
else {
return this.HTML ? ' ' : ' ';
}
},
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;
},
quote: quote,
literal: literal,
join: join,
depth: 1,
maxDepth: config.maxDepth,
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';
var 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 ret = [];
if (dump.maxDepth && dump.depth > dump.maxDepth) {
return '[object Object]';
}
dump.up();
var keys = [];
for (var key in map) {
keys.push(key);
}
var nonEnumerableProperties = ['message', 'name'];
for (var i in nonEnumerableProperties) {
var _key = nonEnumerableProperties[i];
if (_key in map && !inArray(_key, keys)) {
keys.push(_key);
}
}
keys.sort();
for (var _i = 0; _i < keys.length; _i++) {
var _key2 = keys[_i];
var val = map[_key2];
ret.push(dump.parse(_key2, 'key') + ': ' + dump.parse(val, undefined, stack));
}
dump.down();
return join('{', ret, '}');
},
node: function node(_node) {
var open = dump.HTML ? '<' : '<';
var close = dump.HTML ? '>' : '>';
var tag = _node.nodeName.toLowerCase();
var ret = open + tag;
var attrs = _node.attributes;
if (attrs) {
for (var i = 0; i < attrs.length; i++) {
var val = attrs[i].nodeValue;
if (val && val !== 'inherit') {
ret += ' ' + attrs[i].nodeName + '=' + dump.parse(val, 'attribute');
}
}
}
ret += close;
if (_node.nodeType === 3 || _node.nodeType === 4) {
ret += _node.nodeValue;
}
return ret + open + '/' + tag + close;
},
functionArgs: function functionArgs(fn) {
var l = fn.length;
if (!l) {
return '';
}
var args = new Array(l);
while (l--) {
args[l] = String.fromCharCode(97 + l);
}
return ' ' + args.join(', ') + ' ';
},
key: quote,
functionCode: '[code]',
attribute: quote,
string: quote,
date: quote,
regexp: literal,
number: literal,
boolean: literal,
symbol: function symbol(sym) {
return sym.toString();
}
},
HTML: false,
indentChar: ' ',
multiline: true
};
return dump;
})();
var Logger = {
warn: console$1 ? Function.prototype.bind.call(console$1.warn || console$1.log, console$1) : function () { }
};
var SuiteReport = function () {
function SuiteReport(name, parentSuite) {
_classCallCheck(this, SuiteReport);
this.name = name;
this.fullName = parentSuite ? parentSuite.fullName.concat(name) : [];
this.globalFailureCount = 0;
this.tests = [];
this.childSuites = [];
if (parentSuite) {
parentSuite.pushChildSuite(this);
}
}
_createClass(SuiteReport, [{
key: "start",
value: function start(recordTime) {
if (recordTime) {
this._startTime = performance.now();
}
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 = performance.now();
}
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 Math.round(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.failed += this.globalFailureCount;
counts.total += this.globalFailureCount;
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 _this$getTestCounts = this.getTestCounts(), total = _this$getTestCounts.total, failed = _this$getTestCounts.failed, skipped = _this$getTestCounts.skipped, todo = _this$getTestCounts.todo;
if (failed) {
return 'failed';
}
else {
if (skipped === total) {
return 'skipped';
}
else if (todo === total) {
return 'todo';
}
else {
return 'passed';
}
}
}
}]);
return SuiteReport;
}();
var moduleStack = [];
var runSuite = new SuiteReport();
function isParentModuleInQueue() {
var modulesInQueue = config.modules.filter(function (module) {
return !module.ignored;
}).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 : runSuite;
var skip = parentModule !== null && parentModule.skip || modifiers.skip;
var todo = parentModule !== null && parentModule.todo || modifiers.todo;
var env = {};
if (parentModule) {
extend(env, parentModule.testEnvironment);
}
extend(env, testEnvironment);
var module = {
name: moduleName,
parentModule: parentModule,
hooks: {
before: [],
beforeEach: [],
afterEach: [],
after: []
},
testEnvironment: env,
tests: [],
moduleId: generateHash(moduleName),
testsRun: 0,
testsIgnored: 0,
childModules: [],
suiteReport: new SuiteReport(name, parentSuite),
stats: null,
skip: skip,
todo: skip ? false : todo,
ignored: modifiers.ignored || false
};
if (parentModule) {
parentModule.childModules.push(module);
}
config.modules.push(module);
return module;
}
function setHookFromEnvironment(hooks, environment, name) {
var potentialHook = environment[name];
if (typeof potentialHook === 'function') {
hooks[name].push(potentialHook);
}
delete environment[name];
}
function makeSetHook(module, hookName) {
return function setHook(callback) {
if (config.currentModule !== module) {
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.');
}
module.hooks[hookName].push(callback);
};
}
function processModule(name, options, executeNow) {
var modifiers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
if (typeof options === 'function') {
executeNow = options;
options = undefined;
}
var module = createModule(name, options, modifiers);
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: makeSetHook(module, 'before'),
beforeEach: makeSetHook(module, 'beforeEach'),
afterEach: makeSetHook(module, 'afterEach'),
after: makeSetHook(module, 'after')
};
var prevModule = config.currentModule;
config.currentModule = module;
if (typeof executeNow === 'function') {
moduleStack.push(module);
try {
var cbReturnValue = executeNow.call(module.testEnvironment, moduleFns);
if (cbReturnValue && typeof cbReturnValue.then === 'function') {
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.');
}
}
finally {
moduleStack.pop();
config.currentModule = module.parentModule || prevModule;
}
}
}
var focused$1 = false;
function module$1(name, options, executeNow) {
var ignored = focused$1 && !isParentModuleInQueue();
processModule(name, options, executeNow, {
ignored: ignored
});
}
module$1.only = function () {
if (!focused$1) {
config.modules.length = 0;
config.queue.length = 0;
config.currentModule.ignored = true;
}
focused$1 = true;
processModule.apply(void 0, arguments);
};
module$1.skip = function (name, options, executeNow) {
if (focused$1) {
return;
}
processModule(name, options, executeNow, {
skip: true
});
};
module$1.todo = function (name, options, executeNow) {
if (focused$1) {
return;
}
processModule(name, options, executeNow, {
todo: true
});
};
var fileName = (sourceFromStacktrace(0) || '').replace(/(:\d+)+\)?/, '')
.replace(/.+[/\\]/, '');
function extractStacktrace(e, offset) {
offset = offset === undefined ? 4 : offset;
if (e && e.stack) {
var stack = e.stack.split('\n');
if (/^error$/i.test(stack[0])) {
stack.shift();
}
if (fileName) {
var include = [];
for (var i = offset; i < stack.length; i++) {
if (stack[i].indexOf(fileName) !== -1) {
break;
}
include.push(stack[i]);
}
if (include.length) {
return include.join('\n');
}
}
return stack[offset];
}
}
function sourceFromStacktrace(offset) {
var error = new Error();
if (!error.stack) {
try {
throw error;
}
catch (err) {
error = err;
}
}
return extractStacktrace(error, offset);
}
var Assert = function () {
function Assert(testContext) {
_classCallCheck(this, Assert);
this.test = testContext;
}
_createClass(Assert, [{
key: "timeout",
value: function timeout(duration) {
if (typeof duration !== 'number') {
throw new Error('You must pass a number as the duration to assert.timeout');
}
this.test.timeout = duration;
if (config.timeout) {
clearTimeout(config.timeout);
config.timeout = null;
if (config.timeoutHandler && this.test.timeout > 0) {
this.test.internalResetTimeout(this.test.timeout);
}
}
}
}, {
key: "step",
value: function step(message) {
var assertionMessage = message;
var result = !!message;
this.test.steps.push(message);
if (typeof message === 'undefined' || message === '') {
assertionMessage = 'You must provide a message to assert.step';
}
else if (typeof message !== 'string') {
assertionMessage = 'You must provide a string value to assert.step';
result = false;
}
this.pushResult({
result: result,
message: assertionMessage
});
}
}, {
key: "verifySteps",
value: function verifySteps(steps, message) {
var actualStepsClone = this.test.steps.slice();
this.deepEqual(actualStepsClone, steps, message);
this.test.steps.length = 0;
}
}, {
key: "expect",
value: function expect(asserts) {
if (arguments.length === 1) {
this.test.expected = asserts;
}
else {
return this.test.expected;
}
}
}, {
key: "async",
value: function async(count) {
if (count === undefined) {
count = 1;
}
else if (typeof count !== 'number') {
throw new TypeError('async takes number as an input');
}
var requiredCalls = count;
return this.test.internalStop(requiredCalls);
}
}, {
key: "push",
value: function push(result, actual, expected, message, negative) {
Logger.warn('assert.push is deprecated and will be removed in QUnit 3.0.' + ' Please use assert.pushResult instead (https://api.qunitjs.com/assert/pushResult).');
var currentAssert = this instanceof Assert ? this : config.current.assert;
return currentAssert.pushResult({
result: result,
actual: actual,
expected: expected,
message: message,
negative: negative
});
}
}, {
key: "pushResult",
value: function pushResult(resultInfo) {
var assert = this;
var currentTest = assert instanceof Assert && assert.test || config.current;
if (!currentTest) {
throw new Error('assertion outside test context, in ' + sourceFromStacktrace(2));
}
if (!(assert instanceof Assert)) {
assert = currentTest.assert;
}
return assert.test.pushResult(resultInfo);
}
}, {
key: "ok",
value: function ok(result, message) {
if (!message) {
message = result ? 'okay' : "failed, expected argument to be truthy, was: ".concat(dump.parse(result));
}
this.pushResult({
result: !!result,
actual: result,
expected: true,
message: message
});
}
}, {
key: "notOk",
value: function notOk(result, message) {
if (!message) {
message = !result ? 'okay' : "failed, expected argument to be falsy, was: ".concat(dump.parse(result));
}
this.pushResult({
result: !result,
actual: result,
expected: false,
message: message
});
}
}, {
key: "true",
value: function _true(result, message) {
this.pushResult({
result: result === true,
actual: result,
expected: true,
message: message
});
}
}, {
key: "false",
value: function _false(result, message) {
this.pushResult({
result: result === false,
actual: result,
expected: false,
message: message
});
}
}, {
key: "equal",
value: function equal(actual, expected, message) {
this.pushResult({
result: expected == actual,
actual: actual,
expected: expected,
message: message
});
}
}, {
key: "notEqual",
value: function notEqual(actual, expected, message) {
this.pushResult({
result: expected != actual,
actual: actual,
expected: expected,
message: message,
negative: true
});
}
}, {
key: "propEqual",
value: function propEqual(actual, expected, message) {
actual = objectValues(actual);
expected = objectValues(expected);
this.pushResult({
result: equiv(actual, expected),
actual: actual,
expected: expected,
message: message
});
}
}, {
key: "notPropEqual",
value: function notPropEqual(actual, expected, message) {
actual = objectValues(actual);
expected = objectValues(expected);
this.pushResult({
result: !equiv(actual, expected),
actual: actual,
expected: expected,
message: message,
negative: true
});
}
}, {
key: "propContains",
value: function propContains(actual, expected, message) {
actual = objectValuesSubset(actual, expected);
expected = objectValues(expected, false);
this.pushResult({
result: equiv(actual, expected),
actual: actual,
expected: expected,
message: message
});
}
}, {
key: "notPropContains",
value: function notPropContains(actual, expected, message) {
actual = objectValuesSubset(actual, expected);
expected = objectValues(expected);
this.pushResult({
result: !equiv(actual, expected),
actual: actual,
expected: expected,
message: message,
negative: true
});
}
}, {
key: "deepEqual",
value: function deepEqual(actual, expected, message) {
this.pushResult({
result: equiv(actual, expected),
actual: actual,
expected: expected,
message: message
});
}
}, {
key: "notDeepEqual",
value: function notDeepEqual(actual, expected, message) {
this.pushResult({
result: !equiv(actual, expected),
actual: actual,
expected: expected,
message: message,
negative: true
});
}
}, {
key: "strictEqual",
value: function strictEqual(actual, expected, message) {
this.pushResult({
result: expected === actual,
actual: actual,
expected: expected,
message: message
});
}
}, {
key: "notStrictEqual",
value: function notStrictEqual(actual, expected, message) {
this.pushResult({
result: expected !== actual,
actual: actual,
expected: expected,
message: message,
negative: true
});
}
}, {
key: 'throws',
value: function throws(block, expected, message) {
var _validateExpectedExce = validateExpectedExceptionArgs(expected, message, 'throws');
var _validateExpectedExce2 = _slicedToArray(_validateExpectedExce, 2);
expected = _validateExpectedExce2[0];