ga-basic-slider
Version:
A vanilla javascript slider plug-in that's made to be styleable
1,608 lines (1,410 loc) • 256 kB
JavaScript
/*
Copyright (c) 2008-2020 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// eslint-disable-next-line no-unused-vars
var getJasmineRequireObj = (function(jasmineGlobal) {
var jasmineRequire;
if (
typeof module !== 'undefined' &&
module.exports &&
typeof exports !== 'undefined'
) {
if (typeof global !== 'undefined') {
jasmineGlobal = global;
} else {
jasmineGlobal = {};
}
jasmineRequire = exports;
} else {
if (
typeof window !== 'undefined' &&
typeof window.toString === 'function' &&
window.toString() === '[object GjsGlobal]'
) {
jasmineGlobal = window;
}
jasmineRequire = jasmineGlobal.jasmineRequire = {};
}
function getJasmineRequire() {
return jasmineRequire;
}
getJasmineRequire().core = function(jRequire) {
var j$ = {};
jRequire.base(j$, jasmineGlobal);
j$.util = jRequire.util(j$);
j$.errors = jRequire.errors();
j$.formatErrorMsg = jRequire.formatErrorMsg();
j$.Any = jRequire.Any(j$);
j$.Anything = jRequire.Anything(j$);
j$.CallTracker = jRequire.CallTracker(j$);
j$.MockDate = jRequire.MockDate();
j$.getClearStack = jRequire.clearStack(j$);
j$.Clock = jRequire.Clock();
j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler(j$);
j$.Env = jRequire.Env(j$);
j$.StackTrace = jRequire.StackTrace(j$);
j$.ExceptionFormatter = jRequire.ExceptionFormatter(j$);
j$.ExpectationFilterChain = jRequire.ExpectationFilterChain();
j$.Expector = jRequire.Expector(j$);
j$.Expectation = jRequire.Expectation(j$);
j$.buildExpectationResult = jRequire.buildExpectationResult(j$);
j$.JsApiReporter = jRequire.JsApiReporter(j$);
j$.asymmetricEqualityTesterArgCompatShim = jRequire.asymmetricEqualityTesterArgCompatShim(
j$
);
j$.makePrettyPrinter = jRequire.makePrettyPrinter(j$);
j$.pp = j$.makePrettyPrinter();
j$.MatchersUtil = jRequire.MatchersUtil(j$);
j$.matchersUtil = new j$.MatchersUtil({
customTesters: [],
pp: j$.pp
});
j$.ObjectContaining = jRequire.ObjectContaining(j$);
j$.ArrayContaining = jRequire.ArrayContaining(j$);
j$.ArrayWithExactContents = jRequire.ArrayWithExactContents(j$);
j$.MapContaining = jRequire.MapContaining(j$);
j$.SetContaining = jRequire.SetContaining(j$);
j$.QueueRunner = jRequire.QueueRunner(j$);
j$.ReportDispatcher = jRequire.ReportDispatcher(j$);
j$.Spec = jRequire.Spec(j$);
j$.Spy = jRequire.Spy(j$);
j$.SpyFactory = jRequire.SpyFactory(j$);
j$.SpyRegistry = jRequire.SpyRegistry(j$);
j$.SpyStrategy = jRequire.SpyStrategy(j$);
j$.StringMatching = jRequire.StringMatching(j$);
j$.UserContext = jRequire.UserContext(j$);
j$.Suite = jRequire.Suite(j$);
j$.Timer = jRequire.Timer();
j$.TreeProcessor = jRequire.TreeProcessor();
j$.version = jRequire.version();
j$.Order = jRequire.Order();
j$.DiffBuilder = jRequire.DiffBuilder(j$);
j$.NullDiffBuilder = jRequire.NullDiffBuilder(j$);
j$.ObjectPath = jRequire.ObjectPath(j$);
j$.MismatchTree = jRequire.MismatchTree(j$);
j$.GlobalErrors = jRequire.GlobalErrors(j$);
j$.Truthy = jRequire.Truthy(j$);
j$.Falsy = jRequire.Falsy(j$);
j$.Empty = jRequire.Empty(j$);
j$.NotEmpty = jRequire.NotEmpty(j$);
j$.matchers = jRequire.requireMatchers(jRequire, j$);
j$.asyncMatchers = jRequire.requireAsyncMatchers(jRequire, j$);
return j$;
};
return getJasmineRequire;
})(this);
getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
var availableMatchers = [
'nothing',
'toBe',
'toBeCloseTo',
'toBeDefined',
'toBeInstanceOf',
'toBeFalse',
'toBeFalsy',
'toBeGreaterThan',
'toBeGreaterThanOrEqual',
'toBeLessThan',
'toBeLessThanOrEqual',
'toBeNaN',
'toBeNegativeInfinity',
'toBeNull',
'toBePositiveInfinity',
'toBeTrue',
'toBeTruthy',
'toBeUndefined',
'toContain',
'toEqual',
'toHaveSize',
'toHaveBeenCalled',
'toHaveBeenCalledBefore',
'toHaveBeenCalledOnceWith',
'toHaveBeenCalledTimes',
'toHaveBeenCalledWith',
'toHaveClass',
'toMatch',
'toThrow',
'toThrowError',
'toThrowMatching'
],
matchers = {};
for (var i = 0; i < availableMatchers.length; i++) {
var name = availableMatchers[i];
matchers[name] = jRequire[name](j$);
}
return matchers;
};
getJasmineRequireObj().base = function(j$, jasmineGlobal) {
j$.unimplementedMethod_ = function() {
throw new Error('unimplemented method');
};
/**
* Maximum object depth the pretty printer will print to.
* Set this to a lower value to speed up pretty printing if you have large objects.
* @name jasmine.MAX_PRETTY_PRINT_DEPTH
* @since 1.3.0
*/
j$.MAX_PRETTY_PRINT_DEPTH = 8;
/**
* Maximum number of array elements to display when pretty printing objects.
* This will also limit the number of keys and values displayed for an object.
* Elements past this number will be ellipised.
* @name jasmine.MAX_PRETTY_PRINT_ARRAY_LENGTH
* @since 2.7.0
*/
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 50;
/**
* Maximum number of characters to display when pretty printing objects.
* Characters past this number will be ellipised.
* @name jasmine.MAX_PRETTY_PRINT_CHARS
* @since 2.9.0
*/
j$.MAX_PRETTY_PRINT_CHARS = 1000;
/**
* Default number of milliseconds Jasmine will wait for an asynchronous spec to complete.
* @name jasmine.DEFAULT_TIMEOUT_INTERVAL
* @since 1.3.0
*/
j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
j$.getGlobal = function() {
return jasmineGlobal;
};
/**
* Get the currently booted Jasmine Environment.
*
* @name jasmine.getEnv
* @since 1.3.0
* @function
* @return {Env}
*/
j$.getEnv = function(options) {
var env = (j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options));
//jasmine. singletons in here (setTimeout blah blah).
return env;
};
j$.isArray_ = function(value) {
return j$.isA_('Array', value);
};
j$.isObject_ = function(value) {
return (
!j$.util.isUndefined(value) && value !== null && j$.isA_('Object', value)
);
};
j$.isString_ = function(value) {
return j$.isA_('String', value);
};
j$.isNumber_ = function(value) {
return j$.isA_('Number', value);
};
j$.isFunction_ = function(value) {
return j$.isA_('Function', value);
};
j$.isAsyncFunction_ = function(value) {
return j$.isA_('AsyncFunction', value);
};
j$.isTypedArray_ = function(value) {
return (
j$.isA_('Float32Array', value) ||
j$.isA_('Float64Array', value) ||
j$.isA_('Int16Array', value) ||
j$.isA_('Int32Array', value) ||
j$.isA_('Int8Array', value) ||
j$.isA_('Uint16Array', value) ||
j$.isA_('Uint32Array', value) ||
j$.isA_('Uint8Array', value) ||
j$.isA_('Uint8ClampedArray', value)
);
};
j$.isA_ = function(typeName, value) {
return j$.getType_(value) === '[object ' + typeName + ']';
};
j$.isError_ = function(value) {
if (value instanceof Error) {
return true;
}
if (value && value.constructor && value.constructor.constructor) {
var valueGlobal = value.constructor.constructor('return this');
if (j$.isFunction_(valueGlobal)) {
valueGlobal = valueGlobal();
}
if (valueGlobal.Error && value instanceof valueGlobal.Error) {
return true;
}
}
return false;
};
j$.isAsymmetricEqualityTester_ = function(obj) {
return obj ? j$.isA_('Function', obj.asymmetricMatch) : false;
};
j$.getType_ = function(value) {
return Object.prototype.toString.apply(value);
};
j$.isDomNode = function(obj) {
// Node is a function, because constructors
return typeof jasmineGlobal.Node !== 'undefined'
? obj instanceof jasmineGlobal.Node
: obj !== null &&
typeof obj === 'object' &&
typeof obj.nodeType === 'number' &&
typeof obj.nodeName === 'string';
// return obj.nodeType > 0;
};
j$.isMap = function(obj) {
return (
obj !== null &&
typeof obj !== 'undefined' &&
typeof jasmineGlobal.Map !== 'undefined' &&
obj.constructor === jasmineGlobal.Map
);
};
j$.isSet = function(obj) {
return (
obj !== null &&
typeof obj !== 'undefined' &&
typeof jasmineGlobal.Set !== 'undefined' &&
obj.constructor === jasmineGlobal.Set
);
};
j$.isWeakMap = function(obj) {
return (
obj !== null &&
typeof obj !== 'undefined' &&
typeof jasmineGlobal.WeakMap !== 'undefined' &&
obj.constructor === jasmineGlobal.WeakMap
);
};
j$.isDataView = function(obj) {
return (
obj !== null &&
typeof obj !== 'undefined' &&
typeof jasmineGlobal.DataView !== 'undefined' &&
obj.constructor === jasmineGlobal.DataView
);
};
j$.isPromise = function(obj) {
return (
typeof jasmineGlobal.Promise !== 'undefined' &&
!!obj &&
obj.constructor === jasmineGlobal.Promise
);
};
j$.isPromiseLike = function(obj) {
return !!obj && j$.isFunction_(obj.then);
};
j$.fnNameFor = function(func) {
if (func.name) {
return func.name;
}
var matches =
func.toString().match(/^\s*function\s*(\w+)\s*\(/) ||
func.toString().match(/^\s*\[object\s*(\w+)Constructor\]/);
return matches ? matches[1] : '<anonymous>';
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is an instance of the specified class/constructor.
* @name jasmine.any
* @since 1.3.0
* @function
* @param {Constructor} clazz - The constructor to check against.
*/
j$.any = function(clazz) {
return new j$.Any(clazz);
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is not `null` and not `undefined`.
* @name jasmine.anything
* @since 2.2.0
* @function
*/
j$.anything = function() {
return new j$.Anything();
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is `true` or anything truthy.
* @name jasmine.truthy
* @since 3.1.0
* @function
*/
j$.truthy = function() {
return new j$.Truthy();
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is `null`, `undefined`, `0`, `false` or anything falsey.
* @name jasmine.falsy
* @since 3.1.0
* @function
*/
j$.falsy = function() {
return new j$.Falsy();
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is empty.
* @name jasmine.empty
* @since 3.1.0
* @function
*/
j$.empty = function() {
return new j$.Empty();
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared is not empty.
* @name jasmine.notEmpty
* @since 3.1.0
* @function
*/
j$.notEmpty = function() {
return new j$.NotEmpty();
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value being compared contains at least the keys and values.
* @name jasmine.objectContaining
* @since 1.3.0
* @function
* @param {Object} sample - The subset of properties that _must_ be in the actual.
*/
j$.objectContaining = function(sample) {
return new j$.ObjectContaining(sample);
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value is a `String` that matches the `RegExp` or `String`.
* @name jasmine.stringMatching
* @since 2.2.0
* @function
* @param {RegExp|String} expected
*/
j$.stringMatching = function(expected) {
return new j$.StringMatching(expected);
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value is an `Array` that contains at least the elements in the sample.
* @name jasmine.arrayContaining
* @since 2.2.0
* @function
* @param {Array} sample
*/
j$.arrayContaining = function(sample) {
return new j$.ArrayContaining(sample);
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if the actual value is an `Array` that contains all of the elements in the sample in any order.
* @name jasmine.arrayWithExactContents
* @since 2.8.0
* @function
* @param {Array} sample
*/
j$.arrayWithExactContents = function(sample) {
return new j$.ArrayWithExactContents(sample);
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if every key/value pair in the sample passes the deep equality comparison
* with at least one key/value pair in the actual value being compared
* @name jasmine.mapContaining
* @since 3.5.0
* @function
* @param {Map} sample - The subset of items that _must_ be in the actual.
*/
j$.mapContaining = function(sample) {
return new j$.MapContaining(sample);
};
/**
* Get a matcher, usable in any {@link matchers|matcher} that uses Jasmine's equality (e.g. {@link matchers#toEqual|toEqual}, {@link matchers#toContain|toContain}, or {@link matchers#toHaveBeenCalledWith|toHaveBeenCalledWith}),
* that will succeed if every item in the sample passes the deep equality comparison
* with at least one item in the actual value being compared
* @name jasmine.setContaining
* @since 3.5.0
* @function
* @param {Set} sample - The subset of items that _must_ be in the actual.
*/
j$.setContaining = function(sample) {
return new j$.SetContaining(sample);
};
j$.isSpy = function(putativeSpy) {
if (!putativeSpy) {
return false;
}
return (
putativeSpy.and instanceof j$.SpyStrategy &&
putativeSpy.calls instanceof j$.CallTracker
);
};
};
getJasmineRequireObj().util = function(j$) {
var util = {};
util.inherit = function(childClass, parentClass) {
var Subclass = function() {};
Subclass.prototype = parentClass.prototype;
childClass.prototype = new Subclass();
};
util.htmlEscape = function(str) {
if (!str) {
return str;
}
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>');
};
util.argsToArray = function(args) {
var arrayOfArgs = [];
for (var i = 0; i < args.length; i++) {
arrayOfArgs.push(args[i]);
}
return arrayOfArgs;
};
util.isUndefined = function(obj) {
return obj === void 0;
};
util.arrayContains = function(array, search) {
var i = array.length;
while (i--) {
if (array[i] === search) {
return true;
}
}
return false;
};
util.clone = function(obj) {
if (Object.prototype.toString.apply(obj) === '[object Array]') {
return obj.slice();
}
var cloned = {};
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
cloned[prop] = obj[prop];
}
}
return cloned;
};
util.cloneArgs = function(args) {
var clonedArgs = [];
var argsAsArray = j$.util.argsToArray(args);
for (var i = 0; i < argsAsArray.length; i++) {
var str = Object.prototype.toString.apply(argsAsArray[i]),
primitives = /^\[object (Boolean|String|RegExp|Number)/;
// All falsey values are either primitives, `null`, or `undefined.
if (!argsAsArray[i] || str.match(primitives)) {
clonedArgs.push(argsAsArray[i]);
} else {
clonedArgs.push(j$.util.clone(argsAsArray[i]));
}
}
return clonedArgs;
};
util.getPropertyDescriptor = function(obj, methodName) {
var descriptor,
proto = obj;
do {
descriptor = Object.getOwnPropertyDescriptor(proto, methodName);
proto = Object.getPrototypeOf(proto);
} while (!descriptor && proto);
return descriptor;
};
util.objectDifference = function(obj, toRemove) {
var diff = {};
for (var key in obj) {
if (util.has(obj, key) && !util.has(toRemove, key)) {
diff[key] = obj[key];
}
}
return diff;
};
util.has = function(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
};
util.errorWithStack = function errorWithStack() {
// Don't throw and catch if we don't have to, because it makes it harder
// for users to debug their code with exception breakpoints.
var error = new Error();
if (error.stack) {
return error;
}
// But some browsers (e.g. Phantom) only provide a stack trace if we throw.
try {
throw new Error();
} catch (e) {
return e;
}
};
function callerFile() {
var trace = new j$.StackTrace(util.errorWithStack());
return trace.frames[2].file;
}
util.jasmineFile = (function() {
var result;
return function() {
if (!result) {
result = callerFile();
}
return result;
};
})();
function StopIteration() {}
StopIteration.prototype = Object.create(Error.prototype);
StopIteration.prototype.constructor = StopIteration;
// useful for maps and sets since `forEach` is the only IE11-compatible way to iterate them
util.forEachBreakable = function(iterable, iteratee) {
function breakLoop() {
throw new StopIteration();
}
try {
iterable.forEach(function(value, key) {
iteratee(breakLoop, value, key, iterable);
});
} catch (error) {
if (!(error instanceof StopIteration)) throw error;
}
};
return util;
};
getJasmineRequireObj().Spec = function(j$) {
function Spec(attrs) {
this.expectationFactory = attrs.expectationFactory;
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
this.resultCallback = attrs.resultCallback || function() {};
this.id = attrs.id;
this.description = attrs.description || '';
this.queueableFn = attrs.queueableFn;
this.beforeAndAfterFns =
attrs.beforeAndAfterFns ||
function() {
return { befores: [], afters: [] };
};
this.userContext =
attrs.userContext ||
function() {
return {};
};
this.onStart = attrs.onStart || function() {};
this.getSpecName =
attrs.getSpecName ||
function() {
return '';
};
this.expectationResultFactory =
attrs.expectationResultFactory || function() {};
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
this.catchingExceptions =
attrs.catchingExceptions ||
function() {
return true;
};
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
this.timer = attrs.timer || new j$.Timer();
if (!this.queueableFn.fn) {
this.pend();
}
/**
* @typedef SpecResult
* @property {Int} id - The unique id of this spec.
* @property {String} description - The description passed to the {@link it} that created this spec.
* @property {String} fullName - The full description including all ancestors of this spec.
* @property {Expectation[]} failedExpectations - The list of expectations that failed during execution of this spec.
* @property {Expectation[]} passedExpectations - The list of expectations that passed during execution of this spec.
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred during execution this spec.
* @property {String} pendingReason - If the spec is {@link pending}, this will be the reason.
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
*/
this.result = {
id: this.id,
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
passedExpectations: [],
deprecationWarnings: [],
pendingReason: '',
duration: null,
properties: null
};
}
Spec.prototype.addExpectationResult = function(passed, data, isError) {
var expectationResult = this.expectationResultFactory(data);
if (passed) {
this.result.passedExpectations.push(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
if (this.throwOnExpectationFailure && !isError) {
throw new j$.errors.ExpectationFailed();
}
}
};
Spec.prototype.setSpecProperty = function(key, value) {
this.result.properties = this.result.properties || {};
this.result.properties[key] = value;
};
Spec.prototype.expect = function(actual) {
return this.expectationFactory(actual, this);
};
Spec.prototype.expectAsync = function(actual) {
return this.asyncExpectationFactory(actual, this);
};
Spec.prototype.execute = function(onComplete, excluded, failSpecWithNoExp) {
var self = this;
var onStart = {
fn: function(done) {
self.timer.start();
self.onStart(self, done);
}
};
var complete = {
fn: function(done) {
self.queueableFn.fn = null;
self.result.status = self.status(excluded, failSpecWithNoExp);
self.result.duration = self.timer.elapsed();
self.resultCallback(self.result, done);
}
};
var fns = this.beforeAndAfterFns();
var regularFns = fns.befores.concat(this.queueableFn);
var runnerConfig = {
isLeaf: true,
queueableFns: regularFns,
cleanupFns: fns.afters,
onException: function() {
self.onException.apply(self, arguments);
},
onComplete: function() {
onComplete(
self.result.status === 'failed' &&
new j$.StopExecutionError('spec failed')
);
},
userContext: this.userContext()
};
if (this.markedPending || excluded === true) {
runnerConfig.queueableFns = [];
runnerConfig.cleanupFns = [];
}
runnerConfig.queueableFns.unshift(onStart);
runnerConfig.cleanupFns.push(complete);
this.queueRunnerFactory(runnerConfig);
};
Spec.prototype.onException = function onException(e) {
if (Spec.isPendingSpecException(e)) {
this.pend(extractCustomPendingMessage(e));
return;
}
if (e instanceof j$.errors.ExpectationFailed) {
return;
}
this.addExpectationResult(
false,
{
matcherName: '',
passed: false,
expected: '',
actual: '',
error: e
},
true
);
};
Spec.prototype.pend = function(message) {
this.markedPending = true;
if (message) {
this.result.pendingReason = message;
}
};
Spec.prototype.getResult = function() {
this.result.status = this.status();
return this.result;
};
Spec.prototype.status = function(excluded, failSpecWithNoExpectations) {
if (excluded === true) {
return 'excluded';
}
if (this.markedPending) {
return 'pending';
}
if (
this.result.failedExpectations.length > 0 ||
(failSpecWithNoExpectations &&
this.result.failedExpectations.length +
this.result.passedExpectations.length ===
0)
) {
return 'failed';
}
return 'passed';
};
Spec.prototype.getFullName = function() {
return this.getSpecName(this);
};
Spec.prototype.addDeprecationWarning = function(deprecation) {
if (typeof deprecation === 'string') {
deprecation = { message: deprecation };
}
this.result.deprecationWarnings.push(
this.expectationResultFactory(deprecation)
);
};
var extractCustomPendingMessage = function(e) {
var fullMessage = e.toString(),
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
boilerplateEnd =
boilerplateStart + Spec.pendingSpecExceptionMessage.length;
return fullMessage.substr(boilerplateEnd);
};
Spec.pendingSpecExceptionMessage = '=> marked Pending';
Spec.isPendingSpecException = function(e) {
return !!(
e &&
e.toString &&
e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1
);
};
return Spec;
};
if (typeof window == void 0 && typeof exports == 'object') {
/* globals exports */
exports.Spec = jasmineRequire.Spec;
}
/*jshint bitwise: false*/
getJasmineRequireObj().Order = function() {
function Order(options) {
this.random = 'random' in options ? options.random : true;
var seed = (this.seed = options.seed || generateSeed());
this.sort = this.random ? randomOrder : naturalOrder;
function naturalOrder(items) {
return items;
}
function randomOrder(items) {
var copy = items.slice();
copy.sort(function(a, b) {
return jenkinsHash(seed + a.id) - jenkinsHash(seed + b.id);
});
return copy;
}
function generateSeed() {
return String(Math.random()).slice(-5);
}
// Bob Jenkins One-at-a-Time Hash algorithm is a non-cryptographic hash function
// used to get a different output when the key changes slightly.
// We use your return to sort the children randomly in a consistent way when
// used in conjunction with a seed
function jenkinsHash(key) {
var hash, i;
for (hash = i = 0; i < key.length; ++i) {
hash += key.charCodeAt(i);
hash += hash << 10;
hash ^= hash >> 6;
}
hash += hash << 3;
hash ^= hash >> 11;
hash += hash << 15;
return hash;
}
}
return Order;
};
getJasmineRequireObj().Env = function(j$) {
/**
* _Note:_ Do not construct this directly, Jasmine will make one during booting.
* @name Env
* @since 2.0.0
* @classdesc The Jasmine environment
* @constructor
*/
function Env(options) {
options = options || {};
var self = this;
var global = options.global || j$.getGlobal();
var customPromise;
var totalSpecsDefined = 0;
var realSetTimeout = global.setTimeout;
var realClearTimeout = global.clearTimeout;
var clearStack = j$.getClearStack(global);
this.clock = new j$.Clock(
global,
function() {
return new j$.DelayedFunctionScheduler();
},
new j$.MockDate(global)
);
var runnableResources = {};
var currentSpec = null;
var currentlyExecutingSuites = [];
var currentDeclarationSuite = null;
var hasFailures = false;
/**
* This represents the available options to configure Jasmine.
* Options that are not provided will use their default values
* @interface Configuration
* @since 3.3.0
*/
var config = {
/**
* Whether to randomize spec execution order
* @name Configuration#random
* @since 3.3.0
* @type Boolean
* @default true
*/
random: true,
/**
* Seed to use as the basis of randomization.
* Null causes the seed to be determined randomly at the start of execution.
* @name Configuration#seed
* @since 3.3.0
* @type function
* @default null
*/
seed: null,
/**
* Whether to stop execution of the suite after the first spec failure
* @name Configuration#failFast
* @since 3.3.0
* @type Boolean
* @default false
*/
failFast: false,
/**
* Whether to fail the spec if it ran no expectations. By default
* a spec that ran no expectations is reported as passed. Setting this
* to true will report such spec as a failure.
* @name Configuration#failSpecWithNoExpectations
* @since 3.5.0
* @type Boolean
* @default false
*/
failSpecWithNoExpectations: false,
/**
* Whether to cause specs to only have one expectation failure.
* @name Configuration#oneFailurePerSpec
* @since 3.3.0
* @type Boolean
* @default false
*/
oneFailurePerSpec: false,
/**
* Function to use to filter specs
* @name Configuration#specFilter
* @since 3.3.0
* @type function
* @default true
*/
specFilter: function() {
return true;
},
/**
* Whether or not reporters should hide disabled specs from their output.
* Currently only supported by Jasmine's HTMLReporter
* @name Configuration#hideDisabled
* @since 3.3.0
* @type Boolean
* @default false
*/
hideDisabled: false,
/**
* Set to provide a custom promise library that Jasmine will use if it needs
* to create a promise. If not set, it will default to whatever global Promise
* library is available (if any).
* @name Configuration#Promise
* @since 3.5.0
* @type function
* @default undefined
*/
Promise: undefined
};
var currentSuite = function() {
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
};
var currentRunnable = function() {
return currentSpec || currentSuite();
};
var globalErrors = null;
var installGlobalErrors = function() {
if (globalErrors) {
return;
}
globalErrors = new j$.GlobalErrors();
globalErrors.install();
};
if (!options.suppressLoadErrors) {
installGlobalErrors();
globalErrors.pushListener(function(
message,
filename,
lineno,
colNo,
err
) {
topSuite.result.failedExpectations.push({
passed: false,
globalErrorType: 'load',
message: message,
stack: err && err.stack,
filename: filename,
lineno: lineno
});
});
}
/**
* Configure your jasmine environment
* @name Env#configure
* @since 3.3.0
* @argument {Configuration} configuration
* @function
*/
this.configure = function(configuration) {
if (configuration.specFilter) {
config.specFilter = configuration.specFilter;
}
if (configuration.hasOwnProperty('random')) {
config.random = !!configuration.random;
}
if (configuration.hasOwnProperty('seed')) {
config.seed = configuration.seed;
}
if (configuration.hasOwnProperty('failFast')) {
config.failFast = configuration.failFast;
}
if (configuration.hasOwnProperty('failSpecWithNoExpectations')) {
config.failSpecWithNoExpectations =
configuration.failSpecWithNoExpectations;
}
if (configuration.hasOwnProperty('oneFailurePerSpec')) {
config.oneFailurePerSpec = configuration.oneFailurePerSpec;
}
if (configuration.hasOwnProperty('hideDisabled')) {
config.hideDisabled = configuration.hideDisabled;
}
// Don't use hasOwnProperty to check for Promise existence because Promise
// can be initialized to undefined, either explicitly or by using the
// object returned from Env#configuration. In particular, Karma does this.
if (configuration.Promise) {
if (
typeof configuration.Promise.resolve === 'function' &&
typeof configuration.Promise.reject === 'function'
) {
customPromise = configuration.Promise;
} else {
throw new Error(
'Custom promise library missing `resolve`/`reject` functions'
);
}
}
};
/**
* Get the current configuration for your jasmine environment
* @name Env#configuration
* @since 3.3.0
* @function
* @returns {Configuration}
*/
this.configuration = function() {
var result = {};
for (var property in config) {
result[property] = config[property];
}
return result;
};
Object.defineProperty(this, 'specFilter', {
get: function() {
self.deprecated(
'Getting specFilter directly from Env is deprecated and will be removed in a future version of Jasmine, please check the specFilter option from `configuration`'
);
return config.specFilter;
},
set: function(val) {
self.deprecated(
'Setting specFilter directly on Env is deprecated and will be removed in a future version of Jasmine, please use the specFilter option in `configure`'
);
config.specFilter = val;
}
});
this.setDefaultSpyStrategy = function(defaultStrategyFn) {
if (!currentRunnable()) {
throw new Error(
'Default spy strategy must be set in a before function or a spec'
);
}
runnableResources[
currentRunnable().id
].defaultStrategyFn = defaultStrategyFn;
};
this.addSpyStrategy = function(name, fn) {
if (!currentRunnable()) {
throw new Error(
'Custom spy strategies must be added in a before function or a spec'
);
}
runnableResources[currentRunnable().id].customSpyStrategies[name] = fn;
};
this.addCustomEqualityTester = function(tester) {
if (!currentRunnable()) {
throw new Error(
'Custom Equalities must be added in a before function or a spec'
);
}
runnableResources[currentRunnable().id].customEqualityTesters.push(
tester
);
};
this.addMatchers = function(matchersToAdd) {
if (!currentRunnable()) {
throw new Error(
'Matchers must be added in a before function or a spec'
);
}
var customMatchers =
runnableResources[currentRunnable().id].customMatchers;
for (var matcherName in matchersToAdd) {
customMatchers[matcherName] = matchersToAdd[matcherName];
}
};
this.addAsyncMatchers = function(matchersToAdd) {
if (!currentRunnable()) {
throw new Error(
'Async Matchers must be added in a before function or a spec'
);
}
var customAsyncMatchers =
runnableResources[currentRunnable().id].customAsyncMatchers;
for (var matcherName in matchersToAdd) {
customAsyncMatchers[matcherName] = matchersToAdd[matcherName];
}
};
this.addCustomObjectFormatter = function(formatter) {
if (!currentRunnable()) {
throw new Error(
'Custom object formatters must be added in a before function or a spec'
);
}
runnableResources[currentRunnable().id].customObjectFormatters.push(
formatter
);
};
j$.Expectation.addCoreMatchers(j$.matchers);
j$.Expectation.addAsyncCoreMatchers(j$.asyncMatchers);
var nextSpecId = 0;
var getNextSpecId = function() {
return 'spec' + nextSpecId++;
};
var nextSuiteId = 0;
var getNextSuiteId = function() {
return 'suite' + nextSuiteId++;
};
var makePrettyPrinter = function() {
var customObjectFormatters =
runnableResources[currentRunnable().id].customObjectFormatters;
return j$.makePrettyPrinter(customObjectFormatters);
};
var makeMatchersUtil = function() {
var customEqualityTesters =
runnableResources[currentRunnable().id].customEqualityTesters;
return new j$.MatchersUtil({
customTesters: customEqualityTesters,
pp: makePrettyPrinter()
});
};
var expectationFactory = function(actual, spec) {
var customEqualityTesters =
runnableResources[spec.id].customEqualityTesters;
return j$.Expectation.factory({
matchersUtil: makeMatchersUtil(),
customEqualityTesters: customEqualityTesters,
customMatchers: runnableResources[spec.id].customMatchers,
actual: actual,
addExpectationResult: addExpectationResult
});
function addExpectationResult(passed, result) {
return spec.addExpectationResult(passed, result);
}
};
function recordLateExpectation(runable, runableType, result) {
var delayedExpectationResult = {};
Object.keys(result).forEach(function(k) {
delayedExpectationResult[k] = result[k];
});
delayedExpectationResult.passed = false;
delayedExpectationResult.globalErrorType = 'lateExpectation';
delayedExpectationResult.message =
runableType +
' "' +
runable.getFullName() +
'" ran a "' +
result.matcherName +
'" expectation after it finished.\n';
if (result.message) {
delayedExpectationResult.message +=
'Message: "' + result.message + '"\n';
}
delayedExpectationResult.message +=
'Did you forget to return or await the result of expectAsync?';
topSuite.result.failedExpectations.push(delayedExpectationResult);
}
var asyncExpectationFactory = function(actual, spec, runableType) {
return j$.Expectation.asyncFactory({
matchersUtil: makeMatchersUtil(),
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers,
actual: actual,
addExpectationResult: addExpectationResult
});
function addExpectationResult(passed, result) {
if (currentRunnable() !== spec) {
recordLateExpectation(spec, runableType, result);
}
return spec.addExpectationResult(passed, result);
}
};
var suiteAsyncExpectationFactory = function(actual, suite) {
return asyncExpectationFactory(actual, suite, 'Suite');
};
var specAsyncExpectationFactory = function(actual, suite) {
return asyncExpectationFactory(actual, suite, 'Spec');
};
var defaultResourcesForRunnable = function(id, parentRunnableId) {
var resources = {
spies: [],
customEqualityTesters: [],
customMatchers: {},
customAsyncMatchers: {},
customSpyStrategies: {},
defaultStrategyFn: undefined,
customObjectFormatters: []
};
if (runnableResources[parentRunnableId]) {
resources.customEqualityTesters = j$.util.clone(
runnableResources[parentRunnableId].customEqualityTesters
);
resources.customMatchers = j$.util.clone(
runnableResources[parentRunnableId].customMatchers
);
resources.customAsyncMatchers = j$.util.clone(
runnableResources[parentRunnableId].customAsyncMatchers
);
resources.defaultStrategyFn =
runnableResources[parentRunnableId].defaultStrategyFn;
}
runnableResources[id] = resources;
};
var clearResourcesForRunnable = function(id) {
spyRegistry.clearSpies();
delete runnableResources[id];
};
var beforeAndAfterFns = function(suite) {
return function() {
var befores = [],
afters = [];
while (suite) {
befores = befores.concat(suite.beforeFns);
afters = afters.concat(suite.afterFns);
suite = suite.parentSuite;
}
return {
befores: befores.reverse(),
afters: afters
};
};
};
var getSpecName = function(spec, suite) {
var fullName = [spec.description],
suiteFullName = suite.getFullName();
if (suiteFullName !== '') {
fullName.unshift(suiteFullName);
}
return fullName.join(' ');
};
// TODO: we may just be able to pass in the fn instead of wrapping here
var buildExpectationResult = j$.buildExpectationResult,
exceptionFormatter = new j$.ExceptionFormatter(),
expectationResultFactory = function(attrs) {
attrs.messageFormatter = exceptionFormatter.message;
attrs.stackFormatter = exceptionFormatter.stack;
return buildExpectationResult(attrs);
};
/**
* Sets whether Jasmine should throw an Error when an expectation fails.
* This causes a spec to only have one expectation failure.
* @name Env#throwOnExpectationFailure
* @since 2.3.0
* @function
* @param {Boolean} value Whether to throw when a expectation fails
* @deprecated Use the `oneFailurePerSpec` option with {@link Env#configure}
*/
this.throwOnExpectationFailure = function(value) {
this.deprecated(
'Setting throwOnExpectationFailure directly on Env is deprecated and will be removed in a future version of Jasmine, please use the oneFailurePerSpec option in `configure`'
);
this.configure({ oneFailurePerSpec: !!value });
};
this.throwingExpectationFailures = function() {
this.deprecated(
'Getting throwingExpectationFailures directly from Env is deprecated and will be removed in a future version of Jasmine, please check the oneFailurePerSpec option from `configuration`'
);
return config.oneFailurePerSpec;
};
/**
* Set whether to stop suite execution when a spec fails
* @name Env#stopOnSpecFailure
* @since 2.7.0
* @function
* @param {Boolean} value Whether to stop suite execution when a spec fails
* @deprecated Use the `failFast` option with {@link Env#configure}
*/
this.stopOnSpecFailure = function(value) {
this.deprecated(
'Setting stopOnSpecFailure directly is deprecated and will be removed in a future version of Jasmine, please use the failFast option in `configure`'
);
this.configure({ failFast: !!value });
};
this.stoppingOnSpecFailure = function() {
this.deprecated(
'Getting stoppingOnSpecFailure directly from Env is deprecated and will be removed in a future version of Jasmine, please check the failFast option from `configuration`'
);
return config.failFast;
};
/**
* Set whether to randomize test execution order
* @name Env#randomizeTests
* @since 2.4.0
* @function
* @param {Boolean} value Whether to randomize execution order
* @deprecated Use the `random` option with {@link Env#configure}
*/
this.randomizeTests = function(value) {
this.deprecated(
'Setting randomizeTests directly is deprecated and will be removed in a future version of Jasmine, please use the random option in `configure`'
);
config.random = !!value;
};
this.randomTests = function() {
this.deprecated(
'Getting randomTests directly from Env is deprecated and will be removed in a future version of Jasmine, please check the random option from `configuration`'
);
return config.random;
};
/**
* Set the random number seed for spec randomization
* @name Env#seed
* @since 2.4.0
* @function
* @param {Number} value The seed value
* @deprecated Use the `seed` option with {@link Env#configure}
*/
this.seed = function(value) {
this.deprecated(
'Setting seed directly is deprecated and will be removed in a future version of Jasmine, please use the seed option in `configure`'
);
if (value) {
config.seed = value;
}
return config.seed;
};
this.hidingDisabled = function(value) {
this.deprecated(
'Getting hidingDisabled directly from Env is deprecated and will be removed in a future version of Jasmine, please check the hideDisabled option from `configuration`'
);
return config.hideDisabled;
};
/**
* @name Env#hideDisabled
* @since 3.2.0
* @function
*/
this.hideDisabled = function(value) {
this.deprecated(
'Setting hideDisabled directly is deprecated and will be removed in a future version of Jasmine, please use the hideDisabled option in `configure`'
);
config.hideDisabled = !!value;
};
this.deprecated = function(deprecation) {
var runnable = currentRunnable() || topSuite;
runnable.addDeprecationWarning(deprecation);
if (
typeof console !== 'undefined' &&
typeof console.error === 'function'
) {
console.error('DEPRECATION:', deprecation);
}
};
var queueRunnerFactory = function(options, args) {
var failFast = false;
if (options.isLeaf) {
failFast = config.oneFailurePerSpec;
} else if (!options.isReporter) {
failFast = config.failFast;
}
options.clearStack = options.clearStack || clearStack;
options.timeout = {
setTimeout: realSetTimeout,
clearTimeout: realClearTimeout
};
options.fail = self.fail;
options.globalErrors = globalErrors;
options.completeOnFirstError = failFast;
options.onException =
options.onException ||
function(e) {
(currentRunnable() || topSuite).onException(e);
};
options.deprecated = self.deprecated;
new j$.QueueRunner(options).execute(args);
};
var topSuite = new j$.Suite({
env: this,
id: getNextSuiteId(),
description: 'Jasmine__TopLevel__Suite',
expectationFactory: expectationFactory,
asyncExpectationFactory: suiteAsyncExpectationFactory,
expectationResultFactory: expectationResultFactory
});
defaultResourcesForRunnable(topSuite.id);
currentDeclarationSuite = topSuite;
this.topSuite = function() {
return topSuite;
};
/**
* This represents the available reporter callback for an object passed to {@link Env#addReporter}.
* @interface Reporter
* @see custom_reporter
*/
var reporter = new j$.ReportDispatcher(
[
/**
* `jasmineStarted` is called after all of the specs have been loaded, but just before execution starts.
* @function
* @name Reporter#jasmineStarted
* @param {JasmineStartedInfo} suiteInfo Information about the full Jasmine suite that is being run
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.
* @returns {} Optionally return a Promise instead of using `done` to cause Jasmine to wait for completion.
* @see async
*/
'jasmineStarted',
/**
* When the entire suite has finished execution `jasmineDone` is called
* @function
* @name Reporter#jasmineDone
* @param {JasmineDoneInfo} suiteInfo Information about the full Jasmine suite that just finished running.
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.
* @returns {} Optionally return a Promise instead of using `done`