fix(testrunner): better capture Location for hooks (#1680)
This commit is contained in:
parent
f2b13c0e93
commit
e519a3d762
|
|
@ -49,9 +49,7 @@ class Location {
|
|||
return this._fileName + ':' + this._lineNumber + ':' + this._columnNumber;
|
||||
}
|
||||
|
||||
// TODO: static getCallerLocationIn(glob) vs getCallerLocationIgnoring(glob).
|
||||
|
||||
static getCallerLocation(filename) {
|
||||
static getCallerLocation(ignorePrefix = __dirname) {
|
||||
const error = new Error();
|
||||
const stackFrames = error.stack.split('\n').slice(1);
|
||||
const location = new Location();
|
||||
|
|
@ -71,7 +69,7 @@ class Location {
|
|||
if (!match)
|
||||
return null;
|
||||
const filePath = match[1];
|
||||
if (filePath === __filename || filePath === filename)
|
||||
if (filePath === __filename || filePath.startsWith(ignorePrefix))
|
||||
continue;
|
||||
|
||||
location._filePath = filePath;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class MatchError extends Error {
|
|||
super(message);
|
||||
this.name = this.constructor.name;
|
||||
this.formatter = formatter;
|
||||
this.location = Location.getCallerLocation(__filename);
|
||||
this.location = Location.getCallerLocation();
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ const TestExpectation = {
|
|||
};
|
||||
|
||||
function createHook(callback, name) {
|
||||
const location = Location.getCallerLocation(__filename);
|
||||
const location = Location.getCallerLocation();
|
||||
return { name, body: callback, location };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ class TestCollector {
|
|||
this._currentSuite = new Suite(null, '', new Location());
|
||||
|
||||
this._api.describe = specBuilder(this._suiteModifiers, this._suiteAttributes, (specs, name, suiteCallback, ...suiteArgs) => {
|
||||
const location = Location.getCallerLocation(__filename);
|
||||
const location = Location.getCallerLocation();
|
||||
const suite = new Suite(this._currentSuite, name, location);
|
||||
for (const { callback, args } of specs)
|
||||
callback(suite, ...args);
|
||||
|
|
@ -146,7 +146,7 @@ class TestCollector {
|
|||
this._currentSuite = suite.parentSuite();
|
||||
});
|
||||
this._api.it = specBuilder(this._testModifiers, this._testAttributes, (specs, name, testCallback) => {
|
||||
const location = Location.getCallerLocation(__filename);
|
||||
const location = Location.getCallerLocation();
|
||||
const test = new Test(this._currentSuite, name, testCallback, location);
|
||||
test.setTimeout(timeout);
|
||||
for (const { callback, args } of specs)
|
||||
|
|
|
|||
Loading…
Reference in a new issue