Use arrow fns rather than self = this

This commit is contained in:
Steve Gravrock
2022-06-11 11:54:09 -07:00
parent e2e2275d41
commit 96000220b1
10 changed files with 436 additions and 458 deletions
+218 -229
View File
@@ -791,28 +791,26 @@ getJasmineRequireObj().Spec = function(j$) {
}; };
Spec.prototype.execute = function(onComplete, excluded, failSpecWithNoExp) { Spec.prototype.execute = function(onComplete, excluded, failSpecWithNoExp) {
const self = this;
const onStart = { const onStart = {
fn: function(done) { fn: done => {
self.timer.start(); this.timer.start();
self.onStart(self, done); this.onStart(this, done);
} }
}; };
const complete = { const complete = {
fn: function(done) { fn: done => {
if (self.autoCleanClosures) { if (this.autoCleanClosures) {
self.queueableFn.fn = null; this.queueableFn.fn = null;
} }
self.result.status = self.status(excluded, failSpecWithNoExp); this.result.status = this.status(excluded, failSpecWithNoExp);
self.result.duration = self.timer.elapsed(); this.result.duration = this.timer.elapsed();
if (self.result.status !== 'failed') { if (this.result.status !== 'failed') {
self.result.debugLogs = null; this.result.debugLogs = null;
} }
self.resultCallback(self.result, done); this.resultCallback(this.result, done);
}, },
type: 'specCleanup' type: 'specCleanup'
}; };
@@ -822,24 +820,22 @@ getJasmineRequireObj().Spec = function(j$) {
const runnerConfig = { const runnerConfig = {
isLeaf: true, isLeaf: true,
queueableFns: [...fns.befores, this.queueableFn, ...fns.afters], queueableFns: [...fns.befores, this.queueableFn, ...fns.afters],
onException: function() { onException: e => this.handleException(e),
self.handleException.apply(self, arguments); onMultipleDone: () => {
},
onMultipleDone: function() {
// Issue a deprecation. Include the context ourselves and pass // Issue a deprecation. Include the context ourselves and pass
// ignoreRunnable: true, since getting here always means that we've already // ignoreRunnable: true, since getting here always means that we've already
// moved on and the current runnable isn't the one that caused the problem. // moved on and the current runnable isn't the one that caused the problem.
self.onLateError( this.onLateError(
new Error( new Error(
'An asynchronous spec, beforeEach, or afterEach function called its ' + 'An asynchronous spec, beforeEach, or afterEach function called its ' +
"'done' callback more than once.\n(in spec: " + "'done' callback more than once.\n(in spec: " +
self.getFullName() + this.getFullName() +
')' ')'
) )
); );
}, },
onComplete: function() { onComplete: () => {
if (self.result.status === 'failed') { if (this.result.status === 'failed') {
onComplete(new j$.StopExecutionError('spec failed')); onComplete(new j$.StopExecutionError('spec failed'));
} else { } else {
onComplete(); onComplete();
@@ -3366,24 +3362,23 @@ getJasmineRequireObj().Clock = function() {
* @hideconstructor * @hideconstructor
*/ */
function Clock(global, delayedFunctionSchedulerFactory, mockDate) { function Clock(global, delayedFunctionSchedulerFactory, mockDate) {
const self = this, const realTimingFunctions = {
realTimingFunctions = { setTimeout: global.setTimeout,
setTimeout: global.setTimeout, clearTimeout: global.clearTimeout,
clearTimeout: global.clearTimeout, setInterval: global.setInterval,
setInterval: global.setInterval, clearInterval: global.clearInterval
clearInterval: global.clearInterval };
}, const fakeTimingFunctions = {
fakeTimingFunctions = { setTimeout: setTimeout,
setTimeout: setTimeout, clearTimeout: clearTimeout,
clearTimeout: clearTimeout, setInterval: setInterval,
setInterval: setInterval, clearInterval: clearInterval
clearInterval: clearInterval };
};
let installed = false; let installed = false;
let delayedFunctionScheduler; let delayedFunctionScheduler;
let timer; let timer;
self.FakeTimeout = FakeTimeout; this.FakeTimeout = FakeTimeout;
/** /**
* Install the mock clock over the built-in methods. * Install the mock clock over the built-in methods.
@@ -3392,7 +3387,7 @@ getJasmineRequireObj().Clock = function() {
* @function * @function
* @return {Clock} * @return {Clock}
*/ */
self.install = function() { this.install = function() {
if (!originalTimingFunctionsIntact()) { if (!originalTimingFunctionsIntact()) {
throw new Error( throw new Error(
'Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?' 'Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?'
@@ -3403,7 +3398,7 @@ getJasmineRequireObj().Clock = function() {
delayedFunctionScheduler = delayedFunctionSchedulerFactory(); delayedFunctionScheduler = delayedFunctionSchedulerFactory();
installed = true; installed = true;
return self; return this;
}; };
/** /**
@@ -3412,7 +3407,7 @@ getJasmineRequireObj().Clock = function() {
* @since 2.0.0 * @since 2.0.0
* @function * @function
*/ */
self.uninstall = function() { this.uninstall = function() {
delayedFunctionScheduler = null; delayedFunctionScheduler = null;
mockDate.uninstall(); mockDate.uninstall();
replace(global, realTimingFunctions); replace(global, realTimingFunctions);
@@ -3430,7 +3425,7 @@ getJasmineRequireObj().Clock = function() {
* @function * @function
* @param {Function} closure The function to be called. * @param {Function} closure The function to be called.
*/ */
self.withMock = function(closure) { this.withMock = function(closure) {
this.install(); this.install();
try { try {
closure(); closure();
@@ -3446,29 +3441,29 @@ getJasmineRequireObj().Clock = function() {
* @function * @function
* @param {Date} [initialDate=now] The `Date` to provide. * @param {Date} [initialDate=now] The `Date` to provide.
*/ */
self.mockDate = function(initialDate) { this.mockDate = function(initialDate) {
mockDate.install(initialDate); mockDate.install(initialDate);
}; };
self.setTimeout = function(fn, delay, params) { this.setTimeout = function(fn, delay, params) {
return Function.prototype.apply.apply(timer.setTimeout, [ return Function.prototype.apply.apply(timer.setTimeout, [
global, global,
arguments arguments
]); ]);
}; };
self.setInterval = function(fn, delay, params) { this.setInterval = function(fn, delay, params) {
return Function.prototype.apply.apply(timer.setInterval, [ return Function.prototype.apply.apply(timer.setInterval, [
global, global,
arguments arguments
]); ]);
}; };
self.clearTimeout = function(id) { this.clearTimeout = function(id) {
return Function.prototype.call.apply(timer.clearTimeout, [global, id]); return Function.prototype.call.apply(timer.clearTimeout, [global, id]);
}; };
self.clearInterval = function(id) { this.clearInterval = function(id) {
return Function.prototype.call.apply(timer.clearInterval, [global, id]); return Function.prototype.call.apply(timer.clearInterval, [global, id]);
}; };
@@ -3479,7 +3474,7 @@ getJasmineRequireObj().Clock = function() {
* @function * @function
* @param {int} millis The number of milliseconds to tick. * @param {int} millis The number of milliseconds to tick.
*/ */
self.tick = function(millis) { this.tick = function(millis) {
if (installed) { if (installed) {
delayedFunctionScheduler.tick(millis, function(millis) { delayedFunctionScheduler.tick(millis, function(millis) {
mockDate.tick(millis); mockDate.tick(millis);
@@ -3491,7 +3486,7 @@ getJasmineRequireObj().Clock = function() {
} }
}; };
return self; return this;
function originalTimingFunctionsIntact() { function originalTimingFunctionsIntact() {
return ( return (
@@ -3636,21 +3631,20 @@ getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) {
getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
function DelayedFunctionScheduler() { function DelayedFunctionScheduler() {
const self = this; this.scheduledLookup_ = [];
const scheduledLookup = []; this.scheduledFunctions_ = {};
const scheduledFunctions = {}; this.currentTime_ = 0;
let currentTime = 0; this.delayedFnCount_ = 0;
let delayedFnCount = 0; this.deletedKeys_ = [];
let deletedKeys = [];
self.tick = function(millis, tickDate) { this.tick = function(millis, tickDate) {
millis = millis || 0; millis = millis || 0;
const endTime = currentTime + millis; const endTime = this.currentTime_ + millis;
runScheduledFunctions(endTime, tickDate); this.runScheduledFunctions_(endTime, tickDate);
}; };
self.scheduleFunction = function( this.scheduleFunction = function(
funcToCall, funcToCall,
millis, millis,
params, params,
@@ -3669,8 +3663,8 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
} }
millis = millis || 0; millis = millis || 0;
timeoutKey = timeoutKey || ++delayedFnCount; timeoutKey = timeoutKey || ++this.delayedFnCount_;
runAtMillis = runAtMillis || currentTime + millis; runAtMillis = runAtMillis || this.currentTime_ + millis;
const funcToSchedule = { const funcToSchedule = {
runAtMillis: runAtMillis, runAtMillis: runAtMillis,
@@ -3681,12 +3675,12 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
millis: millis millis: millis
}; };
if (runAtMillis in scheduledFunctions) { if (runAtMillis in this.scheduledFunctions_) {
scheduledFunctions[runAtMillis].push(funcToSchedule); this.scheduledFunctions_[runAtMillis].push(funcToSchedule);
} else { } else {
scheduledFunctions[runAtMillis] = [funcToSchedule]; this.scheduledFunctions_[runAtMillis] = [funcToSchedule];
scheduledLookup.push(runAtMillis); this.scheduledLookup_.push(runAtMillis);
scheduledLookup.sort(function(a, b) { this.scheduledLookup_.sort(function(a, b) {
return a - b; return a - b;
}); });
} }
@@ -3694,19 +3688,19 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
return timeoutKey; return timeoutKey;
}; };
self.removeFunctionWithId = function(timeoutKey) { this.removeFunctionWithId = function(timeoutKey) {
deletedKeys.push(timeoutKey); this.deletedKeys_.push(timeoutKey);
for (const runAtMillis in scheduledFunctions) { for (const runAtMillis in this.scheduledFunctions_) {
const funcs = scheduledFunctions[runAtMillis]; const funcs = this.scheduledFunctions_[runAtMillis];
const i = indexOfFirstToPass(funcs, function(func) { const i = indexOfFirstToPass(funcs, function(func) {
return func.timeoutKey === timeoutKey; return func.timeoutKey === timeoutKey;
}); });
if (i > -1) { if (i > -1) {
if (funcs.length === 1) { if (funcs.length === 1) {
delete scheduledFunctions[runAtMillis]; delete this.scheduledFunctions_[runAtMillis];
deleteFromLookup(runAtMillis); this.deleteFromLookup_(runAtMillis);
} else { } else {
funcs.splice(i, 1); funcs.splice(i, 1);
} }
@@ -3718,93 +3712,99 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
} }
}; };
return self; return this;
}
function indexOfFirstToPass(array, testFn) { DelayedFunctionScheduler.prototype.runScheduledFunctions_ = function(
let index = -1; endTime,
tickDate
) {
tickDate = tickDate || function() {};
if (
this.scheduledLookup_.length === 0 ||
this.scheduledLookup_[0] > endTime
) {
if (endTime >= this.currentTime_) {
tickDate(endTime - this.currentTime_);
this.currentTime_ = endTime;
}
return;
}
for (let i = 0; i < array.length; ++i) { do {
if (testFn(array[i])) { this.deletedKeys_ = [];
index = i; const newCurrentTime = this.scheduledLookup_.shift();
break; if (newCurrentTime >= this.currentTime_) {
tickDate(newCurrentTime - this.currentTime_);
this.currentTime_ = newCurrentTime;
}
const funcsToRun = this.scheduledFunctions_[this.currentTime_];
delete this.scheduledFunctions_[this.currentTime_];
for (const fn of funcsToRun) {
if (fn.recurring) {
this.reschedule_(fn);
} }
} }
return index; for (const fn of funcsToRun) {
if (this.deletedKeys_.includes(fn.timeoutKey)) {
// skip a timeoutKey deleted whilst we were running
return;
}
fn.funcToCall.apply(null, fn.params || []);
}
this.deletedKeys_ = [];
} while (
this.scheduledLookup_.length > 0 &&
// checking first if we're out of time prevents setTimeout(0)
// scheduled in a funcToRun from forcing an extra iteration
this.currentTime_ !== endTime &&
this.scheduledLookup_[0] <= endTime
);
// ran out of functions to call, but still time left on the clock
if (endTime >= this.currentTime_) {
tickDate(endTime - this.currentTime_);
this.currentTime_ = endTime;
} }
};
function deleteFromLookup(key) { DelayedFunctionScheduler.prototype.reschedule_ = function(scheduledFn) {
const value = Number(key); this.scheduleFunction(
const i = indexOfFirstToPass(scheduledLookup, function(millis) { scheduledFn.funcToCall,
return millis === value; scheduledFn.millis,
}); scheduledFn.params,
true,
scheduledFn.timeoutKey,
scheduledFn.runAtMillis + scheduledFn.millis
);
};
if (i > -1) { DelayedFunctionScheduler.prototype.deleteFromLookup_ = function(key) {
scheduledLookup.splice(i, 1); const value = Number(key);
const i = indexOfFirstToPass(this.scheduledLookup_, function(millis) {
return millis === value;
});
if (i > -1) {
this.scheduledLookup_.splice(i, 1);
}
};
function indexOfFirstToPass(array, testFn) {
let index = -1;
for (let i = 0; i < array.length; ++i) {
if (testFn(array[i])) {
index = i;
break;
} }
} }
function reschedule(scheduledFn) { return index;
self.scheduleFunction(
scheduledFn.funcToCall,
scheduledFn.millis,
scheduledFn.params,
true,
scheduledFn.timeoutKey,
scheduledFn.runAtMillis + scheduledFn.millis
);
}
function runScheduledFunctions(endTime, tickDate) {
tickDate = tickDate || function() {};
if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) {
if (endTime >= currentTime) {
tickDate(endTime - currentTime);
currentTime = endTime;
}
return;
}
do {
deletedKeys = [];
const newCurrentTime = scheduledLookup.shift();
if (newCurrentTime >= currentTime) {
tickDate(newCurrentTime - currentTime);
currentTime = newCurrentTime;
}
const funcsToRun = scheduledFunctions[currentTime];
delete scheduledFunctions[currentTime];
for (const fn of funcsToRun) {
if (fn.recurring) {
reschedule(fn);
}
}
for (const fn of funcsToRun) {
if (deletedKeys.includes(fn.timeoutKey)) {
// skip a timeoutKey deleted whilst we were running
return;
}
fn.funcToCall.apply(null, fn.params || []);
}
deletedKeys = [];
} while (
scheduledLookup.length > 0 &&
// checking first if we're out of time prevents setTimeout(0)
// scheduled in a funcToRun from forcing an extra iteration
currentTime !== endTime &&
scheduledLookup[0] <= endTime
);
// ran out of functions to call, but still time left on the clock
if (endTime >= currentTime) {
tickDate(endTime - currentTime);
currentTime = endTime;
}
}
} }
return DelayedFunctionScheduler; return DelayedFunctionScheduler;
@@ -4356,12 +4356,26 @@ getJasmineRequireObj().Expector = function(j$) {
}; };
Expector.prototype.buildMessage = function(result) { Expector.prototype.buildMessage = function(result) {
const self = this;
if (result.pass) { if (result.pass) {
return ''; return '';
} }
const defaultMessage = () => {
if (!result.message) {
const args = this.args.slice();
args.unshift(false);
args.unshift(this.matcherName);
return this.matchersUtil.buildFailureMessage.apply(
this.matchersUtil,
args
);
} else if (j$.isFunction_(result.message)) {
return result.message();
} else {
return result.message;
}
};
const msg = this.filters.buildFailureMessage( const msg = this.filters.buildFailureMessage(
result, result,
this.matcherName, this.matcherName,
@@ -4370,22 +4384,6 @@ getJasmineRequireObj().Expector = function(j$) {
defaultMessage defaultMessage
); );
return this.filters.modifyFailureMessage(msg || defaultMessage()); return this.filters.modifyFailureMessage(msg || defaultMessage());
function defaultMessage() {
if (!result.message) {
const args = self.args.slice();
args.unshift(false);
args.unshift(self.matcherName);
return self.matchersUtil.buildFailureMessage.apply(
self.matchersUtil,
args
);
} else if (j$.isFunction_(result.message)) {
return result.message();
} else {
return result.message;
}
}
}; };
Expector.prototype.compare = function(matcherName, matcherFactory, args) { Expector.prototype.compare = function(matcherName, matcherFactory, args) {
@@ -5105,7 +5103,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
}; };
MatchersUtil.prototype.buildFailureMessage = function() { MatchersUtil.prototype.buildFailureMessage = function() {
const self = this;
const args = Array.prototype.slice.call(arguments, 0), const args = Array.prototype.slice.call(arguments, 0),
matcherName = args[0], matcherName = args[0],
isNot = args[1], isNot = args[1],
@@ -5117,7 +5114,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
let message = let message =
'Expected ' + 'Expected ' +
self.pp(actual) + this.pp(actual) +
(isNot ? ' not ' : ' ') + (isNot ? ' not ' : ' ') +
englishyPredicate; englishyPredicate;
@@ -5126,7 +5123,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
if (i > 0) { if (i > 0) {
message += ','; message += ',';
} }
message += ' ' + self.pp(expected[i]); message += ' ' + this.pp(expected[i]);
} }
} }
@@ -5201,7 +5198,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
// [Underscore](http://underscorejs.org) // [Underscore](http://underscorejs.org)
MatchersUtil.prototype.eq_ = function(a, b, aStack, bStack, diffBuilder) { MatchersUtil.prototype.eq_ = function(a, b, aStack, bStack, diffBuilder) {
let result = true; let result = true;
const self = this;
const asymmetricResult = this.asymmetricMatch_( const asymmetricResult = this.asymmetricMatch_(
a, a,
@@ -5286,7 +5282,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
case '[object ArrayBuffer]': case '[object ArrayBuffer]':
// If we have an instance of ArrayBuffer the Uint8Array ctor // If we have an instance of ArrayBuffer the Uint8Array ctor
// will be defined as well // will be defined as well
return self.eq_( return this.eq_(
new Uint8Array(a), new Uint8Array(a),
new Uint8Array(b), new Uint8Array(b),
aStack, aStack,
@@ -5356,15 +5352,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
}); });
for (let i = 0; i < aLength || i < bLength; i++) { for (let i = 0; i < aLength || i < bLength; i++) {
diffBuilder.withPath(i, function() { diffBuilder.withPath(i, () => {
if (i >= bLength) { if (i >= bLength) {
diffBuilder.recordMismatch( diffBuilder.recordMismatch(
actualArrayIsLongerFormatter.bind(null, self.pp) actualArrayIsLongerFormatter.bind(null, this.pp)
); );
result = false; result = false;
} else { } else {
result = result =
self.eq_( this.eq_(
i < aLength ? a[i] : void 0, i < aLength ? a[i] : void 0,
i < bLength ? b[i] : void 0, i < bLength ? b[i] : void 0,
aStack, aStack,
@@ -5529,8 +5525,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
continue; continue;
} }
diffBuilder.withPath(key, function() { diffBuilder.withPath(key, () => {
if (!self.eq_(a[key], b[key], aStack, bStack, diffBuilder)) { if (!this.eq_(a[key], b[key], aStack, bStack, diffBuilder)) {
result = false; result = false;
} }
}); });
@@ -7388,19 +7384,18 @@ getJasmineRequireObj().toThrowMatching = function(j$) {
getJasmineRequireObj().MockDate = function(j$) { getJasmineRequireObj().MockDate = function(j$) {
function MockDate(global) { function MockDate(global) {
const self = this;
let currentTime = 0; let currentTime = 0;
if (!global || !global.Date) { if (!global || !global.Date) {
self.install = function() {}; this.install = function() {};
self.tick = function() {}; this.tick = function() {};
self.uninstall = function() {}; this.uninstall = function() {};
return self; return this;
} }
const GlobalDate = global.Date; const GlobalDate = global.Date;
self.install = function(mockDate) { this.install = function(mockDate) {
if (mockDate instanceof GlobalDate) { if (mockDate instanceof GlobalDate) {
currentTime = mockDate.getTime(); currentTime = mockDate.getTime();
} else { } else {
@@ -7417,19 +7412,19 @@ getJasmineRequireObj().MockDate = function(j$) {
global.Date = FakeDate; global.Date = FakeDate;
}; };
self.tick = function(millis) { this.tick = function(millis) {
millis = millis || 0; millis = millis || 0;
currentTime = currentTime + millis; currentTime = currentTime + millis;
}; };
self.uninstall = function() { this.uninstall = function() {
currentTime = 0; currentTime = 0;
global.Date = GlobalDate; global.Date = GlobalDate;
}; };
createDateProperties(); createDateProperties();
return self; return this;
function FakeDate() { function FakeDate() {
switch (arguments.length) { switch (arguments.length) {
@@ -7935,12 +7930,11 @@ getJasmineRequireObj().QueueRunner = function(j$) {
} }
QueueRunner.prototype.execute = function() { QueueRunner.prototype.execute = function() {
const self = this; this.handleFinalError = (message, source, lineno, colno, error) => {
this.handleFinalError = function(message, source, lineno, colno, error) {
// Older browsers would send the error as the first parameter. HTML5 // Older browsers would send the error as the first parameter. HTML5
// specifies the the five parameters above. The error instance should // specifies the the five parameters above. The error instance should
// be preffered, otherwise the call stack would get lost. // be preffered, otherwise the call stack would get lost.
self.onException(error || message); this.onException(error || message);
}; };
this.globalErrors.pushListener(this.handleFinalError); this.globalErrors.pushListener(this.handleFinalError);
this.run(0); this.run(0);
@@ -7963,44 +7957,49 @@ getJasmineRequireObj().QueueRunner = function(j$) {
QueueRunner.prototype.attempt = function attempt(iterativeIndex) { QueueRunner.prototype.attempt = function attempt(iterativeIndex) {
let timeoutId; let timeoutId;
let timedOut; let timedOut;
const self = this;
let completedSynchronously = true; let completedSynchronously = true;
const onException = e => {
this.onException(e);
this.recordError_(iterativeIndex);
};
function handleError(error) { function handleError(error) {
// TODO probably shouldn't next() right away here. // TODO probably shouldn't next() right away here.
// That makes debugging async failures much more confusing. // That makes debugging async failures much more confusing.
onException(error); onException(error);
} }
const cleanup = once(function cleanup() { const cleanup = once(() => {
if (timeoutId !== void 0) { if (timeoutId !== void 0) {
self.clearTimeout(timeoutId); this.clearTimeout(timeoutId);
} }
self.globalErrors.popListener(handleError); this.globalErrors.popListener(handleError);
}); });
const next = once( const next = once(
function next(err) { err => {
cleanup(); cleanup();
if (typeof err !== 'undefined') { if (typeof err !== 'undefined') {
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) { if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
self.fail(err); this.fail(err);
} }
self.recordError_(iterativeIndex); this.recordError_(iterativeIndex);
} }
function runNext() { const runNext = () => {
self.run(self.nextFnIx_(iterativeIndex)); this.run(this.nextFnIx_(iterativeIndex));
} };
if (completedSynchronously) { if (completedSynchronously) {
self.setTimeout(runNext); this.setTimeout(runNext);
} else { } else {
runNext(); runNext();
} }
}, },
function() { () => {
try { try {
if (!timedOut) { if (!timedOut) {
self.onMultipleDone(); this.onMultipleDone();
} }
} catch (error) { } catch (error) {
// Any error we catch here is probably due to a bug in Jasmine, // Any error we catch here is probably due to a bug in Jasmine,
@@ -8011,20 +8010,20 @@ getJasmineRequireObj().QueueRunner = function(j$) {
} }
); );
timedOut = false; timedOut = false;
const queueableFn = self.queueableFns[iterativeIndex]; const queueableFn = this.queueableFns[iterativeIndex];
next.fail = function nextFail() { next.fail = function nextFail() {
self.fail.apply(null, arguments); this.fail.apply(null, arguments);
self.recordError_(iterativeIndex); this.recordError_(iterativeIndex);
next(); next();
}; }.bind(this);
self.globalErrors.pushListener(handleError); this.globalErrors.pushListener(handleError);
if (queueableFn.timeout !== undefined) { if (queueableFn.timeout !== undefined) {
const timeoutInterval = const timeoutInterval =
queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL; queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL;
timeoutId = self.setTimeout(function() { timeoutId = this.setTimeout(function() {
timedOut = true; timedOut = true;
const error = new Error( const error = new Error(
'Timeout - Async function did not complete within ' + 'Timeout - Async function did not complete within ' +
@@ -8046,7 +8045,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
let maybeThenable; let maybeThenable;
if (queueableFn.fn.length === 0) { if (queueableFn.fn.length === 0) {
maybeThenable = queueableFn.fn.call(self.userContext); maybeThenable = queueableFn.fn.call(this.userContext);
if (maybeThenable && j$.isFunction_(maybeThenable.then)) { if (maybeThenable && j$.isFunction_(maybeThenable.then)) {
maybeThenable.then( maybeThenable.then(
@@ -8057,24 +8056,19 @@ getJasmineRequireObj().QueueRunner = function(j$) {
return { completedSynchronously: false }; return { completedSynchronously: false };
} }
} else { } else {
maybeThenable = queueableFn.fn.call(self.userContext, next); maybeThenable = queueableFn.fn.call(this.userContext, next);
this.diagnoseConflictingAsync_(queueableFn.fn, maybeThenable); this.diagnoseConflictingAsync_(queueableFn.fn, maybeThenable);
completedSynchronously = false; completedSynchronously = false;
return { completedSynchronously: false }; return { completedSynchronously: false };
} }
} catch (e) { } catch (e) {
onException(e); onException(e);
self.recordError_(iterativeIndex); this.recordError_(iterativeIndex);
} }
cleanup(); cleanup();
return { completedSynchronously: true }; return { completedSynchronously: true };
function onException(e) {
self.onException(e);
self.recordError_(iterativeIndex);
}
function onPromiseRejection(e) { function onPromiseRejection(e) {
onException(e); onException(e);
next(); next();
@@ -8083,7 +8077,6 @@ getJasmineRequireObj().QueueRunner = function(j$) {
QueueRunner.prototype.run = function(recursiveIndex) { QueueRunner.prototype.run = function(recursiveIndex) {
const length = this.queueableFns.length; const length = this.queueableFns.length;
const self = this;
for ( for (
let iterativeIndex = recursiveIndex; let iterativeIndex = recursiveIndex;
@@ -8097,13 +8090,13 @@ getJasmineRequireObj().QueueRunner = function(j$) {
} }
} }
this.clearStack(function() { this.clearStack(() => {
self.globalErrors.popListener(self.handleFinalError); this.globalErrors.popListener(this.handleFinalError);
if (self.errored_) { if (this.errored_) {
self.onComplete(new StopExecutionError()); this.onComplete(new StopExecutionError());
} else { } else {
self.onComplete(); this.onComplete();
} }
}); });
}; };
@@ -8929,8 +8922,6 @@ getJasmineRequireObj().SpyFactory = function(j$) {
getDefaultStrategyFn, getDefaultStrategyFn,
getMatchersUtil getMatchersUtil
) { ) {
const self = this;
this.createSpy = function(name, originalFn) { this.createSpy = function(name, originalFn) {
return j$.Spy(name, getMatchersUtil(), { return j$.Spy(name, getMatchersUtil(), {
originalFn, originalFn,
@@ -8953,7 +8944,7 @@ getJasmineRequireObj().SpyFactory = function(j$) {
const methods = normalizeKeyValues(methodNames); const methods = normalizeKeyValues(methodNames);
for (let i = 0; i < methods.length; i++) { for (let i = 0; i < methods.length; i++) {
const spy = (obj[methods[i][0]] = self.createSpy( const spy = (obj[methods[i][0]] = this.createSpy(
baseName + '.' + methods[i][0] baseName + '.' + methods[i][0]
)); ));
if (methods[i].length > 1) { if (methods[i].length > 1) {
@@ -8965,8 +8956,8 @@ getJasmineRequireObj().SpyFactory = function(j$) {
for (let i = 0; i < properties.length; i++) { for (let i = 0; i < properties.length; i++) {
const descriptor = { const descriptor = {
enumerable: true, enumerable: true,
get: self.createSpy(baseName + '.' + properties[i][0] + '.get'), get: this.createSpy(baseName + '.' + properties[i][0] + '.get'),
set: self.createSpy(baseName + '.' + properties[i][0] + '.set') set: this.createSpy(baseName + '.' + properties[i][0] + '.set')
}; };
if (properties[i].length > 1) { if (properties[i].length > 1) {
descriptor.get.and.returnValue(properties[i][1]); descriptor.get.and.returnValue(properties[i][1]);
@@ -9267,8 +9258,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
function SpyStrategy(options) { function SpyStrategy(options) {
options = options || {}; options = options || {};
const self = this;
/** /**
* Get the identifying information for the spy. * Get the identifying information for the spy.
* @name SpyStrategy#identity * @name SpyStrategy#identity
@@ -9296,10 +9285,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
* @param {*} value The value to return. * @param {*} value The value to return.
*/ */
this.resolveTo = function(value) { this.resolveTo = function(value) {
self.plan = function() { this.plan = function() {
return Promise.resolve(value); return Promise.resolve(value);
}; };
return self.getSpy(); return this.getSpy();
}; };
/** /**
@@ -9310,10 +9299,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
* @param {*} value The value to return. * @param {*} value The value to return.
*/ */
this.rejectWith = function(value) { this.rejectWith = function(value) {
self.plan = function() { this.plan = function() {
return Promise.reject(value); return Promise.reject(value);
}; };
return self.getSpy(); return this.getSpy();
}; };
} }
+24 -25
View File
@@ -14,24 +14,23 @@ getJasmineRequireObj().Clock = function() {
* @hideconstructor * @hideconstructor
*/ */
function Clock(global, delayedFunctionSchedulerFactory, mockDate) { function Clock(global, delayedFunctionSchedulerFactory, mockDate) {
const self = this, const realTimingFunctions = {
realTimingFunctions = { setTimeout: global.setTimeout,
setTimeout: global.setTimeout, clearTimeout: global.clearTimeout,
clearTimeout: global.clearTimeout, setInterval: global.setInterval,
setInterval: global.setInterval, clearInterval: global.clearInterval
clearInterval: global.clearInterval };
}, const fakeTimingFunctions = {
fakeTimingFunctions = { setTimeout: setTimeout,
setTimeout: setTimeout, clearTimeout: clearTimeout,
clearTimeout: clearTimeout, setInterval: setInterval,
setInterval: setInterval, clearInterval: clearInterval
clearInterval: clearInterval };
};
let installed = false; let installed = false;
let delayedFunctionScheduler; let delayedFunctionScheduler;
let timer; let timer;
self.FakeTimeout = FakeTimeout; this.FakeTimeout = FakeTimeout;
/** /**
* Install the mock clock over the built-in methods. * Install the mock clock over the built-in methods.
@@ -40,7 +39,7 @@ getJasmineRequireObj().Clock = function() {
* @function * @function
* @return {Clock} * @return {Clock}
*/ */
self.install = function() { this.install = function() {
if (!originalTimingFunctionsIntact()) { if (!originalTimingFunctionsIntact()) {
throw new Error( throw new Error(
'Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?' 'Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?'
@@ -51,7 +50,7 @@ getJasmineRequireObj().Clock = function() {
delayedFunctionScheduler = delayedFunctionSchedulerFactory(); delayedFunctionScheduler = delayedFunctionSchedulerFactory();
installed = true; installed = true;
return self; return this;
}; };
/** /**
@@ -60,7 +59,7 @@ getJasmineRequireObj().Clock = function() {
* @since 2.0.0 * @since 2.0.0
* @function * @function
*/ */
self.uninstall = function() { this.uninstall = function() {
delayedFunctionScheduler = null; delayedFunctionScheduler = null;
mockDate.uninstall(); mockDate.uninstall();
replace(global, realTimingFunctions); replace(global, realTimingFunctions);
@@ -78,7 +77,7 @@ getJasmineRequireObj().Clock = function() {
* @function * @function
* @param {Function} closure The function to be called. * @param {Function} closure The function to be called.
*/ */
self.withMock = function(closure) { this.withMock = function(closure) {
this.install(); this.install();
try { try {
closure(); closure();
@@ -94,29 +93,29 @@ getJasmineRequireObj().Clock = function() {
* @function * @function
* @param {Date} [initialDate=now] The `Date` to provide. * @param {Date} [initialDate=now] The `Date` to provide.
*/ */
self.mockDate = function(initialDate) { this.mockDate = function(initialDate) {
mockDate.install(initialDate); mockDate.install(initialDate);
}; };
self.setTimeout = function(fn, delay, params) { this.setTimeout = function(fn, delay, params) {
return Function.prototype.apply.apply(timer.setTimeout, [ return Function.prototype.apply.apply(timer.setTimeout, [
global, global,
arguments arguments
]); ]);
}; };
self.setInterval = function(fn, delay, params) { this.setInterval = function(fn, delay, params) {
return Function.prototype.apply.apply(timer.setInterval, [ return Function.prototype.apply.apply(timer.setInterval, [
global, global,
arguments arguments
]); ]);
}; };
self.clearTimeout = function(id) { this.clearTimeout = function(id) {
return Function.prototype.call.apply(timer.clearTimeout, [global, id]); return Function.prototype.call.apply(timer.clearTimeout, [global, id]);
}; };
self.clearInterval = function(id) { this.clearInterval = function(id) {
return Function.prototype.call.apply(timer.clearInterval, [global, id]); return Function.prototype.call.apply(timer.clearInterval, [global, id]);
}; };
@@ -127,7 +126,7 @@ getJasmineRequireObj().Clock = function() {
* @function * @function
* @param {int} millis The number of milliseconds to tick. * @param {int} millis The number of milliseconds to tick.
*/ */
self.tick = function(millis) { this.tick = function(millis) {
if (installed) { if (installed) {
delayedFunctionScheduler.tick(millis, function(millis) { delayedFunctionScheduler.tick(millis, function(millis) {
mockDate.tick(millis); mockDate.tick(millis);
@@ -139,7 +138,7 @@ getJasmineRequireObj().Clock = function() {
} }
}; };
return self; return this;
function originalTimingFunctionsIntact() { function originalTimingFunctionsIntact() {
return ( return (
+104 -99
View File
@@ -1,20 +1,19 @@
getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
function DelayedFunctionScheduler() { function DelayedFunctionScheduler() {
const self = this; this.scheduledLookup_ = [];
const scheduledLookup = []; this.scheduledFunctions_ = {};
const scheduledFunctions = {}; this.currentTime_ = 0;
let currentTime = 0; this.delayedFnCount_ = 0;
let delayedFnCount = 0; this.deletedKeys_ = [];
let deletedKeys = [];
self.tick = function(millis, tickDate) { this.tick = function(millis, tickDate) {
millis = millis || 0; millis = millis || 0;
const endTime = currentTime + millis; const endTime = this.currentTime_ + millis;
runScheduledFunctions(endTime, tickDate); this.runScheduledFunctions_(endTime, tickDate);
}; };
self.scheduleFunction = function( this.scheduleFunction = function(
funcToCall, funcToCall,
millis, millis,
params, params,
@@ -33,8 +32,8 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
} }
millis = millis || 0; millis = millis || 0;
timeoutKey = timeoutKey || ++delayedFnCount; timeoutKey = timeoutKey || ++this.delayedFnCount_;
runAtMillis = runAtMillis || currentTime + millis; runAtMillis = runAtMillis || this.currentTime_ + millis;
const funcToSchedule = { const funcToSchedule = {
runAtMillis: runAtMillis, runAtMillis: runAtMillis,
@@ -45,12 +44,12 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
millis: millis millis: millis
}; };
if (runAtMillis in scheduledFunctions) { if (runAtMillis in this.scheduledFunctions_) {
scheduledFunctions[runAtMillis].push(funcToSchedule); this.scheduledFunctions_[runAtMillis].push(funcToSchedule);
} else { } else {
scheduledFunctions[runAtMillis] = [funcToSchedule]; this.scheduledFunctions_[runAtMillis] = [funcToSchedule];
scheduledLookup.push(runAtMillis); this.scheduledLookup_.push(runAtMillis);
scheduledLookup.sort(function(a, b) { this.scheduledLookup_.sort(function(a, b) {
return a - b; return a - b;
}); });
} }
@@ -58,19 +57,19 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
return timeoutKey; return timeoutKey;
}; };
self.removeFunctionWithId = function(timeoutKey) { this.removeFunctionWithId = function(timeoutKey) {
deletedKeys.push(timeoutKey); this.deletedKeys_.push(timeoutKey);
for (const runAtMillis in scheduledFunctions) { for (const runAtMillis in this.scheduledFunctions_) {
const funcs = scheduledFunctions[runAtMillis]; const funcs = this.scheduledFunctions_[runAtMillis];
const i = indexOfFirstToPass(funcs, function(func) { const i = indexOfFirstToPass(funcs, function(func) {
return func.timeoutKey === timeoutKey; return func.timeoutKey === timeoutKey;
}); });
if (i > -1) { if (i > -1) {
if (funcs.length === 1) { if (funcs.length === 1) {
delete scheduledFunctions[runAtMillis]; delete this.scheduledFunctions_[runAtMillis];
deleteFromLookup(runAtMillis); this.deleteFromLookup_(runAtMillis);
} else { } else {
funcs.splice(i, 1); funcs.splice(i, 1);
} }
@@ -82,93 +81,99 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
} }
}; };
return self; return this;
}
function indexOfFirstToPass(array, testFn) { DelayedFunctionScheduler.prototype.runScheduledFunctions_ = function(
let index = -1; endTime,
tickDate
) {
tickDate = tickDate || function() {};
if (
this.scheduledLookup_.length === 0 ||
this.scheduledLookup_[0] > endTime
) {
if (endTime >= this.currentTime_) {
tickDate(endTime - this.currentTime_);
this.currentTime_ = endTime;
}
return;
}
for (let i = 0; i < array.length; ++i) { do {
if (testFn(array[i])) { this.deletedKeys_ = [];
index = i; const newCurrentTime = this.scheduledLookup_.shift();
break; if (newCurrentTime >= this.currentTime_) {
tickDate(newCurrentTime - this.currentTime_);
this.currentTime_ = newCurrentTime;
}
const funcsToRun = this.scheduledFunctions_[this.currentTime_];
delete this.scheduledFunctions_[this.currentTime_];
for (const fn of funcsToRun) {
if (fn.recurring) {
this.reschedule_(fn);
} }
} }
return index; for (const fn of funcsToRun) {
if (this.deletedKeys_.includes(fn.timeoutKey)) {
// skip a timeoutKey deleted whilst we were running
return;
}
fn.funcToCall.apply(null, fn.params || []);
}
this.deletedKeys_ = [];
} while (
this.scheduledLookup_.length > 0 &&
// checking first if we're out of time prevents setTimeout(0)
// scheduled in a funcToRun from forcing an extra iteration
this.currentTime_ !== endTime &&
this.scheduledLookup_[0] <= endTime
);
// ran out of functions to call, but still time left on the clock
if (endTime >= this.currentTime_) {
tickDate(endTime - this.currentTime_);
this.currentTime_ = endTime;
} }
};
function deleteFromLookup(key) { DelayedFunctionScheduler.prototype.reschedule_ = function(scheduledFn) {
const value = Number(key); this.scheduleFunction(
const i = indexOfFirstToPass(scheduledLookup, function(millis) { scheduledFn.funcToCall,
return millis === value; scheduledFn.millis,
}); scheduledFn.params,
true,
scheduledFn.timeoutKey,
scheduledFn.runAtMillis + scheduledFn.millis
);
};
if (i > -1) { DelayedFunctionScheduler.prototype.deleteFromLookup_ = function(key) {
scheduledLookup.splice(i, 1); const value = Number(key);
const i = indexOfFirstToPass(this.scheduledLookup_, function(millis) {
return millis === value;
});
if (i > -1) {
this.scheduledLookup_.splice(i, 1);
}
};
function indexOfFirstToPass(array, testFn) {
let index = -1;
for (let i = 0; i < array.length; ++i) {
if (testFn(array[i])) {
index = i;
break;
} }
} }
function reschedule(scheduledFn) { return index;
self.scheduleFunction(
scheduledFn.funcToCall,
scheduledFn.millis,
scheduledFn.params,
true,
scheduledFn.timeoutKey,
scheduledFn.runAtMillis + scheduledFn.millis
);
}
function runScheduledFunctions(endTime, tickDate) {
tickDate = tickDate || function() {};
if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) {
if (endTime >= currentTime) {
tickDate(endTime - currentTime);
currentTime = endTime;
}
return;
}
do {
deletedKeys = [];
const newCurrentTime = scheduledLookup.shift();
if (newCurrentTime >= currentTime) {
tickDate(newCurrentTime - currentTime);
currentTime = newCurrentTime;
}
const funcsToRun = scheduledFunctions[currentTime];
delete scheduledFunctions[currentTime];
for (const fn of funcsToRun) {
if (fn.recurring) {
reschedule(fn);
}
}
for (const fn of funcsToRun) {
if (deletedKeys.includes(fn.timeoutKey)) {
// skip a timeoutKey deleted whilst we were running
return;
}
fn.funcToCall.apply(null, fn.params || []);
}
deletedKeys = [];
} while (
scheduledLookup.length > 0 &&
// checking first if we're out of time prevents setTimeout(0)
// scheduled in a funcToRun from forcing an extra iteration
currentTime !== endTime &&
scheduledLookup[0] <= endTime
);
// ran out of functions to call, but still time left on the clock
if (endTime >= currentTime) {
tickDate(endTime - currentTime);
currentTime = endTime;
}
}
} }
return DelayedFunctionScheduler; return DelayedFunctionScheduler;
+16 -18
View File
@@ -26,12 +26,26 @@ getJasmineRequireObj().Expector = function(j$) {
}; };
Expector.prototype.buildMessage = function(result) { Expector.prototype.buildMessage = function(result) {
const self = this;
if (result.pass) { if (result.pass) {
return ''; return '';
} }
const defaultMessage = () => {
if (!result.message) {
const args = this.args.slice();
args.unshift(false);
args.unshift(this.matcherName);
return this.matchersUtil.buildFailureMessage.apply(
this.matchersUtil,
args
);
} else if (j$.isFunction_(result.message)) {
return result.message();
} else {
return result.message;
}
};
const msg = this.filters.buildFailureMessage( const msg = this.filters.buildFailureMessage(
result, result,
this.matcherName, this.matcherName,
@@ -40,22 +54,6 @@ getJasmineRequireObj().Expector = function(j$) {
defaultMessage defaultMessage
); );
return this.filters.modifyFailureMessage(msg || defaultMessage()); return this.filters.modifyFailureMessage(msg || defaultMessage());
function defaultMessage() {
if (!result.message) {
const args = self.args.slice();
args.unshift(false);
args.unshift(self.matcherName);
return self.matchersUtil.buildFailureMessage.apply(
self.matchersUtil,
args
);
} else if (j$.isFunction_(result.message)) {
return result.message();
} else {
return result.message;
}
}
}; };
Expector.prototype.compare = function(matcherName, matcherFactory, args) { Expector.prototype.compare = function(matcherName, matcherFactory, args) {
+8 -9
View File
@@ -1,18 +1,17 @@
getJasmineRequireObj().MockDate = function(j$) { getJasmineRequireObj().MockDate = function(j$) {
function MockDate(global) { function MockDate(global) {
const self = this;
let currentTime = 0; let currentTime = 0;
if (!global || !global.Date) { if (!global || !global.Date) {
self.install = function() {}; this.install = function() {};
self.tick = function() {}; this.tick = function() {};
self.uninstall = function() {}; this.uninstall = function() {};
return self; return this;
} }
const GlobalDate = global.Date; const GlobalDate = global.Date;
self.install = function(mockDate) { this.install = function(mockDate) {
if (mockDate instanceof GlobalDate) { if (mockDate instanceof GlobalDate) {
currentTime = mockDate.getTime(); currentTime = mockDate.getTime();
} else { } else {
@@ -29,19 +28,19 @@ getJasmineRequireObj().MockDate = function(j$) {
global.Date = FakeDate; global.Date = FakeDate;
}; };
self.tick = function(millis) { this.tick = function(millis) {
millis = millis || 0; millis = millis || 0;
currentTime = currentTime + millis; currentTime = currentTime + millis;
}; };
self.uninstall = function() { this.uninstall = function() {
currentTime = 0; currentTime = 0;
global.Date = GlobalDate; global.Date = GlobalDate;
}; };
createDateProperties(); createDateProperties();
return self; return this;
function FakeDate() { function FakeDate() {
switch (arguments.length) { switch (arguments.length) {
+34 -36
View File
@@ -66,12 +66,11 @@ getJasmineRequireObj().QueueRunner = function(j$) {
} }
QueueRunner.prototype.execute = function() { QueueRunner.prototype.execute = function() {
const self = this; this.handleFinalError = (message, source, lineno, colno, error) => {
this.handleFinalError = function(message, source, lineno, colno, error) {
// Older browsers would send the error as the first parameter. HTML5 // Older browsers would send the error as the first parameter. HTML5
// specifies the the five parameters above. The error instance should // specifies the the five parameters above. The error instance should
// be preffered, otherwise the call stack would get lost. // be preffered, otherwise the call stack would get lost.
self.onException(error || message); this.onException(error || message);
}; };
this.globalErrors.pushListener(this.handleFinalError); this.globalErrors.pushListener(this.handleFinalError);
this.run(0); this.run(0);
@@ -94,44 +93,49 @@ getJasmineRequireObj().QueueRunner = function(j$) {
QueueRunner.prototype.attempt = function attempt(iterativeIndex) { QueueRunner.prototype.attempt = function attempt(iterativeIndex) {
let timeoutId; let timeoutId;
let timedOut; let timedOut;
const self = this;
let completedSynchronously = true; let completedSynchronously = true;
const onException = e => {
this.onException(e);
this.recordError_(iterativeIndex);
};
function handleError(error) { function handleError(error) {
// TODO probably shouldn't next() right away here. // TODO probably shouldn't next() right away here.
// That makes debugging async failures much more confusing. // That makes debugging async failures much more confusing.
onException(error); onException(error);
} }
const cleanup = once(function cleanup() { const cleanup = once(() => {
if (timeoutId !== void 0) { if (timeoutId !== void 0) {
self.clearTimeout(timeoutId); this.clearTimeout(timeoutId);
} }
self.globalErrors.popListener(handleError); this.globalErrors.popListener(handleError);
}); });
const next = once( const next = once(
function next(err) { err => {
cleanup(); cleanup();
if (typeof err !== 'undefined') { if (typeof err !== 'undefined') {
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) { if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
self.fail(err); this.fail(err);
} }
self.recordError_(iterativeIndex); this.recordError_(iterativeIndex);
} }
function runNext() { const runNext = () => {
self.run(self.nextFnIx_(iterativeIndex)); this.run(this.nextFnIx_(iterativeIndex));
} };
if (completedSynchronously) { if (completedSynchronously) {
self.setTimeout(runNext); this.setTimeout(runNext);
} else { } else {
runNext(); runNext();
} }
}, },
function() { () => {
try { try {
if (!timedOut) { if (!timedOut) {
self.onMultipleDone(); this.onMultipleDone();
} }
} catch (error) { } catch (error) {
// Any error we catch here is probably due to a bug in Jasmine, // Any error we catch here is probably due to a bug in Jasmine,
@@ -142,20 +146,20 @@ getJasmineRequireObj().QueueRunner = function(j$) {
} }
); );
timedOut = false; timedOut = false;
const queueableFn = self.queueableFns[iterativeIndex]; const queueableFn = this.queueableFns[iterativeIndex];
next.fail = function nextFail() { next.fail = function nextFail() {
self.fail.apply(null, arguments); this.fail.apply(null, arguments);
self.recordError_(iterativeIndex); this.recordError_(iterativeIndex);
next(); next();
}; }.bind(this);
self.globalErrors.pushListener(handleError); this.globalErrors.pushListener(handleError);
if (queueableFn.timeout !== undefined) { if (queueableFn.timeout !== undefined) {
const timeoutInterval = const timeoutInterval =
queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL; queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL;
timeoutId = self.setTimeout(function() { timeoutId = this.setTimeout(function() {
timedOut = true; timedOut = true;
const error = new Error( const error = new Error(
'Timeout - Async function did not complete within ' + 'Timeout - Async function did not complete within ' +
@@ -177,7 +181,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
let maybeThenable; let maybeThenable;
if (queueableFn.fn.length === 0) { if (queueableFn.fn.length === 0) {
maybeThenable = queueableFn.fn.call(self.userContext); maybeThenable = queueableFn.fn.call(this.userContext);
if (maybeThenable && j$.isFunction_(maybeThenable.then)) { if (maybeThenable && j$.isFunction_(maybeThenable.then)) {
maybeThenable.then( maybeThenable.then(
@@ -188,24 +192,19 @@ getJasmineRequireObj().QueueRunner = function(j$) {
return { completedSynchronously: false }; return { completedSynchronously: false };
} }
} else { } else {
maybeThenable = queueableFn.fn.call(self.userContext, next); maybeThenable = queueableFn.fn.call(this.userContext, next);
this.diagnoseConflictingAsync_(queueableFn.fn, maybeThenable); this.diagnoseConflictingAsync_(queueableFn.fn, maybeThenable);
completedSynchronously = false; completedSynchronously = false;
return { completedSynchronously: false }; return { completedSynchronously: false };
} }
} catch (e) { } catch (e) {
onException(e); onException(e);
self.recordError_(iterativeIndex); this.recordError_(iterativeIndex);
} }
cleanup(); cleanup();
return { completedSynchronously: true }; return { completedSynchronously: true };
function onException(e) {
self.onException(e);
self.recordError_(iterativeIndex);
}
function onPromiseRejection(e) { function onPromiseRejection(e) {
onException(e); onException(e);
next(); next();
@@ -214,7 +213,6 @@ getJasmineRequireObj().QueueRunner = function(j$) {
QueueRunner.prototype.run = function(recursiveIndex) { QueueRunner.prototype.run = function(recursiveIndex) {
const length = this.queueableFns.length; const length = this.queueableFns.length;
const self = this;
for ( for (
let iterativeIndex = recursiveIndex; let iterativeIndex = recursiveIndex;
@@ -228,13 +226,13 @@ getJasmineRequireObj().QueueRunner = function(j$) {
} }
} }
this.clearStack(function() { this.clearStack(() => {
self.globalErrors.popListener(self.handleFinalError); this.globalErrors.popListener(this.handleFinalError);
if (self.errored_) { if (this.errored_) {
self.onComplete(new StopExecutionError()); this.onComplete(new StopExecutionError());
} else { } else {
self.onComplete(); this.onComplete();
} }
}); });
}; };
+17 -21
View File
@@ -100,28 +100,26 @@ getJasmineRequireObj().Spec = function(j$) {
}; };
Spec.prototype.execute = function(onComplete, excluded, failSpecWithNoExp) { Spec.prototype.execute = function(onComplete, excluded, failSpecWithNoExp) {
const self = this;
const onStart = { const onStart = {
fn: function(done) { fn: done => {
self.timer.start(); this.timer.start();
self.onStart(self, done); this.onStart(this, done);
} }
}; };
const complete = { const complete = {
fn: function(done) { fn: done => {
if (self.autoCleanClosures) { if (this.autoCleanClosures) {
self.queueableFn.fn = null; this.queueableFn.fn = null;
} }
self.result.status = self.status(excluded, failSpecWithNoExp); this.result.status = this.status(excluded, failSpecWithNoExp);
self.result.duration = self.timer.elapsed(); this.result.duration = this.timer.elapsed();
if (self.result.status !== 'failed') { if (this.result.status !== 'failed') {
self.result.debugLogs = null; this.result.debugLogs = null;
} }
self.resultCallback(self.result, done); this.resultCallback(this.result, done);
}, },
type: 'specCleanup' type: 'specCleanup'
}; };
@@ -131,24 +129,22 @@ getJasmineRequireObj().Spec = function(j$) {
const runnerConfig = { const runnerConfig = {
isLeaf: true, isLeaf: true,
queueableFns: [...fns.befores, this.queueableFn, ...fns.afters], queueableFns: [...fns.befores, this.queueableFn, ...fns.afters],
onException: function() { onException: e => this.handleException(e),
self.handleException.apply(self, arguments); onMultipleDone: () => {
},
onMultipleDone: function() {
// Issue a deprecation. Include the context ourselves and pass // Issue a deprecation. Include the context ourselves and pass
// ignoreRunnable: true, since getting here always means that we've already // ignoreRunnable: true, since getting here always means that we've already
// moved on and the current runnable isn't the one that caused the problem. // moved on and the current runnable isn't the one that caused the problem.
self.onLateError( this.onLateError(
new Error( new Error(
'An asynchronous spec, beforeEach, or afterEach function called its ' + 'An asynchronous spec, beforeEach, or afterEach function called its ' +
"'done' callback more than once.\n(in spec: " + "'done' callback more than once.\n(in spec: " +
self.getFullName() + this.getFullName() +
')' ')'
) )
); );
}, },
onComplete: function() { onComplete: () => {
if (self.result.status === 'failed') { if (this.result.status === 'failed') {
onComplete(new j$.StopExecutionError('spec failed')); onComplete(new j$.StopExecutionError('spec failed'));
} else { } else {
onComplete(); onComplete();
+3 -5
View File
@@ -4,8 +4,6 @@ getJasmineRequireObj().SpyFactory = function(j$) {
getDefaultStrategyFn, getDefaultStrategyFn,
getMatchersUtil getMatchersUtil
) { ) {
const self = this;
this.createSpy = function(name, originalFn) { this.createSpy = function(name, originalFn) {
return j$.Spy(name, getMatchersUtil(), { return j$.Spy(name, getMatchersUtil(), {
originalFn, originalFn,
@@ -28,7 +26,7 @@ getJasmineRequireObj().SpyFactory = function(j$) {
const methods = normalizeKeyValues(methodNames); const methods = normalizeKeyValues(methodNames);
for (let i = 0; i < methods.length; i++) { for (let i = 0; i < methods.length; i++) {
const spy = (obj[methods[i][0]] = self.createSpy( const spy = (obj[methods[i][0]] = this.createSpy(
baseName + '.' + methods[i][0] baseName + '.' + methods[i][0]
)); ));
if (methods[i].length > 1) { if (methods[i].length > 1) {
@@ -40,8 +38,8 @@ getJasmineRequireObj().SpyFactory = function(j$) {
for (let i = 0; i < properties.length; i++) { for (let i = 0; i < properties.length; i++) {
const descriptor = { const descriptor = {
enumerable: true, enumerable: true,
get: self.createSpy(baseName + '.' + properties[i][0] + '.get'), get: this.createSpy(baseName + '.' + properties[i][0] + '.get'),
set: self.createSpy(baseName + '.' + properties[i][0] + '.set') set: this.createSpy(baseName + '.' + properties[i][0] + '.set')
}; };
if (properties[i].length > 1) { if (properties[i].length > 1) {
descriptor.get.and.returnValue(properties[i][1]); descriptor.get.and.returnValue(properties[i][1]);
+4 -6
View File
@@ -5,8 +5,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
function SpyStrategy(options) { function SpyStrategy(options) {
options = options || {}; options = options || {};
const self = this;
/** /**
* Get the identifying information for the spy. * Get the identifying information for the spy.
* @name SpyStrategy#identity * @name SpyStrategy#identity
@@ -34,10 +32,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
* @param {*} value The value to return. * @param {*} value The value to return.
*/ */
this.resolveTo = function(value) { this.resolveTo = function(value) {
self.plan = function() { this.plan = function() {
return Promise.resolve(value); return Promise.resolve(value);
}; };
return self.getSpy(); return this.getSpy();
}; };
/** /**
@@ -48,10 +46,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
* @param {*} value The value to return. * @param {*} value The value to return.
*/ */
this.rejectWith = function(value) { this.rejectWith = function(value) {
self.plan = function() { this.plan = function() {
return Promise.reject(value); return Promise.reject(value);
}; };
return self.getSpy(); return this.getSpy();
}; };
} }
+8 -10
View File
@@ -74,7 +74,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
}; };
MatchersUtil.prototype.buildFailureMessage = function() { MatchersUtil.prototype.buildFailureMessage = function() {
const self = this;
const args = Array.prototype.slice.call(arguments, 0), const args = Array.prototype.slice.call(arguments, 0),
matcherName = args[0], matcherName = args[0],
isNot = args[1], isNot = args[1],
@@ -86,7 +85,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
let message = let message =
'Expected ' + 'Expected ' +
self.pp(actual) + this.pp(actual) +
(isNot ? ' not ' : ' ') + (isNot ? ' not ' : ' ') +
englishyPredicate; englishyPredicate;
@@ -95,7 +94,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
if (i > 0) { if (i > 0) {
message += ','; message += ',';
} }
message += ' ' + self.pp(expected[i]); message += ' ' + this.pp(expected[i]);
} }
} }
@@ -170,7 +169,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
// [Underscore](http://underscorejs.org) // [Underscore](http://underscorejs.org)
MatchersUtil.prototype.eq_ = function(a, b, aStack, bStack, diffBuilder) { MatchersUtil.prototype.eq_ = function(a, b, aStack, bStack, diffBuilder) {
let result = true; let result = true;
const self = this;
const asymmetricResult = this.asymmetricMatch_( const asymmetricResult = this.asymmetricMatch_(
a, a,
@@ -255,7 +253,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
case '[object ArrayBuffer]': case '[object ArrayBuffer]':
// If we have an instance of ArrayBuffer the Uint8Array ctor // If we have an instance of ArrayBuffer the Uint8Array ctor
// will be defined as well // will be defined as well
return self.eq_( return this.eq_(
new Uint8Array(a), new Uint8Array(a),
new Uint8Array(b), new Uint8Array(b),
aStack, aStack,
@@ -325,15 +323,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
}); });
for (let i = 0; i < aLength || i < bLength; i++) { for (let i = 0; i < aLength || i < bLength; i++) {
diffBuilder.withPath(i, function() { diffBuilder.withPath(i, () => {
if (i >= bLength) { if (i >= bLength) {
diffBuilder.recordMismatch( diffBuilder.recordMismatch(
actualArrayIsLongerFormatter.bind(null, self.pp) actualArrayIsLongerFormatter.bind(null, this.pp)
); );
result = false; result = false;
} else { } else {
result = result =
self.eq_( this.eq_(
i < aLength ? a[i] : void 0, i < aLength ? a[i] : void 0,
i < bLength ? b[i] : void 0, i < bLength ? b[i] : void 0,
aStack, aStack,
@@ -498,8 +496,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
continue; continue;
} }
diffBuilder.withPath(key, function() { diffBuilder.withPath(key, () => {
if (!self.eq_(a[key], b[key], aStack, bStack, diffBuilder)) { if (!this.eq_(a[key], b[key], aStack, bStack, diffBuilder)) {
result = false; result = false;
} }
}); });