Runable, not runnable
This commit is contained in:
@@ -90,7 +90,7 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
|||||||
j$
|
j$
|
||||||
);
|
);
|
||||||
j$.ReportDispatcher = jRequire.ReportDispatcher(j$);
|
j$.ReportDispatcher = jRequire.ReportDispatcher(j$);
|
||||||
j$.RunnableResources = jRequire.RunnableResources(j$);
|
j$.RunableResources = jRequire.RunableResources(j$);
|
||||||
j$.Spec = jRequire.Spec(j$);
|
j$.Spec = jRequire.Spec(j$);
|
||||||
j$.Spy = jRequire.Spy(j$);
|
j$.Spy = jRequire.Spy(j$);
|
||||||
j$.SpyFactory = jRequire.SpyFactory(j$);
|
j$.SpyFactory = jRequire.SpyFactory(j$);
|
||||||
@@ -1113,15 +1113,15 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
new j$.MockDate(global)
|
new j$.MockDate(global)
|
||||||
);
|
);
|
||||||
|
|
||||||
const runnableResources = new j$.RunnableResources(function() {
|
const runableResources = new j$.RunableResources(function() {
|
||||||
const r = currentRunnable();
|
const r = currentRunable();
|
||||||
return r ? r.id : null;
|
return r ? r.id : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
let topSuite;
|
let topSuite;
|
||||||
let currentSpec = null;
|
let currentSpec = null;
|
||||||
const currentlyExecutingSuites = [];
|
const currentlyExecutingSuites = [];
|
||||||
const focusedRunnables = [];
|
const focusedRunables = [];
|
||||||
let currentDeclarationSuite = null;
|
let currentDeclarationSuite = null;
|
||||||
let hasFailures = false;
|
let hasFailures = false;
|
||||||
let deprecator;
|
let deprecator;
|
||||||
@@ -1231,7 +1231,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
|
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function currentRunnable() {
|
function currentRunable() {
|
||||||
return currentSpec || currentSuite();
|
return currentSpec || currentSuite();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1319,27 +1319,27 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.setDefaultSpyStrategy = function(defaultStrategyFn) {
|
this.setDefaultSpyStrategy = function(defaultStrategyFn) {
|
||||||
runnableResources.setDefaultSpyStrategy(defaultStrategyFn);
|
runableResources.setDefaultSpyStrategy(defaultStrategyFn);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addSpyStrategy = function(name, fn) {
|
this.addSpyStrategy = function(name, fn) {
|
||||||
runnableResources.customSpyStrategies()[name] = fn;
|
runableResources.customSpyStrategies()[name] = fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addCustomEqualityTester = function(tester) {
|
this.addCustomEqualityTester = function(tester) {
|
||||||
runnableResources.customEqualityTesters().push(tester);
|
runableResources.customEqualityTesters().push(tester);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addMatchers = function(matchersToAdd) {
|
this.addMatchers = function(matchersToAdd) {
|
||||||
runnableResources.addCustomMatchers(matchersToAdd);
|
runableResources.addCustomMatchers(matchersToAdd);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addAsyncMatchers = function(matchersToAdd) {
|
this.addAsyncMatchers = function(matchersToAdd) {
|
||||||
runnableResources.addCustomAsyncMatchers(matchersToAdd);
|
runableResources.addCustomAsyncMatchers(matchersToAdd);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addCustomObjectFormatter = function(formatter) {
|
this.addCustomObjectFormatter = function(formatter) {
|
||||||
runnableResources.customObjectFormatters().push(formatter);
|
runableResources.customObjectFormatters().push(formatter);
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.Expectation.addCoreMatchers(j$.matchers);
|
j$.Expectation.addCoreMatchers(j$.matchers);
|
||||||
@@ -1359,8 +1359,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
const expectationFactory = function(actual, spec) {
|
const expectationFactory = function(actual, spec) {
|
||||||
return j$.Expectation.factory({
|
return j$.Expectation.factory({
|
||||||
matchersUtil: runnableResources.makeMatchersUtil(),
|
matchersUtil: runableResources.makeMatchersUtil(),
|
||||||
customMatchers: runnableResources.customMatchers(),
|
customMatchers: runableResources.customMatchers(),
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
@@ -1418,7 +1418,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
function routeLateFailure(expectationResult) {
|
function routeLateFailure(expectationResult) {
|
||||||
// Report the result on the nearest ancestor suite that hasn't already
|
// Report the result on the nearest ancestor suite that hasn't already
|
||||||
// been reported done.
|
// been reported done.
|
||||||
for (let r = currentRunnable(); r; r = r.parentSuite) {
|
for (let r = currentRunable(); r; r = r.parentSuite) {
|
||||||
if (!r.reportedDone) {
|
if (!r.reportedDone) {
|
||||||
if (r === topSuite) {
|
if (r === topSuite) {
|
||||||
expectationResult.globalErrorType = 'lateError';
|
expectationResult.globalErrorType = 'lateError';
|
||||||
@@ -1437,14 +1437,14 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
const asyncExpectationFactory = function(actual, spec, runableType) {
|
const asyncExpectationFactory = function(actual, spec, runableType) {
|
||||||
return j$.Expectation.asyncFactory({
|
return j$.Expectation.asyncFactory({
|
||||||
matchersUtil: runnableResources.makeMatchersUtil(),
|
matchersUtil: runableResources.makeMatchersUtil(),
|
||||||
customAsyncMatchers: runnableResources.customAsyncMatchers(),
|
customAsyncMatchers: runableResources.customAsyncMatchers(),
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
|
|
||||||
function addExpectationResult(passed, result) {
|
function addExpectationResult(passed, result) {
|
||||||
if (currentRunnable() !== spec) {
|
if (currentRunable() !== spec) {
|
||||||
recordLateExpectation(spec, runableType, result);
|
recordLateExpectation(spec, runableType, result);
|
||||||
}
|
}
|
||||||
return spec.addExpectationResult(passed, result);
|
return spec.addExpectationResult(passed, result);
|
||||||
@@ -1511,8 +1511,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @param {Object} [options] Optional extra options, as described above
|
* @param {Object} [options] Optional extra options, as described above
|
||||||
*/
|
*/
|
||||||
this.deprecated = function(deprecation, options) {
|
this.deprecated = function(deprecation, options) {
|
||||||
const runnable = currentRunnable() || topSuite;
|
const runable = currentRunable() || topSuite;
|
||||||
deprecator.addDeprecationWarning(runnable, deprecation, options);
|
deprecator.addDeprecationWarning(runable, deprecation, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
function queueRunnerFactory(options, args) {
|
function queueRunnerFactory(options, args) {
|
||||||
@@ -1541,7 +1541,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
options.onException =
|
options.onException =
|
||||||
options.onException ||
|
options.onException ||
|
||||||
function(e) {
|
function(e) {
|
||||||
(currentRunnable() || topSuite).handleException(e);
|
(currentRunable() || topSuite).handleException(e);
|
||||||
};
|
};
|
||||||
options.deprecated = self.deprecated;
|
options.deprecated = self.deprecated;
|
||||||
|
|
||||||
@@ -1674,23 +1674,23 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @name Env#execute
|
* @name Env#execute
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @function
|
* @function
|
||||||
* @param {(string[])=} runnablesToRun IDs of suites and/or specs to run
|
* @param {(string[])=} runablesToRun IDs of suites and/or specs to run
|
||||||
* @param {Function=} onComplete Function that will be called after all specs have run
|
* @param {Function=} onComplete Function that will be called after all specs have run
|
||||||
* @return {Promise<JasmineDoneInfo>}
|
* @return {Promise<JasmineDoneInfo>}
|
||||||
*/
|
*/
|
||||||
this.execute = function(runnablesToRun, onComplete) {
|
this.execute = function(runablesToRun, onComplete) {
|
||||||
if (this._executedBefore) {
|
if (this._executedBefore) {
|
||||||
topSuite.reset();
|
topSuite.reset();
|
||||||
}
|
}
|
||||||
this._executedBefore = true;
|
this._executedBefore = true;
|
||||||
runnableResources.initForRunnable(topSuite.id);
|
runableResources.initForRunable(topSuite.id);
|
||||||
installGlobalErrors();
|
installGlobalErrors();
|
||||||
|
|
||||||
if (!runnablesToRun) {
|
if (!runablesToRun) {
|
||||||
if (focusedRunnables.length) {
|
if (focusedRunables.length) {
|
||||||
runnablesToRun = focusedRunnables;
|
runablesToRun = focusedRunables;
|
||||||
} else {
|
} else {
|
||||||
runnablesToRun = [topSuite.id];
|
runablesToRun = [topSuite.id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1701,12 +1701,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
const processor = new j$.TreeProcessor({
|
const processor = new j$.TreeProcessor({
|
||||||
tree: topSuite,
|
tree: topSuite,
|
||||||
runnableIds: runnablesToRun,
|
runnableIds: runablesToRun,
|
||||||
queueRunnerFactory: queueRunnerFactory,
|
queueRunnerFactory: queueRunnerFactory,
|
||||||
failSpecWithNoExpectations: config.failSpecWithNoExpectations,
|
failSpecWithNoExpectations: config.failSpecWithNoExpectations,
|
||||||
nodeStart: function(suite, next) {
|
nodeStart: function(suite, next) {
|
||||||
currentlyExecutingSuites.push(suite);
|
currentlyExecutingSuites.push(suite);
|
||||||
runnableResources.initForRunnable(suite.id, suite.parentSuite.id);
|
runableResources.initForRunable(suite.id, suite.parentSuite.id);
|
||||||
reporter.suiteStarted(suite.result, next);
|
reporter.suiteStarted(suite.result, next);
|
||||||
suite.startTimer();
|
suite.startTimer();
|
||||||
},
|
},
|
||||||
@@ -1715,7 +1715,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
throw new Error('Tried to complete the wrong suite');
|
throw new Error('Tried to complete the wrong suite');
|
||||||
}
|
}
|
||||||
|
|
||||||
runnableResources.clearForRunnable(suite.id);
|
runableResources.clearForRunable(suite.id);
|
||||||
currentlyExecutingSuites.pop();
|
currentlyExecutingSuites.pop();
|
||||||
|
|
||||||
if (result.status === 'failed') {
|
if (result.status === 'failed') {
|
||||||
@@ -1780,7 +1780,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
await reportChildrenOfBeforeAllFailure(topSuite);
|
await reportChildrenOfBeforeAllFailure(topSuite);
|
||||||
}
|
}
|
||||||
|
|
||||||
runnableResources.clearForRunnable(topSuite.id);
|
runableResources.clearForRunable(topSuite.id);
|
||||||
currentlyExecutingSuites.pop();
|
currentlyExecutingSuites.pop();
|
||||||
let overallStatus, incompleteReason;
|
let overallStatus, incompleteReason;
|
||||||
|
|
||||||
@@ -1789,7 +1789,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
topSuite.result.failedExpectations.length > 0
|
topSuite.result.failedExpectations.length > 0
|
||||||
) {
|
) {
|
||||||
overallStatus = 'failed';
|
overallStatus = 'failed';
|
||||||
} else if (focusedRunnables.length > 0) {
|
} else if (focusedRunables.length > 0) {
|
||||||
overallStatus = 'incomplete';
|
overallStatus = 'incomplete';
|
||||||
incompleteReason = 'fit() or fdescribe() was found';
|
incompleteReason = 'fit() or fdescribe() was found';
|
||||||
} else if (totalSpecsDefined === 0) {
|
} else if (totalSpecsDefined === 0) {
|
||||||
@@ -1914,36 +1914,36 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @param {boolean} allow Whether to allow respying
|
* @param {boolean} allow Whether to allow respying
|
||||||
*/
|
*/
|
||||||
this.allowRespy = function(allow) {
|
this.allowRespy = function(allow) {
|
||||||
runnableResources.spyRegistry.allowRespy(allow);
|
runableResources.spyRegistry.allowRespy(allow);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spyOn = function() {
|
this.spyOn = function() {
|
||||||
return runnableResources.spyRegistry.spyOn.apply(
|
return runableResources.spyRegistry.spyOn.apply(
|
||||||
runnableResources.spyRegistry,
|
runableResources.spyRegistry,
|
||||||
arguments
|
arguments
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spyOnProperty = function() {
|
this.spyOnProperty = function() {
|
||||||
return runnableResources.spyRegistry.spyOnProperty.apply(
|
return runableResources.spyRegistry.spyOnProperty.apply(
|
||||||
runnableResources.spyRegistry,
|
runableResources.spyRegistry,
|
||||||
arguments
|
arguments
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spyOnAllFunctions = function() {
|
this.spyOnAllFunctions = function() {
|
||||||
return runnableResources.spyRegistry.spyOnAllFunctions.apply(
|
return runableResources.spyRegistry.spyOnAllFunctions.apply(
|
||||||
runnableResources.spyRegistry,
|
runableResources.spyRegistry,
|
||||||
arguments
|
arguments
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.createSpy = function(name, originalFn) {
|
this.createSpy = function(name, originalFn) {
|
||||||
return runnableResources.spyFactory.createSpy(name, originalFn);
|
return runableResources.spyFactory.createSpy(name, originalFn);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.createSpyObj = function(baseName, methodNames, propertyNames) {
|
this.createSpyObj = function(baseName, methodNames, propertyNames) {
|
||||||
return runnableResources.spyFactory.createSpyObj(
|
return runableResources.spyFactory.createSpyObj(
|
||||||
baseName,
|
baseName,
|
||||||
methodNames,
|
methodNames,
|
||||||
propertyNames
|
propertyNames
|
||||||
@@ -1967,8 +1967,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ensureIsNotNested(method) {
|
function ensureIsNotNested(method) {
|
||||||
const runnable = currentRunnable();
|
const runable = currentRunable();
|
||||||
if (runnable !== null && runnable !== undefined) {
|
if (runable !== null && runable !== undefined) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"'" + method + "' should only be used in 'describe' function"
|
"'" + method + "' should only be used in 'describe' function"
|
||||||
);
|
);
|
||||||
@@ -2024,7 +2024,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
const suite = suiteFactory(description);
|
const suite = suiteFactory(description);
|
||||||
suite.isFocused = true;
|
suite.isFocused = true;
|
||||||
|
|
||||||
focusedRunnables.push(suite.id);
|
focusedRunables.push(suite.id);
|
||||||
unfocusAncestor();
|
unfocusAncestor();
|
||||||
addSpecsToSuite(suite, specDefinitions);
|
addSpecsToSuite(suite, specDefinitions);
|
||||||
|
|
||||||
@@ -2064,9 +2064,9 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
function unfocusAncestor() {
|
function unfocusAncestor() {
|
||||||
const focusedAncestor = findFocusedAncestor(currentDeclarationSuite);
|
const focusedAncestor = findFocusedAncestor(currentDeclarationSuite);
|
||||||
if (focusedAncestor) {
|
if (focusedAncestor) {
|
||||||
for (let i = 0; i < focusedRunnables.length; i++) {
|
for (let i = 0; i < focusedRunables.length; i++) {
|
||||||
if (focusedRunnables[i] === focusedAncestor) {
|
if (focusedRunables[i] === focusedAncestor) {
|
||||||
focusedRunnables.splice(i, 1);
|
focusedRunables.splice(i, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2102,7 +2102,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return spec;
|
return spec;
|
||||||
|
|
||||||
function specResultCallback(result, next) {
|
function specResultCallback(result, next) {
|
||||||
runnableResources.clearForRunnable(spec.id);
|
runableResources.clearForRunable(spec.id);
|
||||||
currentSpec = null;
|
currentSpec = null;
|
||||||
|
|
||||||
if (result.status === 'failed') {
|
if (result.status === 'failed') {
|
||||||
@@ -2114,7 +2114,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
function specStarted(spec, next) {
|
function specStarted(spec, next) {
|
||||||
currentSpec = spec;
|
currentSpec = spec;
|
||||||
runnableResources.initForRunnable(spec.id, suite.id);
|
runableResources.initForRunable(spec.id, suite.id);
|
||||||
reporter.specStarted(spec.result, next);
|
reporter.specStarted(spec.result, next);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2186,7 +2186,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
timeout
|
timeout
|
||||||
);
|
);
|
||||||
currentDeclarationSuite.addChild(spec);
|
currentDeclarationSuite.addChild(spec);
|
||||||
focusedRunnables.push(spec.id);
|
focusedRunables.push(spec.id);
|
||||||
unfocusAncestor();
|
unfocusAncestor();
|
||||||
return spec.metadata;
|
return spec.metadata;
|
||||||
};
|
};
|
||||||
@@ -2200,12 +2200,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @param {*} value The value of the property
|
* @param {*} value The value of the property
|
||||||
*/
|
*/
|
||||||
this.setSpecProperty = function(key, value) {
|
this.setSpecProperty = function(key, value) {
|
||||||
if (!currentRunnable() || currentRunnable() == currentSuite()) {
|
if (!currentRunable() || currentRunable() == currentSuite()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"'setSpecProperty' was used when there was no current spec"
|
"'setSpecProperty' was used when there was no current spec"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
currentRunnable().setSpecProperty(key, value);
|
currentRunable().setSpecProperty(key, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2226,7 +2226,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.debugLog = function(msg) {
|
this.debugLog = function(msg) {
|
||||||
const maybeSpec = currentRunnable();
|
const maybeSpec = currentRunable();
|
||||||
|
|
||||||
if (!maybeSpec || !maybeSpec.debugLog) {
|
if (!maybeSpec || !maybeSpec.debugLog) {
|
||||||
throw new Error("'debugLog' was called when there was no current spec");
|
throw new Error("'debugLog' was called when there was no current spec");
|
||||||
@@ -2236,23 +2236,23 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.expect = function(actual) {
|
this.expect = function(actual) {
|
||||||
if (!currentRunnable()) {
|
if (!currentRunable()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"'expect' was used when there was no current spec, this could be because an asynchronous test timed out"
|
"'expect' was used when there was no current spec, this could be because an asynchronous test timed out"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentRunnable().expect(actual);
|
return currentRunable().expect(actual);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.expectAsync = function(actual) {
|
this.expectAsync = function(actual) {
|
||||||
if (!currentRunnable()) {
|
if (!currentRunable()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"'expectAsync' was used when there was no current spec, this could be because an asynchronous test timed out"
|
"'expectAsync' was used when there was no current spec, this could be because an asynchronous test timed out"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentRunnable().expectAsync(actual);
|
return currentRunable().expectAsync(actual);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.beforeEach = function(beforeEachFunction, timeout) {
|
this.beforeEach = function(beforeEachFunction, timeout) {
|
||||||
@@ -2321,7 +2321,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.fail = function(error) {
|
this.fail = function(error) {
|
||||||
if (!currentRunnable()) {
|
if (!currentRunable()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"'fail' was used when there was no current spec, this could be because an asynchronous test timed out"
|
"'fail' was used when there was no current spec, this could be because an asynchronous test timed out"
|
||||||
);
|
);
|
||||||
@@ -2336,12 +2336,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
message += error;
|
message += error;
|
||||||
} else {
|
} else {
|
||||||
// pretty print all kind of objects. This includes arrays.
|
// pretty print all kind of objects. This includes arrays.
|
||||||
const pp = runnableResources.makePrettyPrinter();
|
const pp = runableResources.makePrettyPrinter();
|
||||||
message += pp(error);
|
message += pp(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentRunnable().addExpectationResult(false, {
|
currentRunable().addExpectationResult(false, {
|
||||||
matcherName: '',
|
matcherName: '',
|
||||||
passed: false,
|
passed: false,
|
||||||
expected: '',
|
expected: '',
|
||||||
@@ -8533,15 +8533,15 @@ getJasmineRequireObj().interface = function(jasmine, env) {
|
|||||||
return jasmineInterface;
|
return jasmineInterface;
|
||||||
};
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().RunnableResources = function(j$) {
|
getJasmineRequireObj().RunableResources = function(j$) {
|
||||||
class RunnableResources {
|
class RunableResources {
|
||||||
constructor(getCurrentRunnableId) {
|
constructor(getCurrentRunableId) {
|
||||||
this.byRunnableId_ = {};
|
this.byRunableId_ = {};
|
||||||
this.getCurrentRunnableId_ = getCurrentRunnableId;
|
this.getCurrentRunableId_ = getCurrentRunableId;
|
||||||
|
|
||||||
this.spyFactory = new j$.SpyFactory(
|
this.spyFactory = new j$.SpyFactory(
|
||||||
() => {
|
() => {
|
||||||
if (this.getCurrentRunnableId_()) {
|
if (this.getCurrentRunableId_()) {
|
||||||
return this.customSpyStrategies();
|
return this.customSpyStrategies();
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
@@ -8558,8 +8558,8 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
initForRunnable(runnableId, parentId) {
|
initForRunable(runableId, parentId) {
|
||||||
const newRes = (this.byRunnableId_[runnableId] = {
|
const newRes = (this.byRunableId_[runableId] = {
|
||||||
customEqualityTesters: [],
|
customEqualityTesters: [],
|
||||||
customMatchers: {},
|
customMatchers: {},
|
||||||
customAsyncMatchers: {},
|
customAsyncMatchers: {},
|
||||||
@@ -8569,7 +8569,7 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
spies: []
|
spies: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const parentRes = this.byRunnableId_[parentId];
|
const parentRes = this.byRunableId_[parentId];
|
||||||
|
|
||||||
if (parentRes) {
|
if (parentRes) {
|
||||||
newRes.defaultSpyStrategy = parentRes.defaultSpyStrategy;
|
newRes.defaultSpyStrategy = parentRes.defaultSpyStrategy;
|
||||||
@@ -8587,46 +8587,45 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearForRunnable(runnableId) {
|
clearForRunable(runableId) {
|
||||||
this.spyRegistry.clearSpies();
|
this.spyRegistry.clearSpies();
|
||||||
delete this.byRunnableId_[runnableId];
|
delete this.byRunableId_[runableId];
|
||||||
}
|
}
|
||||||
|
|
||||||
spies() {
|
spies() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Spies must be created in a before function or a spec'
|
'Spies must be created in a before function or a spec'
|
||||||
).spies;
|
).spies;
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultSpyStrategy() {
|
defaultSpyStrategy() {
|
||||||
if (!this.getCurrentRunnableId_()) {
|
if (!this.getCurrentRunableId_()) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.byRunnableId_[this.getCurrentRunnableId_()]
|
return this.byRunableId_[this.getCurrentRunableId_()].defaultSpyStrategy;
|
||||||
.defaultSpyStrategy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultSpyStrategy(fn) {
|
setDefaultSpyStrategy(fn) {
|
||||||
this.forCurrentRunnable_(
|
this.forCurrentRunable_(
|
||||||
'Default spy strategy must be set in a before function or a spec'
|
'Default spy strategy must be set in a before function or a spec'
|
||||||
).defaultSpyStrategy = fn;
|
).defaultSpyStrategy = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
customSpyStrategies() {
|
customSpyStrategies() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Custom spy strategies must be added in a before function or a spec'
|
'Custom spy strategies must be added in a before function or a spec'
|
||||||
).customSpyStrategies;
|
).customSpyStrategies;
|
||||||
}
|
}
|
||||||
|
|
||||||
customEqualityTesters() {
|
customEqualityTesters() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Custom Equalities must be added in a before function or a spec'
|
'Custom Equalities must be added in a before function or a spec'
|
||||||
).customEqualityTesters;
|
).customEqualityTesters;
|
||||||
}
|
}
|
||||||
|
|
||||||
customMatchers() {
|
customMatchers() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Matchers must be added in a before function or a spec'
|
'Matchers must be added in a before function or a spec'
|
||||||
).customMatchers;
|
).customMatchers;
|
||||||
}
|
}
|
||||||
@@ -8640,7 +8639,7 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
customAsyncMatchers() {
|
customAsyncMatchers() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Async Matchers must be added in a before function or a spec'
|
'Async Matchers must be added in a before function or a spec'
|
||||||
).customAsyncMatchers;
|
).customAsyncMatchers;
|
||||||
}
|
}
|
||||||
@@ -8654,7 +8653,7 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
customObjectFormatters() {
|
customObjectFormatters() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Custom object formatters must be added in a before function or a spec'
|
'Custom object formatters must be added in a before function or a spec'
|
||||||
).customObjectFormatters;
|
).customObjectFormatters;
|
||||||
}
|
}
|
||||||
@@ -8664,7 +8663,7 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
makeMatchersUtil() {
|
makeMatchersUtil() {
|
||||||
if (this.getCurrentRunnableId_()) {
|
if (this.getCurrentRunableId_()) {
|
||||||
return new j$.MatchersUtil({
|
return new j$.MatchersUtil({
|
||||||
customTesters: this.customEqualityTesters(),
|
customTesters: this.customEqualityTesters(),
|
||||||
pp: this.makePrettyPrinter()
|
pp: this.makePrettyPrinter()
|
||||||
@@ -8674,8 +8673,8 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forCurrentRunnable_(errorMsg) {
|
forCurrentRunable_(errorMsg) {
|
||||||
const resources = this.byRunnableId_[this.getCurrentRunnableId_()];
|
const resources = this.byRunableId_[this.getCurrentRunableId_()];
|
||||||
|
|
||||||
if (!resources && errorMsg) {
|
if (!resources && errorMsg) {
|
||||||
throw new Error(errorMsg);
|
throw new Error(errorMsg);
|
||||||
@@ -8685,7 +8684,7 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return RunnableResources;
|
return RunableResources;
|
||||||
};
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().SkipAfterBeforeAllErrorPolicy = function(j$) {
|
getJasmineRequireObj().SkipAfterBeforeAllErrorPolicy = function(j$) {
|
||||||
|
|||||||
496
spec/core/RunableResourcesSpec.js
Normal file
496
spec/core/RunableResourcesSpec.js
Normal file
@@ -0,0 +1,496 @@
|
|||||||
|
describe('RunableResources', function() {
|
||||||
|
describe('#spies', function() {
|
||||||
|
behavesLikeAPerRunableMutableArray(
|
||||||
|
'spies',
|
||||||
|
'Spies must be created in a before function or a spec',
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customSpyStrategies', function() {
|
||||||
|
behavesLikeAPerRunableMutableObject(
|
||||||
|
'customSpyStrategies',
|
||||||
|
'Custom spy strategies must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customEqualityTesters', function() {
|
||||||
|
behavesLikeAPerRunableMutableArray(
|
||||||
|
'customEqualityTesters',
|
||||||
|
'Custom Equalities must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customObjectFormatters', function() {
|
||||||
|
behavesLikeAPerRunableMutableArray(
|
||||||
|
'customObjectFormatters',
|
||||||
|
'Custom object formatters must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customMatchers', function() {
|
||||||
|
behavesLikeAPerRunableMutableObject(
|
||||||
|
'customMatchers',
|
||||||
|
'Matchers must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#addCustomMatchers', function() {
|
||||||
|
it("adds all properties to the current runable's matchers", function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
function toBeFoo() {}
|
||||||
|
function toBeBar() {}
|
||||||
|
function toBeBaz() {}
|
||||||
|
|
||||||
|
runableResources.addCustomMatchers({ toBeFoo });
|
||||||
|
expect(runableResources.customMatchers()).toEqual({ toBeFoo });
|
||||||
|
|
||||||
|
runableResources.addCustomMatchers({ toBeBar, toBeBaz });
|
||||||
|
expect(runableResources.customMatchers()).toEqual({
|
||||||
|
toBeFoo,
|
||||||
|
toBeBar,
|
||||||
|
toBeBaz
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#customAsyncMatchers', function() {
|
||||||
|
behavesLikeAPerRunableMutableObject(
|
||||||
|
'customAsyncMatchers',
|
||||||
|
'Async Matchers must be added in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#addCustomAsyncMatchers', function() {
|
||||||
|
it("adds all properties to the current runable's matchers", function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
function toBeFoo() {}
|
||||||
|
function toBeBar() {}
|
||||||
|
function toBeBaz() {}
|
||||||
|
|
||||||
|
runableResources.addCustomAsyncMatchers({ toBeFoo });
|
||||||
|
expect(runableResources.customAsyncMatchers()).toEqual({ toBeFoo });
|
||||||
|
|
||||||
|
runableResources.addCustomAsyncMatchers({ toBeBar, toBeBaz });
|
||||||
|
expect(runableResources.customAsyncMatchers()).toEqual({
|
||||||
|
toBeFoo,
|
||||||
|
toBeBar,
|
||||||
|
toBeBaz
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#defaultSpyStrategy', function() {
|
||||||
|
it('returns undefined for a newly initialized resource', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the value previously set by #setDefaultSpyStrategy', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
const fn = () => {};
|
||||||
|
runableResources.setDefaultSpyStrategy(fn);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBe(fn);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is per-runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
runableResources.setDefaultSpyStrategy(() => {});
|
||||||
|
currentRunableId = 2;
|
||||||
|
runableResources.initForRunable(2);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not require a current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => null
|
||||||
|
);
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("inherits the parent runable's value", function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
const fn = () => {};
|
||||||
|
runableResources.setDefaultSpyStrategy(fn);
|
||||||
|
currentRunableId = 2;
|
||||||
|
runableResources.initForRunable(2, 1);
|
||||||
|
|
||||||
|
expect(runableResources.defaultSpyStrategy()).toBe(fn);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#setDefaultSpyStrategy', function() {
|
||||||
|
it('throws a user-facing error when there is no current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => null
|
||||||
|
);
|
||||||
|
expect(function() {
|
||||||
|
runableResources.setDefaultSpyStrategy();
|
||||||
|
}).toThrowError(
|
||||||
|
'Default spy strategy must be set in a before function or a spec'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#makePrettyPrinter', function() {
|
||||||
|
it('returns a pretty printer configured with the current customObjectFormatters', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(() => 1);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function cof() {}
|
||||||
|
runableResources.customObjectFormatters().push(cof);
|
||||||
|
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.callThrough();
|
||||||
|
const pp = runableResources.makePrettyPrinter();
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledOnceWith([
|
||||||
|
cof
|
||||||
|
]);
|
||||||
|
expect(pp).toBe(
|
||||||
|
jasmineUnderTest.makePrettyPrinter.calls.first().returnValue
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#makeMatchersUtil', function() {
|
||||||
|
describe('When there is a current runable', function() {
|
||||||
|
it('returns a MatchersUtil configured with the current resources', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(() => 1);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function cof() {}
|
||||||
|
runableResources.customObjectFormatters().push(cof);
|
||||||
|
function ceq() {}
|
||||||
|
runableResources.customEqualityTesters().push(ceq);
|
||||||
|
const expectedPP = {};
|
||||||
|
const expectedMatchersUtil = {};
|
||||||
|
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(
|
||||||
|
expectedPP
|
||||||
|
);
|
||||||
|
spyOn(jasmineUnderTest, 'MatchersUtil').and.returnValue(
|
||||||
|
expectedMatchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
const matchersUtil = runableResources.makeMatchersUtil();
|
||||||
|
|
||||||
|
expect(matchersUtil).toBe(expectedMatchersUtil);
|
||||||
|
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledOnceWith([
|
||||||
|
cof
|
||||||
|
]);
|
||||||
|
// We need === equality on the pp passed to MatchersUtil
|
||||||
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledOnceWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
customTesters: [ceq]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].pp).toBe(
|
||||||
|
expectedPP
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When there is no current runable', function() {
|
||||||
|
it('returns a MatchersUtil configured with defaults', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => null
|
||||||
|
);
|
||||||
|
const expectedMatchersUtil = {};
|
||||||
|
spyOn(jasmineUnderTest, 'MatchersUtil').and.returnValue(
|
||||||
|
expectedMatchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
const matchersUtil = runableResources.makeMatchersUtil();
|
||||||
|
|
||||||
|
expect(matchersUtil).toBe(expectedMatchersUtil);
|
||||||
|
// We need === equality on the pp passed to MatchersUtil
|
||||||
|
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledTimes(1);
|
||||||
|
expect(jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].pp).toBe(
|
||||||
|
jasmineUnderTest.basicPrettyPrinter_
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].customTesters
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('.spyFactory', function() {
|
||||||
|
describe('When there is no current runable', function() {
|
||||||
|
it('is configured with default strategies and matchersUtil', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => null
|
||||||
|
);
|
||||||
|
spyOn(jasmineUnderTest, 'Spy');
|
||||||
|
const matchersUtil = {};
|
||||||
|
spyOn(runableResources, 'makeMatchersUtil').and.returnValue(
|
||||||
|
matchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
runableResources.spyFactory.createSpy('foo');
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.Spy).toHaveBeenCalledWith(
|
||||||
|
'foo',
|
||||||
|
is(matchersUtil),
|
||||||
|
jasmine.objectContaining({
|
||||||
|
customStrategies: {},
|
||||||
|
defaultStrategyFn: undefined
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When there is a current runable', function() {
|
||||||
|
it("is configured with the current runable's strategies and matchersUtil", function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(() => 1);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function customStrategy() {}
|
||||||
|
function defaultStrategy() {}
|
||||||
|
runableResources.customSpyStrategies().foo = customStrategy;
|
||||||
|
runableResources.setDefaultSpyStrategy(defaultStrategy);
|
||||||
|
spyOn(jasmineUnderTest, 'Spy');
|
||||||
|
const matchersUtil = {};
|
||||||
|
spyOn(runableResources, 'makeMatchersUtil').and.returnValue(
|
||||||
|
matchersUtil
|
||||||
|
);
|
||||||
|
|
||||||
|
runableResources.spyFactory.createSpy('foo');
|
||||||
|
|
||||||
|
expect(jasmineUnderTest.Spy).toHaveBeenCalledWith(
|
||||||
|
'foo',
|
||||||
|
is(matchersUtil),
|
||||||
|
jasmine.objectContaining({
|
||||||
|
customStrategies: { foo: customStrategy },
|
||||||
|
defaultStrategyFn: defaultStrategy
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function is(expected) {
|
||||||
|
return {
|
||||||
|
asymmetricMatch: function(actual) {
|
||||||
|
return actual === expected;
|
||||||
|
},
|
||||||
|
jasmineToString: function(pp) {
|
||||||
|
return '<same instance as ' + pp(expected) + '>';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('.spyRegistry', function() {
|
||||||
|
it("writes to the current runable's spies", function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(() => 1);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function foo() {}
|
||||||
|
const spyObj = { foo };
|
||||||
|
runableResources.spyRegistry.spyOn(spyObj, 'foo');
|
||||||
|
|
||||||
|
expect(runableResources.spies()).toEqual([
|
||||||
|
jasmine.objectContaining({
|
||||||
|
restoreObjectToOriginalState: jasmine.any(Function)
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
expect(jasmineUnderTest.isSpy(spyObj.foo)).toBeTrue();
|
||||||
|
|
||||||
|
runableResources.spyRegistry.clearSpies();
|
||||||
|
expect(spyObj.foo).toBe(foo);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#clearForRunable', function() {
|
||||||
|
it('removes resources for the specified runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(() => 1);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
expect(function() {
|
||||||
|
runableResources.spies();
|
||||||
|
}).not.toThrow();
|
||||||
|
runableResources.clearForRunable(1);
|
||||||
|
expect(function() {
|
||||||
|
runableResources.spies();
|
||||||
|
}).toThrowError('Spies must be created in a before function or a spec');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears spies', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(() => 1);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function foo() {}
|
||||||
|
const spyObj = { foo };
|
||||||
|
runableResources.spyRegistry.spyOn(spyObj, 'foo');
|
||||||
|
expect(spyObj.foo).not.toBe(foo);
|
||||||
|
|
||||||
|
runableResources.clearForRunable(1);
|
||||||
|
expect(spyObj.foo).toBe(foo);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not remove resources for other runables', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(() => 1);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function cof() {}
|
||||||
|
runableResources.customObjectFormatters().push(cof);
|
||||||
|
runableResources.clearForRunable(2);
|
||||||
|
expect(runableResources.customObjectFormatters()).toEqual([cof]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function behavesLikeAPerRunableMutableArray(
|
||||||
|
methodName,
|
||||||
|
errorMsg,
|
||||||
|
inherits = true
|
||||||
|
) {
|
||||||
|
it('is initially empty', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
expect(runableResources[methodName]()).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is mutable', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function newItem() {}
|
||||||
|
runableResources[methodName]().push(newItem);
|
||||||
|
expect(runableResources[methodName]()).toEqual([newItem]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is per-runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
runableResources[methodName]().push(() => {});
|
||||||
|
runableResources.initForRunable(2);
|
||||||
|
currentRunableId = 2;
|
||||||
|
expect(runableResources[methodName]()).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws a user-facing error when there is no current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => null
|
||||||
|
);
|
||||||
|
expect(function() {
|
||||||
|
runableResources[methodName]();
|
||||||
|
}).toThrowError(errorMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (inherits) {
|
||||||
|
it('inherits from the parent runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function parentItem() {}
|
||||||
|
runableResources[methodName]().push(parentItem);
|
||||||
|
runableResources.initForRunable(2, 1);
|
||||||
|
currentRunableId = 2;
|
||||||
|
function childItem() {}
|
||||||
|
runableResources[methodName]().push(childItem);
|
||||||
|
expect(runableResources[methodName]()).toEqual([parentItem, childItem]);
|
||||||
|
|
||||||
|
currentRunableId = 1;
|
||||||
|
expect(runableResources[methodName]()).toEqual([parentItem]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function behavesLikeAPerRunableMutableObject(methodName, errorMsg) {
|
||||||
|
it('is initially empty', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
|
||||||
|
expect(runableResources[methodName]()).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is mutable', function() {
|
||||||
|
const currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function newItem() {}
|
||||||
|
runableResources[methodName]().foo = newItem;
|
||||||
|
expect(runableResources[methodName]()).toEqual({ foo: newItem });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is per-runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
runableResources[methodName]().foo = function() {};
|
||||||
|
runableResources.initForRunable(2);
|
||||||
|
currentRunableId = 2;
|
||||||
|
expect(runableResources[methodName]()).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws a user-facing error when there is no current runable', function() {
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => null
|
||||||
|
);
|
||||||
|
expect(function() {
|
||||||
|
runableResources[methodName]();
|
||||||
|
}).toThrowError(errorMsg);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('inherits from the parent runable', function() {
|
||||||
|
let currentRunableId = 1;
|
||||||
|
const runableResources = new jasmineUnderTest.RunableResources(
|
||||||
|
() => currentRunableId
|
||||||
|
);
|
||||||
|
runableResources.initForRunable(1);
|
||||||
|
function parentItem() {}
|
||||||
|
runableResources[methodName]().parentName = parentItem;
|
||||||
|
runableResources.initForRunable(2, 1);
|
||||||
|
currentRunableId = 2;
|
||||||
|
function childItem() {}
|
||||||
|
runableResources[methodName]().childName = childItem;
|
||||||
|
expect(runableResources[methodName]()).toEqual({
|
||||||
|
parentName: parentItem,
|
||||||
|
childName: childItem
|
||||||
|
});
|
||||||
|
|
||||||
|
currentRunableId = 1;
|
||||||
|
expect(runableResources[methodName]()).toEqual({
|
||||||
|
parentName: parentItem
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,503 +0,0 @@
|
|||||||
describe('RunnableResources', function() {
|
|
||||||
describe('#spies', function() {
|
|
||||||
behavesLikeAPerRunnableMutableArray(
|
|
||||||
'spies',
|
|
||||||
'Spies must be created in a before function or a spec',
|
|
||||||
false
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#customSpyStrategies', function() {
|
|
||||||
behavesLikeAPerRunnableMutableObject(
|
|
||||||
'customSpyStrategies',
|
|
||||||
'Custom spy strategies must be added in a before function or a spec'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#customEqualityTesters', function() {
|
|
||||||
behavesLikeAPerRunnableMutableArray(
|
|
||||||
'customEqualityTesters',
|
|
||||||
'Custom Equalities must be added in a before function or a spec'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#customObjectFormatters', function() {
|
|
||||||
behavesLikeAPerRunnableMutableArray(
|
|
||||||
'customObjectFormatters',
|
|
||||||
'Custom object formatters must be added in a before function or a spec'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#customMatchers', function() {
|
|
||||||
behavesLikeAPerRunnableMutableObject(
|
|
||||||
'customMatchers',
|
|
||||||
'Matchers must be added in a before function or a spec'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#addCustomMatchers', function() {
|
|
||||||
it("adds all properties to the current runnable's matchers", function() {
|
|
||||||
const currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
|
|
||||||
function toBeFoo() {}
|
|
||||||
function toBeBar() {}
|
|
||||||
function toBeBaz() {}
|
|
||||||
|
|
||||||
runnableResources.addCustomMatchers({ toBeFoo });
|
|
||||||
expect(runnableResources.customMatchers()).toEqual({ toBeFoo });
|
|
||||||
|
|
||||||
runnableResources.addCustomMatchers({ toBeBar, toBeBaz });
|
|
||||||
expect(runnableResources.customMatchers()).toEqual({
|
|
||||||
toBeFoo,
|
|
||||||
toBeBar,
|
|
||||||
toBeBaz
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#customAsyncMatchers', function() {
|
|
||||||
behavesLikeAPerRunnableMutableObject(
|
|
||||||
'customAsyncMatchers',
|
|
||||||
'Async Matchers must be added in a before function or a spec'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#addCustomAsyncMatchers', function() {
|
|
||||||
it("adds all properties to the current runnable's matchers", function() {
|
|
||||||
const currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
|
|
||||||
function toBeFoo() {}
|
|
||||||
function toBeBar() {}
|
|
||||||
function toBeBaz() {}
|
|
||||||
|
|
||||||
runnableResources.addCustomAsyncMatchers({ toBeFoo });
|
|
||||||
expect(runnableResources.customAsyncMatchers()).toEqual({ toBeFoo });
|
|
||||||
|
|
||||||
runnableResources.addCustomAsyncMatchers({ toBeBar, toBeBaz });
|
|
||||||
expect(runnableResources.customAsyncMatchers()).toEqual({
|
|
||||||
toBeFoo,
|
|
||||||
toBeBar,
|
|
||||||
toBeBaz
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#defaultSpyStrategy', function() {
|
|
||||||
it('returns undefined for a newly initialized resource', function() {
|
|
||||||
let currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
|
|
||||||
expect(runnableResources.defaultSpyStrategy()).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns the value previously set by #setDefaultSpyStrategy', function() {
|
|
||||||
let currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
const fn = () => {};
|
|
||||||
runnableResources.setDefaultSpyStrategy(fn);
|
|
||||||
|
|
||||||
expect(runnableResources.defaultSpyStrategy()).toBe(fn);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is per-runnable', function() {
|
|
||||||
let currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
runnableResources.setDefaultSpyStrategy(() => {});
|
|
||||||
currentRunnableId = 2;
|
|
||||||
runnableResources.initForRunnable(2);
|
|
||||||
|
|
||||||
expect(runnableResources.defaultSpyStrategy()).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not require a current runnable', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => null
|
|
||||||
);
|
|
||||||
expect(runnableResources.defaultSpyStrategy()).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("inherits the parent runnable's value", function() {
|
|
||||||
let currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
const fn = () => {};
|
|
||||||
runnableResources.setDefaultSpyStrategy(fn);
|
|
||||||
currentRunnableId = 2;
|
|
||||||
runnableResources.initForRunnable(2, 1);
|
|
||||||
|
|
||||||
expect(runnableResources.defaultSpyStrategy()).toBe(fn);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#setDefaultSpyStrategy', function() {
|
|
||||||
it('throws a user-facing error when there is no current runnable', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => null
|
|
||||||
);
|
|
||||||
expect(function() {
|
|
||||||
runnableResources.setDefaultSpyStrategy();
|
|
||||||
}).toThrowError(
|
|
||||||
'Default spy strategy must be set in a before function or a spec'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#makePrettyPrinter', function() {
|
|
||||||
it('returns a pretty printer configured with the current customObjectFormatters', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(() => 1);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
function cof() {}
|
|
||||||
runnableResources.customObjectFormatters().push(cof);
|
|
||||||
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.callThrough();
|
|
||||||
const pp = runnableResources.makePrettyPrinter();
|
|
||||||
|
|
||||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledOnceWith([
|
|
||||||
cof
|
|
||||||
]);
|
|
||||||
expect(pp).toBe(
|
|
||||||
jasmineUnderTest.makePrettyPrinter.calls.first().returnValue
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#makeMatchersUtil', function() {
|
|
||||||
describe('When there is a current runnable', function() {
|
|
||||||
it('returns a MatchersUtil configured with the current resources', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => 1
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
function cof() {}
|
|
||||||
runnableResources.customObjectFormatters().push(cof);
|
|
||||||
function ceq() {}
|
|
||||||
runnableResources.customEqualityTesters().push(ceq);
|
|
||||||
const expectedPP = {};
|
|
||||||
const expectedMatchersUtil = {};
|
|
||||||
spyOn(jasmineUnderTest, 'makePrettyPrinter').and.returnValue(
|
|
||||||
expectedPP
|
|
||||||
);
|
|
||||||
spyOn(jasmineUnderTest, 'MatchersUtil').and.returnValue(
|
|
||||||
expectedMatchersUtil
|
|
||||||
);
|
|
||||||
|
|
||||||
const matchersUtil = runnableResources.makeMatchersUtil();
|
|
||||||
|
|
||||||
expect(matchersUtil).toBe(expectedMatchersUtil);
|
|
||||||
expect(jasmineUnderTest.makePrettyPrinter).toHaveBeenCalledOnceWith([
|
|
||||||
cof
|
|
||||||
]);
|
|
||||||
// We need === equality on the pp passed to MatchersUtil
|
|
||||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledOnceWith(
|
|
||||||
jasmine.objectContaining({
|
|
||||||
customTesters: [ceq]
|
|
||||||
})
|
|
||||||
);
|
|
||||||
expect(jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].pp).toBe(
|
|
||||||
expectedPP
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('When there is no current runnable', function() {
|
|
||||||
it('returns a MatchersUtil configured with defaults', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => null
|
|
||||||
);
|
|
||||||
const expectedMatchersUtil = {};
|
|
||||||
spyOn(jasmineUnderTest, 'MatchersUtil').and.returnValue(
|
|
||||||
expectedMatchersUtil
|
|
||||||
);
|
|
||||||
|
|
||||||
const matchersUtil = runnableResources.makeMatchersUtil();
|
|
||||||
|
|
||||||
expect(matchersUtil).toBe(expectedMatchersUtil);
|
|
||||||
// We need === equality on the pp passed to MatchersUtil
|
|
||||||
expect(jasmineUnderTest.MatchersUtil).toHaveBeenCalledTimes(1);
|
|
||||||
expect(jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].pp).toBe(
|
|
||||||
jasmineUnderTest.basicPrettyPrinter_
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
jasmineUnderTest.MatchersUtil.calls.argsFor(0)[0].customTesters
|
|
||||||
).toBeUndefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.spyFactory', function() {
|
|
||||||
describe('When there is no current runnable', function() {
|
|
||||||
it('is configured with default strategies and matchersUtil', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => null
|
|
||||||
);
|
|
||||||
spyOn(jasmineUnderTest, 'Spy');
|
|
||||||
const matchersUtil = {};
|
|
||||||
spyOn(runnableResources, 'makeMatchersUtil').and.returnValue(
|
|
||||||
matchersUtil
|
|
||||||
);
|
|
||||||
|
|
||||||
runnableResources.spyFactory.createSpy('foo');
|
|
||||||
|
|
||||||
expect(jasmineUnderTest.Spy).toHaveBeenCalledWith(
|
|
||||||
'foo',
|
|
||||||
is(matchersUtil),
|
|
||||||
jasmine.objectContaining({
|
|
||||||
customStrategies: {},
|
|
||||||
defaultStrategyFn: undefined
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('When there is a current runnable', function() {
|
|
||||||
it("is configured with the current runnable's strategies and matchersUtil", function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => 1
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
function customStrategy() {}
|
|
||||||
function defaultStrategy() {}
|
|
||||||
runnableResources.customSpyStrategies().foo = customStrategy;
|
|
||||||
runnableResources.setDefaultSpyStrategy(defaultStrategy);
|
|
||||||
spyOn(jasmineUnderTest, 'Spy');
|
|
||||||
const matchersUtil = {};
|
|
||||||
spyOn(runnableResources, 'makeMatchersUtil').and.returnValue(
|
|
||||||
matchersUtil
|
|
||||||
);
|
|
||||||
|
|
||||||
runnableResources.spyFactory.createSpy('foo');
|
|
||||||
|
|
||||||
expect(jasmineUnderTest.Spy).toHaveBeenCalledWith(
|
|
||||||
'foo',
|
|
||||||
is(matchersUtil),
|
|
||||||
jasmine.objectContaining({
|
|
||||||
customStrategies: { foo: customStrategy },
|
|
||||||
defaultStrategyFn: defaultStrategy
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function is(expected) {
|
|
||||||
return {
|
|
||||||
asymmetricMatch: function(actual) {
|
|
||||||
return actual === expected;
|
|
||||||
},
|
|
||||||
jasmineToString: function(pp) {
|
|
||||||
return '<same instance as ' + pp(expected) + '>';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('.spyRegistry', function() {
|
|
||||||
it("writes to the current runnable's spies", function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(() => 1);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
function foo() {}
|
|
||||||
const spyObj = { foo };
|
|
||||||
runnableResources.spyRegistry.spyOn(spyObj, 'foo');
|
|
||||||
|
|
||||||
expect(runnableResources.spies()).toEqual([
|
|
||||||
jasmine.objectContaining({
|
|
||||||
restoreObjectToOriginalState: jasmine.any(Function)
|
|
||||||
})
|
|
||||||
]);
|
|
||||||
expect(jasmineUnderTest.isSpy(spyObj.foo)).toBeTrue();
|
|
||||||
|
|
||||||
runnableResources.spyRegistry.clearSpies();
|
|
||||||
expect(spyObj.foo).toBe(foo);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#clearForRunnable', function() {
|
|
||||||
it('removes resources for the specified runnable', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(() => 1);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
expect(function() {
|
|
||||||
runnableResources.spies();
|
|
||||||
}).not.toThrow();
|
|
||||||
runnableResources.clearForRunnable(1);
|
|
||||||
expect(function() {
|
|
||||||
runnableResources.spies();
|
|
||||||
}).toThrowError('Spies must be created in a before function or a spec');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('clears spies', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(() => 1);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
function foo() {}
|
|
||||||
const spyObj = { foo };
|
|
||||||
runnableResources.spyRegistry.spyOn(spyObj, 'foo');
|
|
||||||
expect(spyObj.foo).not.toBe(foo);
|
|
||||||
|
|
||||||
runnableResources.clearForRunnable(1);
|
|
||||||
expect(spyObj.foo).toBe(foo);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not remove resources for other runnables', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(() => 1);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
function cof() {}
|
|
||||||
runnableResources.customObjectFormatters().push(cof);
|
|
||||||
runnableResources.clearForRunnable(2);
|
|
||||||
expect(runnableResources.customObjectFormatters()).toEqual([cof]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function behavesLikeAPerRunnableMutableArray(
|
|
||||||
methodName,
|
|
||||||
errorMsg,
|
|
||||||
inherits = true
|
|
||||||
) {
|
|
||||||
it('is initially empty', function() {
|
|
||||||
const currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
|
|
||||||
expect(runnableResources[methodName]()).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is mutable', function() {
|
|
||||||
const currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
function newItem() {}
|
|
||||||
runnableResources[methodName]().push(newItem);
|
|
||||||
expect(runnableResources[methodName]()).toEqual([newItem]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is per-runnable', function() {
|
|
||||||
let currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
runnableResources[methodName]().push(() => {});
|
|
||||||
runnableResources.initForRunnable(2);
|
|
||||||
currentRunnableId = 2;
|
|
||||||
expect(runnableResources[methodName]()).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('throws a user-facing error when there is no current runnable', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => null
|
|
||||||
);
|
|
||||||
expect(function() {
|
|
||||||
runnableResources[methodName]();
|
|
||||||
}).toThrowError(errorMsg);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (inherits) {
|
|
||||||
it('inherits from the parent runnable', function() {
|
|
||||||
let currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
function parentItem() {}
|
|
||||||
runnableResources[methodName]().push(parentItem);
|
|
||||||
runnableResources.initForRunnable(2, 1);
|
|
||||||
currentRunnableId = 2;
|
|
||||||
function childItem() {}
|
|
||||||
runnableResources[methodName]().push(childItem);
|
|
||||||
expect(runnableResources[methodName]()).toEqual([
|
|
||||||
parentItem,
|
|
||||||
childItem
|
|
||||||
]);
|
|
||||||
|
|
||||||
currentRunnableId = 1;
|
|
||||||
expect(runnableResources[methodName]()).toEqual([parentItem]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function behavesLikeAPerRunnableMutableObject(methodName, errorMsg) {
|
|
||||||
it('is initially empty', function() {
|
|
||||||
const currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
|
|
||||||
expect(runnableResources[methodName]()).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is mutable', function() {
|
|
||||||
const currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
function newItem() {}
|
|
||||||
runnableResources[methodName]().foo = newItem;
|
|
||||||
expect(runnableResources[methodName]()).toEqual({ foo: newItem });
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is per-runnable', function() {
|
|
||||||
let currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
runnableResources[methodName]().foo = function() {};
|
|
||||||
runnableResources.initForRunnable(2);
|
|
||||||
currentRunnableId = 2;
|
|
||||||
expect(runnableResources[methodName]()).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('throws a user-facing error when there is no current runnable', function() {
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => null
|
|
||||||
);
|
|
||||||
expect(function() {
|
|
||||||
runnableResources[methodName]();
|
|
||||||
}).toThrowError(errorMsg);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inherits from the parent runnable', function() {
|
|
||||||
let currentRunnableId = 1;
|
|
||||||
const runnableResources = new jasmineUnderTest.RunnableResources(
|
|
||||||
() => currentRunnableId
|
|
||||||
);
|
|
||||||
runnableResources.initForRunnable(1);
|
|
||||||
function parentItem() {}
|
|
||||||
runnableResources[methodName]().parentName = parentItem;
|
|
||||||
runnableResources.initForRunnable(2, 1);
|
|
||||||
currentRunnableId = 2;
|
|
||||||
function childItem() {}
|
|
||||||
runnableResources[methodName]().childName = childItem;
|
|
||||||
expect(runnableResources[methodName]()).toEqual({
|
|
||||||
parentName: parentItem,
|
|
||||||
childName: childItem
|
|
||||||
});
|
|
||||||
|
|
||||||
currentRunnableId = 1;
|
|
||||||
expect(runnableResources[methodName]()).toEqual({
|
|
||||||
parentName: parentItem
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
118
src/core/Env.js
118
src/core/Env.js
@@ -26,15 +26,15 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
new j$.MockDate(global)
|
new j$.MockDate(global)
|
||||||
);
|
);
|
||||||
|
|
||||||
const runnableResources = new j$.RunnableResources(function() {
|
const runableResources = new j$.RunableResources(function() {
|
||||||
const r = currentRunnable();
|
const r = currentRunable();
|
||||||
return r ? r.id : null;
|
return r ? r.id : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
let topSuite;
|
let topSuite;
|
||||||
let currentSpec = null;
|
let currentSpec = null;
|
||||||
const currentlyExecutingSuites = [];
|
const currentlyExecutingSuites = [];
|
||||||
const focusedRunnables = [];
|
const focusedRunables = [];
|
||||||
let currentDeclarationSuite = null;
|
let currentDeclarationSuite = null;
|
||||||
let hasFailures = false;
|
let hasFailures = false;
|
||||||
let deprecator;
|
let deprecator;
|
||||||
@@ -144,7 +144,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
|
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function currentRunnable() {
|
function currentRunable() {
|
||||||
return currentSpec || currentSuite();
|
return currentSpec || currentSuite();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,27 +232,27 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.setDefaultSpyStrategy = function(defaultStrategyFn) {
|
this.setDefaultSpyStrategy = function(defaultStrategyFn) {
|
||||||
runnableResources.setDefaultSpyStrategy(defaultStrategyFn);
|
runableResources.setDefaultSpyStrategy(defaultStrategyFn);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addSpyStrategy = function(name, fn) {
|
this.addSpyStrategy = function(name, fn) {
|
||||||
runnableResources.customSpyStrategies()[name] = fn;
|
runableResources.customSpyStrategies()[name] = fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addCustomEqualityTester = function(tester) {
|
this.addCustomEqualityTester = function(tester) {
|
||||||
runnableResources.customEqualityTesters().push(tester);
|
runableResources.customEqualityTesters().push(tester);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addMatchers = function(matchersToAdd) {
|
this.addMatchers = function(matchersToAdd) {
|
||||||
runnableResources.addCustomMatchers(matchersToAdd);
|
runableResources.addCustomMatchers(matchersToAdd);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addAsyncMatchers = function(matchersToAdd) {
|
this.addAsyncMatchers = function(matchersToAdd) {
|
||||||
runnableResources.addCustomAsyncMatchers(matchersToAdd);
|
runableResources.addCustomAsyncMatchers(matchersToAdd);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addCustomObjectFormatter = function(formatter) {
|
this.addCustomObjectFormatter = function(formatter) {
|
||||||
runnableResources.customObjectFormatters().push(formatter);
|
runableResources.customObjectFormatters().push(formatter);
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.Expectation.addCoreMatchers(j$.matchers);
|
j$.Expectation.addCoreMatchers(j$.matchers);
|
||||||
@@ -272,8 +272,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
const expectationFactory = function(actual, spec) {
|
const expectationFactory = function(actual, spec) {
|
||||||
return j$.Expectation.factory({
|
return j$.Expectation.factory({
|
||||||
matchersUtil: runnableResources.makeMatchersUtil(),
|
matchersUtil: runableResources.makeMatchersUtil(),
|
||||||
customMatchers: runnableResources.customMatchers(),
|
customMatchers: runableResources.customMatchers(),
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
@@ -331,7 +331,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
function routeLateFailure(expectationResult) {
|
function routeLateFailure(expectationResult) {
|
||||||
// Report the result on the nearest ancestor suite that hasn't already
|
// Report the result on the nearest ancestor suite that hasn't already
|
||||||
// been reported done.
|
// been reported done.
|
||||||
for (let r = currentRunnable(); r; r = r.parentSuite) {
|
for (let r = currentRunable(); r; r = r.parentSuite) {
|
||||||
if (!r.reportedDone) {
|
if (!r.reportedDone) {
|
||||||
if (r === topSuite) {
|
if (r === topSuite) {
|
||||||
expectationResult.globalErrorType = 'lateError';
|
expectationResult.globalErrorType = 'lateError';
|
||||||
@@ -350,14 +350,14 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
const asyncExpectationFactory = function(actual, spec, runableType) {
|
const asyncExpectationFactory = function(actual, spec, runableType) {
|
||||||
return j$.Expectation.asyncFactory({
|
return j$.Expectation.asyncFactory({
|
||||||
matchersUtil: runnableResources.makeMatchersUtil(),
|
matchersUtil: runableResources.makeMatchersUtil(),
|
||||||
customAsyncMatchers: runnableResources.customAsyncMatchers(),
|
customAsyncMatchers: runableResources.customAsyncMatchers(),
|
||||||
actual: actual,
|
actual: actual,
|
||||||
addExpectationResult: addExpectationResult
|
addExpectationResult: addExpectationResult
|
||||||
});
|
});
|
||||||
|
|
||||||
function addExpectationResult(passed, result) {
|
function addExpectationResult(passed, result) {
|
||||||
if (currentRunnable() !== spec) {
|
if (currentRunable() !== spec) {
|
||||||
recordLateExpectation(spec, runableType, result);
|
recordLateExpectation(spec, runableType, result);
|
||||||
}
|
}
|
||||||
return spec.addExpectationResult(passed, result);
|
return spec.addExpectationResult(passed, result);
|
||||||
@@ -424,8 +424,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @param {Object} [options] Optional extra options, as described above
|
* @param {Object} [options] Optional extra options, as described above
|
||||||
*/
|
*/
|
||||||
this.deprecated = function(deprecation, options) {
|
this.deprecated = function(deprecation, options) {
|
||||||
const runnable = currentRunnable() || topSuite;
|
const runable = currentRunable() || topSuite;
|
||||||
deprecator.addDeprecationWarning(runnable, deprecation, options);
|
deprecator.addDeprecationWarning(runable, deprecation, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
function queueRunnerFactory(options, args) {
|
function queueRunnerFactory(options, args) {
|
||||||
@@ -454,7 +454,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
options.onException =
|
options.onException =
|
||||||
options.onException ||
|
options.onException ||
|
||||||
function(e) {
|
function(e) {
|
||||||
(currentRunnable() || topSuite).handleException(e);
|
(currentRunable() || topSuite).handleException(e);
|
||||||
};
|
};
|
||||||
options.deprecated = self.deprecated;
|
options.deprecated = self.deprecated;
|
||||||
|
|
||||||
@@ -587,23 +587,23 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @name Env#execute
|
* @name Env#execute
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @function
|
* @function
|
||||||
* @param {(string[])=} runnablesToRun IDs of suites and/or specs to run
|
* @param {(string[])=} runablesToRun IDs of suites and/or specs to run
|
||||||
* @param {Function=} onComplete Function that will be called after all specs have run
|
* @param {Function=} onComplete Function that will be called after all specs have run
|
||||||
* @return {Promise<JasmineDoneInfo>}
|
* @return {Promise<JasmineDoneInfo>}
|
||||||
*/
|
*/
|
||||||
this.execute = function(runnablesToRun, onComplete) {
|
this.execute = function(runablesToRun, onComplete) {
|
||||||
if (this._executedBefore) {
|
if (this._executedBefore) {
|
||||||
topSuite.reset();
|
topSuite.reset();
|
||||||
}
|
}
|
||||||
this._executedBefore = true;
|
this._executedBefore = true;
|
||||||
runnableResources.initForRunnable(topSuite.id);
|
runableResources.initForRunable(topSuite.id);
|
||||||
installGlobalErrors();
|
installGlobalErrors();
|
||||||
|
|
||||||
if (!runnablesToRun) {
|
if (!runablesToRun) {
|
||||||
if (focusedRunnables.length) {
|
if (focusedRunables.length) {
|
||||||
runnablesToRun = focusedRunnables;
|
runablesToRun = focusedRunables;
|
||||||
} else {
|
} else {
|
||||||
runnablesToRun = [topSuite.id];
|
runablesToRun = [topSuite.id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,12 +614,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
const processor = new j$.TreeProcessor({
|
const processor = new j$.TreeProcessor({
|
||||||
tree: topSuite,
|
tree: topSuite,
|
||||||
runnableIds: runnablesToRun,
|
runnableIds: runablesToRun,
|
||||||
queueRunnerFactory: queueRunnerFactory,
|
queueRunnerFactory: queueRunnerFactory,
|
||||||
failSpecWithNoExpectations: config.failSpecWithNoExpectations,
|
failSpecWithNoExpectations: config.failSpecWithNoExpectations,
|
||||||
nodeStart: function(suite, next) {
|
nodeStart: function(suite, next) {
|
||||||
currentlyExecutingSuites.push(suite);
|
currentlyExecutingSuites.push(suite);
|
||||||
runnableResources.initForRunnable(suite.id, suite.parentSuite.id);
|
runableResources.initForRunable(suite.id, suite.parentSuite.id);
|
||||||
reporter.suiteStarted(suite.result, next);
|
reporter.suiteStarted(suite.result, next);
|
||||||
suite.startTimer();
|
suite.startTimer();
|
||||||
},
|
},
|
||||||
@@ -628,7 +628,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
throw new Error('Tried to complete the wrong suite');
|
throw new Error('Tried to complete the wrong suite');
|
||||||
}
|
}
|
||||||
|
|
||||||
runnableResources.clearForRunnable(suite.id);
|
runableResources.clearForRunable(suite.id);
|
||||||
currentlyExecutingSuites.pop();
|
currentlyExecutingSuites.pop();
|
||||||
|
|
||||||
if (result.status === 'failed') {
|
if (result.status === 'failed') {
|
||||||
@@ -693,7 +693,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
await reportChildrenOfBeforeAllFailure(topSuite);
|
await reportChildrenOfBeforeAllFailure(topSuite);
|
||||||
}
|
}
|
||||||
|
|
||||||
runnableResources.clearForRunnable(topSuite.id);
|
runableResources.clearForRunable(topSuite.id);
|
||||||
currentlyExecutingSuites.pop();
|
currentlyExecutingSuites.pop();
|
||||||
let overallStatus, incompleteReason;
|
let overallStatus, incompleteReason;
|
||||||
|
|
||||||
@@ -702,7 +702,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
topSuite.result.failedExpectations.length > 0
|
topSuite.result.failedExpectations.length > 0
|
||||||
) {
|
) {
|
||||||
overallStatus = 'failed';
|
overallStatus = 'failed';
|
||||||
} else if (focusedRunnables.length > 0) {
|
} else if (focusedRunables.length > 0) {
|
||||||
overallStatus = 'incomplete';
|
overallStatus = 'incomplete';
|
||||||
incompleteReason = 'fit() or fdescribe() was found';
|
incompleteReason = 'fit() or fdescribe() was found';
|
||||||
} else if (totalSpecsDefined === 0) {
|
} else if (totalSpecsDefined === 0) {
|
||||||
@@ -827,36 +827,36 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @param {boolean} allow Whether to allow respying
|
* @param {boolean} allow Whether to allow respying
|
||||||
*/
|
*/
|
||||||
this.allowRespy = function(allow) {
|
this.allowRespy = function(allow) {
|
||||||
runnableResources.spyRegistry.allowRespy(allow);
|
runableResources.spyRegistry.allowRespy(allow);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spyOn = function() {
|
this.spyOn = function() {
|
||||||
return runnableResources.spyRegistry.spyOn.apply(
|
return runableResources.spyRegistry.spyOn.apply(
|
||||||
runnableResources.spyRegistry,
|
runableResources.spyRegistry,
|
||||||
arguments
|
arguments
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spyOnProperty = function() {
|
this.spyOnProperty = function() {
|
||||||
return runnableResources.spyRegistry.spyOnProperty.apply(
|
return runableResources.spyRegistry.spyOnProperty.apply(
|
||||||
runnableResources.spyRegistry,
|
runableResources.spyRegistry,
|
||||||
arguments
|
arguments
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spyOnAllFunctions = function() {
|
this.spyOnAllFunctions = function() {
|
||||||
return runnableResources.spyRegistry.spyOnAllFunctions.apply(
|
return runableResources.spyRegistry.spyOnAllFunctions.apply(
|
||||||
runnableResources.spyRegistry,
|
runableResources.spyRegistry,
|
||||||
arguments
|
arguments
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.createSpy = function(name, originalFn) {
|
this.createSpy = function(name, originalFn) {
|
||||||
return runnableResources.spyFactory.createSpy(name, originalFn);
|
return runableResources.spyFactory.createSpy(name, originalFn);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.createSpyObj = function(baseName, methodNames, propertyNames) {
|
this.createSpyObj = function(baseName, methodNames, propertyNames) {
|
||||||
return runnableResources.spyFactory.createSpyObj(
|
return runableResources.spyFactory.createSpyObj(
|
||||||
baseName,
|
baseName,
|
||||||
methodNames,
|
methodNames,
|
||||||
propertyNames
|
propertyNames
|
||||||
@@ -880,8 +880,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ensureIsNotNested(method) {
|
function ensureIsNotNested(method) {
|
||||||
const runnable = currentRunnable();
|
const runable = currentRunable();
|
||||||
if (runnable !== null && runnable !== undefined) {
|
if (runable !== null && runable !== undefined) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"'" + method + "' should only be used in 'describe' function"
|
"'" + method + "' should only be used in 'describe' function"
|
||||||
);
|
);
|
||||||
@@ -937,7 +937,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
const suite = suiteFactory(description);
|
const suite = suiteFactory(description);
|
||||||
suite.isFocused = true;
|
suite.isFocused = true;
|
||||||
|
|
||||||
focusedRunnables.push(suite.id);
|
focusedRunables.push(suite.id);
|
||||||
unfocusAncestor();
|
unfocusAncestor();
|
||||||
addSpecsToSuite(suite, specDefinitions);
|
addSpecsToSuite(suite, specDefinitions);
|
||||||
|
|
||||||
@@ -977,9 +977,9 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
function unfocusAncestor() {
|
function unfocusAncestor() {
|
||||||
const focusedAncestor = findFocusedAncestor(currentDeclarationSuite);
|
const focusedAncestor = findFocusedAncestor(currentDeclarationSuite);
|
||||||
if (focusedAncestor) {
|
if (focusedAncestor) {
|
||||||
for (let i = 0; i < focusedRunnables.length; i++) {
|
for (let i = 0; i < focusedRunables.length; i++) {
|
||||||
if (focusedRunnables[i] === focusedAncestor) {
|
if (focusedRunables[i] === focusedAncestor) {
|
||||||
focusedRunnables.splice(i, 1);
|
focusedRunables.splice(i, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1015,7 +1015,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return spec;
|
return spec;
|
||||||
|
|
||||||
function specResultCallback(result, next) {
|
function specResultCallback(result, next) {
|
||||||
runnableResources.clearForRunnable(spec.id);
|
runableResources.clearForRunable(spec.id);
|
||||||
currentSpec = null;
|
currentSpec = null;
|
||||||
|
|
||||||
if (result.status === 'failed') {
|
if (result.status === 'failed') {
|
||||||
@@ -1027,7 +1027,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
function specStarted(spec, next) {
|
function specStarted(spec, next) {
|
||||||
currentSpec = spec;
|
currentSpec = spec;
|
||||||
runnableResources.initForRunnable(spec.id, suite.id);
|
runableResources.initForRunable(spec.id, suite.id);
|
||||||
reporter.specStarted(spec.result, next);
|
reporter.specStarted(spec.result, next);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1099,7 +1099,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
timeout
|
timeout
|
||||||
);
|
);
|
||||||
currentDeclarationSuite.addChild(spec);
|
currentDeclarationSuite.addChild(spec);
|
||||||
focusedRunnables.push(spec.id);
|
focusedRunables.push(spec.id);
|
||||||
unfocusAncestor();
|
unfocusAncestor();
|
||||||
return spec.metadata;
|
return spec.metadata;
|
||||||
};
|
};
|
||||||
@@ -1113,12 +1113,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
* @param {*} value The value of the property
|
* @param {*} value The value of the property
|
||||||
*/
|
*/
|
||||||
this.setSpecProperty = function(key, value) {
|
this.setSpecProperty = function(key, value) {
|
||||||
if (!currentRunnable() || currentRunnable() == currentSuite()) {
|
if (!currentRunable() || currentRunable() == currentSuite()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"'setSpecProperty' was used when there was no current spec"
|
"'setSpecProperty' was used when there was no current spec"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
currentRunnable().setSpecProperty(key, value);
|
currentRunable().setSpecProperty(key, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1139,7 +1139,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.debugLog = function(msg) {
|
this.debugLog = function(msg) {
|
||||||
const maybeSpec = currentRunnable();
|
const maybeSpec = currentRunable();
|
||||||
|
|
||||||
if (!maybeSpec || !maybeSpec.debugLog) {
|
if (!maybeSpec || !maybeSpec.debugLog) {
|
||||||
throw new Error("'debugLog' was called when there was no current spec");
|
throw new Error("'debugLog' was called when there was no current spec");
|
||||||
@@ -1149,23 +1149,23 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.expect = function(actual) {
|
this.expect = function(actual) {
|
||||||
if (!currentRunnable()) {
|
if (!currentRunable()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"'expect' was used when there was no current spec, this could be because an asynchronous test timed out"
|
"'expect' was used when there was no current spec, this could be because an asynchronous test timed out"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentRunnable().expect(actual);
|
return currentRunable().expect(actual);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.expectAsync = function(actual) {
|
this.expectAsync = function(actual) {
|
||||||
if (!currentRunnable()) {
|
if (!currentRunable()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"'expectAsync' was used when there was no current spec, this could be because an asynchronous test timed out"
|
"'expectAsync' was used when there was no current spec, this could be because an asynchronous test timed out"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentRunnable().expectAsync(actual);
|
return currentRunable().expectAsync(actual);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.beforeEach = function(beforeEachFunction, timeout) {
|
this.beforeEach = function(beforeEachFunction, timeout) {
|
||||||
@@ -1234,7 +1234,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.fail = function(error) {
|
this.fail = function(error) {
|
||||||
if (!currentRunnable()) {
|
if (!currentRunable()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"'fail' was used when there was no current spec, this could be because an asynchronous test timed out"
|
"'fail' was used when there was no current spec, this could be because an asynchronous test timed out"
|
||||||
);
|
);
|
||||||
@@ -1249,12 +1249,12 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
message += error;
|
message += error;
|
||||||
} else {
|
} else {
|
||||||
// pretty print all kind of objects. This includes arrays.
|
// pretty print all kind of objects. This includes arrays.
|
||||||
const pp = runnableResources.makePrettyPrinter();
|
const pp = runableResources.makePrettyPrinter();
|
||||||
message += pp(error);
|
message += pp(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentRunnable().addExpectationResult(false, {
|
currentRunable().addExpectationResult(false, {
|
||||||
matcherName: '',
|
matcherName: '',
|
||||||
passed: false,
|
passed: false,
|
||||||
expected: '',
|
expected: '',
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
getJasmineRequireObj().RunnableResources = function(j$) {
|
getJasmineRequireObj().RunableResources = function(j$) {
|
||||||
class RunnableResources {
|
class RunableResources {
|
||||||
constructor(getCurrentRunnableId) {
|
constructor(getCurrentRunableId) {
|
||||||
this.byRunnableId_ = {};
|
this.byRunableId_ = {};
|
||||||
this.getCurrentRunnableId_ = getCurrentRunnableId;
|
this.getCurrentRunableId_ = getCurrentRunableId;
|
||||||
|
|
||||||
this.spyFactory = new j$.SpyFactory(
|
this.spyFactory = new j$.SpyFactory(
|
||||||
() => {
|
() => {
|
||||||
if (this.getCurrentRunnableId_()) {
|
if (this.getCurrentRunableId_()) {
|
||||||
return this.customSpyStrategies();
|
return this.customSpyStrategies();
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
@@ -23,8 +23,8 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
initForRunnable(runnableId, parentId) {
|
initForRunable(runableId, parentId) {
|
||||||
const newRes = (this.byRunnableId_[runnableId] = {
|
const newRes = (this.byRunableId_[runableId] = {
|
||||||
customEqualityTesters: [],
|
customEqualityTesters: [],
|
||||||
customMatchers: {},
|
customMatchers: {},
|
||||||
customAsyncMatchers: {},
|
customAsyncMatchers: {},
|
||||||
@@ -34,7 +34,7 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
spies: []
|
spies: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const parentRes = this.byRunnableId_[parentId];
|
const parentRes = this.byRunableId_[parentId];
|
||||||
|
|
||||||
if (parentRes) {
|
if (parentRes) {
|
||||||
newRes.defaultSpyStrategy = parentRes.defaultSpyStrategy;
|
newRes.defaultSpyStrategy = parentRes.defaultSpyStrategy;
|
||||||
@@ -52,46 +52,45 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearForRunnable(runnableId) {
|
clearForRunable(runableId) {
|
||||||
this.spyRegistry.clearSpies();
|
this.spyRegistry.clearSpies();
|
||||||
delete this.byRunnableId_[runnableId];
|
delete this.byRunableId_[runableId];
|
||||||
}
|
}
|
||||||
|
|
||||||
spies() {
|
spies() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Spies must be created in a before function or a spec'
|
'Spies must be created in a before function or a spec'
|
||||||
).spies;
|
).spies;
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultSpyStrategy() {
|
defaultSpyStrategy() {
|
||||||
if (!this.getCurrentRunnableId_()) {
|
if (!this.getCurrentRunableId_()) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.byRunnableId_[this.getCurrentRunnableId_()]
|
return this.byRunableId_[this.getCurrentRunableId_()].defaultSpyStrategy;
|
||||||
.defaultSpyStrategy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultSpyStrategy(fn) {
|
setDefaultSpyStrategy(fn) {
|
||||||
this.forCurrentRunnable_(
|
this.forCurrentRunable_(
|
||||||
'Default spy strategy must be set in a before function or a spec'
|
'Default spy strategy must be set in a before function or a spec'
|
||||||
).defaultSpyStrategy = fn;
|
).defaultSpyStrategy = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
customSpyStrategies() {
|
customSpyStrategies() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Custom spy strategies must be added in a before function or a spec'
|
'Custom spy strategies must be added in a before function or a spec'
|
||||||
).customSpyStrategies;
|
).customSpyStrategies;
|
||||||
}
|
}
|
||||||
|
|
||||||
customEqualityTesters() {
|
customEqualityTesters() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Custom Equalities must be added in a before function or a spec'
|
'Custom Equalities must be added in a before function or a spec'
|
||||||
).customEqualityTesters;
|
).customEqualityTesters;
|
||||||
}
|
}
|
||||||
|
|
||||||
customMatchers() {
|
customMatchers() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Matchers must be added in a before function or a spec'
|
'Matchers must be added in a before function or a spec'
|
||||||
).customMatchers;
|
).customMatchers;
|
||||||
}
|
}
|
||||||
@@ -105,7 +104,7 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
customAsyncMatchers() {
|
customAsyncMatchers() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Async Matchers must be added in a before function or a spec'
|
'Async Matchers must be added in a before function or a spec'
|
||||||
).customAsyncMatchers;
|
).customAsyncMatchers;
|
||||||
}
|
}
|
||||||
@@ -119,7 +118,7 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
customObjectFormatters() {
|
customObjectFormatters() {
|
||||||
return this.forCurrentRunnable_(
|
return this.forCurrentRunable_(
|
||||||
'Custom object formatters must be added in a before function or a spec'
|
'Custom object formatters must be added in a before function or a spec'
|
||||||
).customObjectFormatters;
|
).customObjectFormatters;
|
||||||
}
|
}
|
||||||
@@ -129,7 +128,7 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
makeMatchersUtil() {
|
makeMatchersUtil() {
|
||||||
if (this.getCurrentRunnableId_()) {
|
if (this.getCurrentRunableId_()) {
|
||||||
return new j$.MatchersUtil({
|
return new j$.MatchersUtil({
|
||||||
customTesters: this.customEqualityTesters(),
|
customTesters: this.customEqualityTesters(),
|
||||||
pp: this.makePrettyPrinter()
|
pp: this.makePrettyPrinter()
|
||||||
@@ -139,8 +138,8 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forCurrentRunnable_(errorMsg) {
|
forCurrentRunable_(errorMsg) {
|
||||||
const resources = this.byRunnableId_[this.getCurrentRunnableId_()];
|
const resources = this.byRunableId_[this.getCurrentRunableId_()];
|
||||||
|
|
||||||
if (!resources && errorMsg) {
|
if (!resources && errorMsg) {
|
||||||
throw new Error(errorMsg);
|
throw new Error(errorMsg);
|
||||||
@@ -150,5 +149,5 @@ getJasmineRequireObj().RunnableResources = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return RunnableResources;
|
return RunableResources;
|
||||||
};
|
};
|
||||||
@@ -68,7 +68,7 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
|||||||
j$
|
j$
|
||||||
);
|
);
|
||||||
j$.ReportDispatcher = jRequire.ReportDispatcher(j$);
|
j$.ReportDispatcher = jRequire.ReportDispatcher(j$);
|
||||||
j$.RunnableResources = jRequire.RunnableResources(j$);
|
j$.RunableResources = jRequire.RunableResources(j$);
|
||||||
j$.Spec = jRequire.Spec(j$);
|
j$.Spec = jRequire.Spec(j$);
|
||||||
j$.Spy = jRequire.Spy(j$);
|
j$.Spy = jRequire.Spy(j$);
|
||||||
j$.SpyFactory = jRequire.SpyFactory(j$);
|
j$.SpyFactory = jRequire.SpyFactory(j$);
|
||||||
|
|||||||
Reference in New Issue
Block a user