Convert Spec to an es6 class
This commit is contained in:
@@ -771,7 +771,8 @@ getJasmineRequireObj().util = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().Spec = function(j$) {
|
getJasmineRequireObj().Spec = function(j$) {
|
||||||
function Spec(attrs) {
|
class Spec {
|
||||||
|
constructor(attrs) {
|
||||||
this.expectationFactory = attrs.expectationFactory;
|
this.expectationFactory = attrs.expectationFactory;
|
||||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||||
this.id = attrs.id;
|
this.id = attrs.id;
|
||||||
@@ -790,7 +791,9 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
this.autoCleanClosures =
|
this.autoCleanClosures =
|
||||||
attrs.autoCleanClosures === undefined ? true : !!attrs.autoCleanClosures;
|
attrs.autoCleanClosures === undefined
|
||||||
|
? true
|
||||||
|
: !!attrs.autoCleanClosures;
|
||||||
|
|
||||||
this.getPath = function() {
|
this.getPath = function() {
|
||||||
return attrs.getPath ? attrs.getPath(this) : [];
|
return attrs.getPath ? attrs.getPath(this) : [];
|
||||||
@@ -812,7 +815,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Spec.prototype.addExpectationResult = function(passed, data, isError) {
|
addExpectationResult(passed, data, isError) {
|
||||||
const expectationResult = j$.buildExpectationResult(data);
|
const expectationResult = j$.buildExpectationResult(data);
|
||||||
|
|
||||||
if (passed) {
|
if (passed) {
|
||||||
@@ -833,23 +836,23 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
throw new j$.errors.ExpectationFailed();
|
throw new j$.errors.ExpectationFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.getSpecProperty = function(key) {
|
getSpecProperty(key) {
|
||||||
this.result.properties = this.result.properties || {};
|
this.result.properties = this.result.properties || {};
|
||||||
return this.result.properties[key];
|
return this.result.properties[key];
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.setSpecProperty = function(key, value) {
|
setSpecProperty(key, value) {
|
||||||
this.result.properties = this.result.properties || {};
|
this.result.properties = this.result.properties || {};
|
||||||
this.result.properties[key] = value;
|
this.result.properties[key] = value;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.executionStarted = function() {
|
executionStarted() {
|
||||||
this.timer.start();
|
this.timer.start();
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.executionFinished = function(excluded, failSpecWithNoExp) {
|
executionFinished(excluded, failSpecWithNoExp) {
|
||||||
if (this.autoCleanClosures) {
|
if (this.autoCleanClosures) {
|
||||||
this.queueableFn.fn = null;
|
this.queueableFn.fn = null;
|
||||||
}
|
}
|
||||||
@@ -860,9 +863,9 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
if (this.result.status !== 'failed') {
|
if (this.result.status !== 'failed') {
|
||||||
this.result.debugLogs = null;
|
this.result.debugLogs = null;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.reset = function() {
|
reset() {
|
||||||
/**
|
/**
|
||||||
* @typedef SpecResult
|
* @typedef SpecResult
|
||||||
* @property {String} id - The unique id of this spec.
|
* @property {String} id - The unique id of this spec.
|
||||||
@@ -901,9 +904,9 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
};
|
};
|
||||||
this.markedPending = this.markedExcluding;
|
this.markedPending = this.markedExcluding;
|
||||||
this.reportedDone = false;
|
this.reportedDone = false;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.handleException = function handleException(e) {
|
handleException(e) {
|
||||||
if (Spec.isPendingSpecException(e)) {
|
if (Spec.isPendingSpecException(e)) {
|
||||||
this.pend(extractCustomPendingMessage(e));
|
this.pend(extractCustomPendingMessage(e));
|
||||||
return;
|
return;
|
||||||
@@ -924,40 +927,33 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
/*
|
pend(message) {
|
||||||
* Marks state as pending
|
|
||||||
* @param {string} [message] An optional reason message
|
|
||||||
*/
|
|
||||||
Spec.prototype.pend = function(message) {
|
|
||||||
this.markedPending = true;
|
this.markedPending = true;
|
||||||
if (message) {
|
if (message) {
|
||||||
this.result.pendingReason = message;
|
this.result.pendingReason = message;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/*
|
// Like pend(), but pending state will survive reset().
|
||||||
* Like {@link Spec#pend}, but pending state will survive {@link Spec#reset}
|
// Useful for fit, xit, where pending state remains.
|
||||||
* Useful for fit, xit, where pending state remains.
|
exclude(message) {
|
||||||
* @param {string} [message] An optional reason message
|
|
||||||
*/
|
|
||||||
Spec.prototype.exclude = function(message) {
|
|
||||||
this.markedExcluding = true;
|
this.markedExcluding = true;
|
||||||
if (this.message) {
|
if (this.message) {
|
||||||
this.excludeMessage = message;
|
this.excludeMessage = message;
|
||||||
}
|
}
|
||||||
this.pend(message);
|
this.pend(message);
|
||||||
};
|
}
|
||||||
|
|
||||||
// TODO: ensure that all access to result goes through .getResult()
|
// TODO: ensure that all access to result goes through .getResult()
|
||||||
// so that the status is correct.
|
// so that the status is correct.
|
||||||
Spec.prototype.getResult = function() {
|
getResult() {
|
||||||
this.result.status = this.status();
|
this.result.status = this.status();
|
||||||
return this.result;
|
return this.result;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.status = function(excluded, failSpecWithNoExpectations) {
|
status(excluded, failSpecWithNoExpectations) {
|
||||||
if (excluded === true) {
|
if (excluded === true) {
|
||||||
return 'excluded';
|
return 'excluded';
|
||||||
}
|
}
|
||||||
@@ -977,22 +973,22 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 'passed';
|
return 'passed';
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.getFullName = function() {
|
getFullName() {
|
||||||
return this.getPath().join(' ');
|
return this.getPath().join(' ');
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.addDeprecationWarning = function(deprecation) {
|
addDeprecationWarning(deprecation) {
|
||||||
if (typeof deprecation === 'string') {
|
if (typeof deprecation === 'string') {
|
||||||
deprecation = { message: deprecation };
|
deprecation = { message: deprecation };
|
||||||
}
|
}
|
||||||
this.result.deprecationWarnings.push(
|
this.result.deprecationWarnings.push(
|
||||||
j$.buildExpectationResult(deprecation)
|
j$.buildExpectationResult(deprecation)
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.debugLog = function(msg) {
|
debugLog(msg) {
|
||||||
if (!this.result.debugLogs) {
|
if (!this.result.debugLogs) {
|
||||||
this.result.debugLogs = [];
|
this.result.debugLogs = [];
|
||||||
}
|
}
|
||||||
@@ -1007,38 +1003,18 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
message: msg,
|
message: msg,
|
||||||
timestamp: this.timer.elapsed()
|
timestamp: this.timer.elapsed()
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
const extractCustomPendingMessage = function(e) {
|
|
||||||
const fullMessage = e.toString(),
|
|
||||||
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
|
|
||||||
boilerplateEnd =
|
|
||||||
boilerplateStart + Spec.pendingSpecExceptionMessage.length;
|
|
||||||
|
|
||||||
return fullMessage.slice(boilerplateEnd);
|
|
||||||
};
|
|
||||||
|
|
||||||
Spec.pendingSpecExceptionMessage = '=> marked Pending';
|
|
||||||
|
|
||||||
Spec.isPendingSpecException = function(e) {
|
|
||||||
return !!(
|
|
||||||
e &&
|
|
||||||
e.toString &&
|
|
||||||
e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interface Spec
|
* @interface Spec
|
||||||
* @see Configuration#specFilter
|
* @see Configuration#specFilter
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
Object.defineProperty(Spec.prototype, 'metadata', {
|
get metadata() {
|
||||||
// NOTE: Although most of jasmine-core only exposes these metadata objects,
|
// NOTE: Although most of jasmine-core only exposes these metadata objects,
|
||||||
// actual Spec instances are still passed to Configuration#specFilter. Until
|
// actual Spec instances are still passed to Configuration#specFilter. Until
|
||||||
// that is fixed, it's important to make sure that all metadata properties
|
// that is fixed, it's important to make sure that all metadata properties
|
||||||
// also exist in compatible form on the underlying Spec.
|
// also exist in compatible form on the underlying Spec.
|
||||||
get: function() {
|
|
||||||
if (!this.metadata_) {
|
if (!this.metadata_) {
|
||||||
this.metadata_ = {
|
this.metadata_ = {
|
||||||
/**
|
/**
|
||||||
@@ -1081,7 +1057,26 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
|
|
||||||
return this.metadata_;
|
return this.metadata_;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
const extractCustomPendingMessage = function(e) {
|
||||||
|
const fullMessage = e.toString(),
|
||||||
|
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
|
||||||
|
boilerplateEnd =
|
||||||
|
boilerplateStart + Spec.pendingSpecExceptionMessage.length;
|
||||||
|
|
||||||
|
return fullMessage.slice(boilerplateEnd);
|
||||||
|
};
|
||||||
|
|
||||||
|
Spec.pendingSpecExceptionMessage = '=> marked Pending';
|
||||||
|
|
||||||
|
Spec.isPendingSpecException = function(e) {
|
||||||
|
return !!(
|
||||||
|
e &&
|
||||||
|
e.toString &&
|
||||||
|
e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return Spec;
|
return Spec;
|
||||||
};
|
};
|
||||||
|
|||||||
117
src/core/Spec.js
117
src/core/Spec.js
@@ -1,5 +1,6 @@
|
|||||||
getJasmineRequireObj().Spec = function(j$) {
|
getJasmineRequireObj().Spec = function(j$) {
|
||||||
function Spec(attrs) {
|
class Spec {
|
||||||
|
constructor(attrs) {
|
||||||
this.expectationFactory = attrs.expectationFactory;
|
this.expectationFactory = attrs.expectationFactory;
|
||||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||||
this.id = attrs.id;
|
this.id = attrs.id;
|
||||||
@@ -18,7 +19,9 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
this.autoCleanClosures =
|
this.autoCleanClosures =
|
||||||
attrs.autoCleanClosures === undefined ? true : !!attrs.autoCleanClosures;
|
attrs.autoCleanClosures === undefined
|
||||||
|
? true
|
||||||
|
: !!attrs.autoCleanClosures;
|
||||||
|
|
||||||
this.getPath = function() {
|
this.getPath = function() {
|
||||||
return attrs.getPath ? attrs.getPath(this) : [];
|
return attrs.getPath ? attrs.getPath(this) : [];
|
||||||
@@ -40,7 +43,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Spec.prototype.addExpectationResult = function(passed, data, isError) {
|
addExpectationResult(passed, data, isError) {
|
||||||
const expectationResult = j$.buildExpectationResult(data);
|
const expectationResult = j$.buildExpectationResult(data);
|
||||||
|
|
||||||
if (passed) {
|
if (passed) {
|
||||||
@@ -61,23 +64,23 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
throw new j$.errors.ExpectationFailed();
|
throw new j$.errors.ExpectationFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.getSpecProperty = function(key) {
|
getSpecProperty(key) {
|
||||||
this.result.properties = this.result.properties || {};
|
this.result.properties = this.result.properties || {};
|
||||||
return this.result.properties[key];
|
return this.result.properties[key];
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.setSpecProperty = function(key, value) {
|
setSpecProperty(key, value) {
|
||||||
this.result.properties = this.result.properties || {};
|
this.result.properties = this.result.properties || {};
|
||||||
this.result.properties[key] = value;
|
this.result.properties[key] = value;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.executionStarted = function() {
|
executionStarted() {
|
||||||
this.timer.start();
|
this.timer.start();
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.executionFinished = function(excluded, failSpecWithNoExp) {
|
executionFinished(excluded, failSpecWithNoExp) {
|
||||||
if (this.autoCleanClosures) {
|
if (this.autoCleanClosures) {
|
||||||
this.queueableFn.fn = null;
|
this.queueableFn.fn = null;
|
||||||
}
|
}
|
||||||
@@ -88,9 +91,9 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
if (this.result.status !== 'failed') {
|
if (this.result.status !== 'failed') {
|
||||||
this.result.debugLogs = null;
|
this.result.debugLogs = null;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.reset = function() {
|
reset() {
|
||||||
/**
|
/**
|
||||||
* @typedef SpecResult
|
* @typedef SpecResult
|
||||||
* @property {String} id - The unique id of this spec.
|
* @property {String} id - The unique id of this spec.
|
||||||
@@ -129,9 +132,9 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
};
|
};
|
||||||
this.markedPending = this.markedExcluding;
|
this.markedPending = this.markedExcluding;
|
||||||
this.reportedDone = false;
|
this.reportedDone = false;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.handleException = function handleException(e) {
|
handleException(e) {
|
||||||
if (Spec.isPendingSpecException(e)) {
|
if (Spec.isPendingSpecException(e)) {
|
||||||
this.pend(extractCustomPendingMessage(e));
|
this.pend(extractCustomPendingMessage(e));
|
||||||
return;
|
return;
|
||||||
@@ -152,40 +155,33 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
/*
|
pend(message) {
|
||||||
* Marks state as pending
|
|
||||||
* @param {string} [message] An optional reason message
|
|
||||||
*/
|
|
||||||
Spec.prototype.pend = function(message) {
|
|
||||||
this.markedPending = true;
|
this.markedPending = true;
|
||||||
if (message) {
|
if (message) {
|
||||||
this.result.pendingReason = message;
|
this.result.pendingReason = message;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/*
|
// Like pend(), but pending state will survive reset().
|
||||||
* Like {@link Spec#pend}, but pending state will survive {@link Spec#reset}
|
// Useful for fit, xit, where pending state remains.
|
||||||
* Useful for fit, xit, where pending state remains.
|
exclude(message) {
|
||||||
* @param {string} [message] An optional reason message
|
|
||||||
*/
|
|
||||||
Spec.prototype.exclude = function(message) {
|
|
||||||
this.markedExcluding = true;
|
this.markedExcluding = true;
|
||||||
if (this.message) {
|
if (this.message) {
|
||||||
this.excludeMessage = message;
|
this.excludeMessage = message;
|
||||||
}
|
}
|
||||||
this.pend(message);
|
this.pend(message);
|
||||||
};
|
}
|
||||||
|
|
||||||
// TODO: ensure that all access to result goes through .getResult()
|
// TODO: ensure that all access to result goes through .getResult()
|
||||||
// so that the status is correct.
|
// so that the status is correct.
|
||||||
Spec.prototype.getResult = function() {
|
getResult() {
|
||||||
this.result.status = this.status();
|
this.result.status = this.status();
|
||||||
return this.result;
|
return this.result;
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.status = function(excluded, failSpecWithNoExpectations) {
|
status(excluded, failSpecWithNoExpectations) {
|
||||||
if (excluded === true) {
|
if (excluded === true) {
|
||||||
return 'excluded';
|
return 'excluded';
|
||||||
}
|
}
|
||||||
@@ -205,22 +201,22 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 'passed';
|
return 'passed';
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.getFullName = function() {
|
getFullName() {
|
||||||
return this.getPath().join(' ');
|
return this.getPath().join(' ');
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.addDeprecationWarning = function(deprecation) {
|
addDeprecationWarning(deprecation) {
|
||||||
if (typeof deprecation === 'string') {
|
if (typeof deprecation === 'string') {
|
||||||
deprecation = { message: deprecation };
|
deprecation = { message: deprecation };
|
||||||
}
|
}
|
||||||
this.result.deprecationWarnings.push(
|
this.result.deprecationWarnings.push(
|
||||||
j$.buildExpectationResult(deprecation)
|
j$.buildExpectationResult(deprecation)
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
Spec.prototype.debugLog = function(msg) {
|
debugLog(msg) {
|
||||||
if (!this.result.debugLogs) {
|
if (!this.result.debugLogs) {
|
||||||
this.result.debugLogs = [];
|
this.result.debugLogs = [];
|
||||||
}
|
}
|
||||||
@@ -235,38 +231,18 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
message: msg,
|
message: msg,
|
||||||
timestamp: this.timer.elapsed()
|
timestamp: this.timer.elapsed()
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
const extractCustomPendingMessage = function(e) {
|
|
||||||
const fullMessage = e.toString(),
|
|
||||||
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
|
|
||||||
boilerplateEnd =
|
|
||||||
boilerplateStart + Spec.pendingSpecExceptionMessage.length;
|
|
||||||
|
|
||||||
return fullMessage.slice(boilerplateEnd);
|
|
||||||
};
|
|
||||||
|
|
||||||
Spec.pendingSpecExceptionMessage = '=> marked Pending';
|
|
||||||
|
|
||||||
Spec.isPendingSpecException = function(e) {
|
|
||||||
return !!(
|
|
||||||
e &&
|
|
||||||
e.toString &&
|
|
||||||
e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @interface Spec
|
* @interface Spec
|
||||||
* @see Configuration#specFilter
|
* @see Configuration#specFilter
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
Object.defineProperty(Spec.prototype, 'metadata', {
|
get metadata() {
|
||||||
// NOTE: Although most of jasmine-core only exposes these metadata objects,
|
// NOTE: Although most of jasmine-core only exposes these metadata objects,
|
||||||
// actual Spec instances are still passed to Configuration#specFilter. Until
|
// actual Spec instances are still passed to Configuration#specFilter. Until
|
||||||
// that is fixed, it's important to make sure that all metadata properties
|
// that is fixed, it's important to make sure that all metadata properties
|
||||||
// also exist in compatible form on the underlying Spec.
|
// also exist in compatible form on the underlying Spec.
|
||||||
get: function() {
|
|
||||||
if (!this.metadata_) {
|
if (!this.metadata_) {
|
||||||
this.metadata_ = {
|
this.metadata_ = {
|
||||||
/**
|
/**
|
||||||
@@ -309,7 +285,26 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
|
|
||||||
return this.metadata_;
|
return this.metadata_;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
const extractCustomPendingMessage = function(e) {
|
||||||
|
const fullMessage = e.toString(),
|
||||||
|
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
|
||||||
|
boilerplateEnd =
|
||||||
|
boilerplateStart + Spec.pendingSpecExceptionMessage.length;
|
||||||
|
|
||||||
|
return fullMessage.slice(boilerplateEnd);
|
||||||
|
};
|
||||||
|
|
||||||
|
Spec.pendingSpecExceptionMessage = '=> marked Pending';
|
||||||
|
|
||||||
|
Spec.isPendingSpecException = function(e) {
|
||||||
|
return !!(
|
||||||
|
e &&
|
||||||
|
e.toString &&
|
||||||
|
e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return Spec;
|
return Spec;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user