Report the path/url of the file that the spec/suite was defined in
Fixes #1884
This commit is contained in:
@@ -674,17 +674,23 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
this.describe = function(description, definitionFn) {
|
||||
ensureIsNotNested('describe');
|
||||
return suiteBuilder.describe(description, definitionFn).metadata;
|
||||
const filename = callerCallerFilename();
|
||||
return suiteBuilder.describe(description, definitionFn, filename)
|
||||
.metadata;
|
||||
};
|
||||
|
||||
this.xdescribe = function(description, definitionFn) {
|
||||
ensureIsNotNested('xdescribe');
|
||||
return suiteBuilder.xdescribe(description, definitionFn).metadata;
|
||||
const filename = callerCallerFilename();
|
||||
return suiteBuilder.xdescribe(description, definitionFn, filename)
|
||||
.metadata;
|
||||
};
|
||||
|
||||
this.fdescribe = function(description, definitionFn) {
|
||||
ensureIsNotNested('fdescribe');
|
||||
return suiteBuilder.fdescribe(description, definitionFn).metadata;
|
||||
const filename = callerCallerFilename();
|
||||
return suiteBuilder.fdescribe(description, definitionFn, filename)
|
||||
.metadata;
|
||||
};
|
||||
|
||||
function specResultCallback(spec, result, next) {
|
||||
@@ -711,17 +717,20 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
this.it = function(description, fn, timeout) {
|
||||
ensureIsNotNested('it');
|
||||
return suiteBuilder.it(description, fn, timeout).metadata;
|
||||
const filename = callerCallerFilename();
|
||||
return suiteBuilder.it(description, fn, timeout, filename).metadata;
|
||||
};
|
||||
|
||||
this.xit = function(description, fn, timeout) {
|
||||
ensureIsNotNested('xit');
|
||||
return suiteBuilder.xit(description, fn, timeout).metadata;
|
||||
const filename = callerCallerFilename();
|
||||
return suiteBuilder.xit(description, fn, timeout, filename).metadata;
|
||||
};
|
||||
|
||||
this.fit = function(description, fn, timeout) {
|
||||
ensureIsNotNested('fit');
|
||||
return suiteBuilder.fit(description, fn, timeout).metadata;
|
||||
const filename = callerCallerFilename();
|
||||
return suiteBuilder.fit(description, fn, timeout, filename).metadata;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -861,5 +870,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
}
|
||||
|
||||
function callerCallerFilename() {
|
||||
return new j$.StackTrace(new Error()).frames[3].file;
|
||||
}
|
||||
|
||||
return Env;
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||
this.resultCallback = attrs.resultCallback || function() {};
|
||||
this.id = attrs.id;
|
||||
this.filename = attrs.filename;
|
||||
this.description = attrs.description || '';
|
||||
this.queueableFn = attrs.queueableFn;
|
||||
this.beforeAndAfterFns =
|
||||
@@ -37,35 +38,7 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
this.exclude();
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef SpecResult
|
||||
* @property {String} id - The unique id of this spec.
|
||||
* @property {String} description - The description passed to the {@link it} that created this spec.
|
||||
* @property {String} fullName - The full description including all ancestors of this spec.
|
||||
* @property {Expectation[]} failedExpectations - The list of expectations that failed during execution of this spec.
|
||||
* @property {Expectation[]} passedExpectations - The list of expectations that passed during execution of this spec.
|
||||
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred during execution this spec.
|
||||
* @property {String} pendingReason - If the spec is {@link pending}, this will be the reason.
|
||||
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
|
||||
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
|
||||
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
|
||||
* @property {DebugLogEntry[]|null} debugLogs - Messages, if any, that were logged using {@link jasmine.debugLog} during a failing spec.
|
||||
* @since 2.0.0
|
||||
*/
|
||||
this.result = {
|
||||
id: this.id,
|
||||
description: this.description,
|
||||
fullName: this.getFullName(),
|
||||
failedExpectations: [],
|
||||
passedExpectations: [],
|
||||
deprecationWarnings: [],
|
||||
pendingReason: '',
|
||||
duration: null,
|
||||
properties: null,
|
||||
debugLogs: null
|
||||
};
|
||||
|
||||
this.reportedDone = false;
|
||||
this.reset();
|
||||
}
|
||||
|
||||
Spec.prototype.addExpectationResult = function(passed, data, isError) {
|
||||
@@ -175,14 +148,31 @@ getJasmineRequireObj().Spec = function(j$) {
|
||||
};
|
||||
|
||||
Spec.prototype.reset = function() {
|
||||
/**
|
||||
* @typedef SpecResult
|
||||
* @property {String} id - The unique id of this spec.
|
||||
* @property {String} description - The description passed to the {@link it} that created this spec.
|
||||
* @property {String} fullName - The full description including all ancestors of this spec.
|
||||
* @property {String} filename - The name of the file the spec was defined in.
|
||||
* @property {Expectation[]} failedExpectations - The list of expectations that failed during execution of this spec.
|
||||
* @property {Expectation[]} passedExpectations - The list of expectations that passed during execution of this spec.
|
||||
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred during execution this spec.
|
||||
* @property {String} pendingReason - If the spec is {@link pending}, this will be the reason.
|
||||
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
|
||||
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
|
||||
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
|
||||
* @property {DebugLogEntry[]|null} debugLogs - Messages, if any, that were logged using {@link jasmine.debugLog} during a failing spec.
|
||||
* @since 2.0.0
|
||||
*/
|
||||
this.result = {
|
||||
id: this.id,
|
||||
description: this.description,
|
||||
fullName: this.getFullName(),
|
||||
filename: this.filename,
|
||||
failedExpectations: [],
|
||||
passedExpectations: [],
|
||||
deprecationWarnings: [],
|
||||
pendingReason: this.excludeMessage,
|
||||
pendingReason: this.excludeMessage || '',
|
||||
duration: null,
|
||||
properties: null,
|
||||
debugLogs: null
|
||||
|
||||
@@ -4,6 +4,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
this.id = attrs.id;
|
||||
this.parentSuite = attrs.parentSuite;
|
||||
this.description = attrs.description;
|
||||
this.filename = attrs.filename;
|
||||
this.expectationFactory = attrs.expectationFactory;
|
||||
this.asyncExpectationFactory = attrs.asyncExpectationFactory;
|
||||
this.throwOnExpectationFailure = !!attrs.throwOnExpectationFailure;
|
||||
@@ -109,6 +110,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
* @property {String} id - The unique id of this suite.
|
||||
* @property {String} description - The description text passed to the {@link describe} that made this suite.
|
||||
* @property {String} fullName - The full description including all ancestors of this suite.
|
||||
* @property {String} filename - The name of the file the suite was defined in.
|
||||
* @property {Expectation[]} failedExpectations - The list of expectations that failed in an {@link afterAll} for this suite.
|
||||
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred on this suite.
|
||||
* @property {String} status - Once the suite has completed, this string represents the pass/fail status of this suite.
|
||||
@@ -120,6 +122,7 @@ getJasmineRequireObj().Suite = function(j$) {
|
||||
id: this.id,
|
||||
description: this.description,
|
||||
fullName: this.getFullName(),
|
||||
filename: this.filename,
|
||||
failedExpectations: [],
|
||||
deprecationWarnings: [],
|
||||
duration: null,
|
||||
|
||||
@@ -22,9 +22,9 @@ getJasmineRequireObj().SuiteBuilder = function(j$) {
|
||||
this.focusedRunables = [];
|
||||
}
|
||||
|
||||
describe(description, definitionFn) {
|
||||
describe(description, definitionFn, filename) {
|
||||
ensureIsFunction(definitionFn, 'describe');
|
||||
const suite = this.suiteFactory_(description);
|
||||
const suite = this.suiteFactory_(description, filename);
|
||||
if (definitionFn.length > 0) {
|
||||
throw new Error('describe does not expect any arguments');
|
||||
}
|
||||
@@ -35,9 +35,9 @@ getJasmineRequireObj().SuiteBuilder = function(j$) {
|
||||
return suite;
|
||||
}
|
||||
|
||||
fdescribe(description, definitionFn) {
|
||||
fdescribe(description, definitionFn, filename) {
|
||||
ensureIsFunction(definitionFn, 'fdescribe');
|
||||
const suite = this.suiteFactory_(description);
|
||||
const suite = this.suiteFactory_(description, filename);
|
||||
suite.isFocused = true;
|
||||
|
||||
this.focusedRunables.push(suite.id);
|
||||
@@ -47,37 +47,37 @@ getJasmineRequireObj().SuiteBuilder = function(j$) {
|
||||
return suite;
|
||||
}
|
||||
|
||||
xdescribe(description, definitionFn) {
|
||||
xdescribe(description, definitionFn, filename) {
|
||||
ensureIsFunction(definitionFn, 'xdescribe');
|
||||
const suite = this.suiteFactory_(description);
|
||||
const suite = this.suiteFactory_(description, filename);
|
||||
suite.exclude();
|
||||
this.addSpecsToSuite_(suite, definitionFn);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
it(description, fn, timeout) {
|
||||
it(description, fn, timeout, filename) {
|
||||
// it() sometimes doesn't have a fn argument, so only check the type if
|
||||
// it's given.
|
||||
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||
ensureIsFunctionOrAsync(fn, 'it');
|
||||
}
|
||||
|
||||
return this.it_(description, fn, timeout);
|
||||
return this.it_(description, fn, timeout, filename);
|
||||
}
|
||||
|
||||
xit(description, fn, timeout) {
|
||||
xit(description, fn, timeout, filename) {
|
||||
// xit(), like it(), doesn't always have a fn argument, so only check the
|
||||
// type when needed.
|
||||
if (arguments.length > 1 && typeof fn !== 'undefined') {
|
||||
ensureIsFunctionOrAsync(fn, 'xit');
|
||||
}
|
||||
const spec = this.it_(description, fn, timeout);
|
||||
const spec = this.it_(description, fn, timeout, filename);
|
||||
spec.exclude('Temporarily disabled with xit');
|
||||
return spec;
|
||||
}
|
||||
|
||||
fit(description, fn, timeout) {
|
||||
fit(description, fn, timeout, filename) {
|
||||
// Unlike it and xit, the function is required because it doesn't make
|
||||
// sense to focus on nothing.
|
||||
ensureIsFunctionOrAsync(fn, 'fit');
|
||||
@@ -85,7 +85,7 @@ getJasmineRequireObj().SuiteBuilder = function(j$) {
|
||||
if (timeout) {
|
||||
j$.util.validateTimeout(timeout);
|
||||
}
|
||||
const spec = this.specFactory_(description, fn, timeout);
|
||||
const spec = this.specFactory_(description, fn, timeout, filename);
|
||||
this.currentDeclarationSuite_.addChild(spec);
|
||||
this.focusedRunables.push(spec.id);
|
||||
this.unfocusAncestor_();
|
||||
@@ -145,12 +145,12 @@ getJasmineRequireObj().SuiteBuilder = function(j$) {
|
||||
});
|
||||
}
|
||||
|
||||
it_(description, fn, timeout) {
|
||||
it_(description, fn, timeout, filename) {
|
||||
if (timeout) {
|
||||
j$.util.validateTimeout(timeout);
|
||||
}
|
||||
|
||||
const spec = this.specFactory_(description, fn, timeout);
|
||||
const spec = this.specFactory_(description, fn, timeout, filename);
|
||||
if (this.currentDeclarationSuite_.markedExcluding) {
|
||||
spec.exclude();
|
||||
}
|
||||
@@ -159,11 +159,12 @@ getJasmineRequireObj().SuiteBuilder = function(j$) {
|
||||
return spec;
|
||||
}
|
||||
|
||||
suiteFactory_(description) {
|
||||
suiteFactory_(description, filename) {
|
||||
const config = this.env_.configuration();
|
||||
return new j$.Suite({
|
||||
id: 'suite' + this.nextSuiteId_++,
|
||||
description,
|
||||
filename,
|
||||
parentSuite: this.currentDeclarationSuite_,
|
||||
timer: new j$.Timer(),
|
||||
expectationFactory: this.expectationFactory_,
|
||||
@@ -196,12 +197,13 @@ getJasmineRequireObj().SuiteBuilder = function(j$) {
|
||||
this.currentDeclarationSuite_ = parentSuite;
|
||||
}
|
||||
|
||||
specFactory_(description, fn, timeout) {
|
||||
specFactory_(description, fn, timeout, filename) {
|
||||
this.totalSpecsDefined++;
|
||||
const config = this.env_.configuration();
|
||||
const suite = this.currentDeclarationSuite_;
|
||||
const spec = new j$.Spec({
|
||||
id: 'spec' + this.nextSpecId_++,
|
||||
filename,
|
||||
beforeAndAfterFns: beforeAndAfterFns(suite),
|
||||
expectationFactory: this.expectationFactory_,
|
||||
asyncExpectationFactory: this.specAsyncExpectationFactory_,
|
||||
|
||||
Reference in New Issue
Block a user