Skip to content

Commit e519a3d

Browse files
authored
fix(testrunner): better capture Location for hooks (#1680)
1 parent f2b13c0 commit e519a3d

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

utils/testrunner/Location.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ class Location {
4949
return this._fileName + ':' + this._lineNumber + ':' + this._columnNumber;
5050
}
5151

52-
// TODO: static getCallerLocationIn(glob) vs getCallerLocationIgnoring(glob).
53-
54-
static getCallerLocation(filename) {
52+
static getCallerLocation(ignorePrefix = __dirname) {
5553
const error = new Error();
5654
const stackFrames = error.stack.split('\n').slice(1);
5755
const location = new Location();
@@ -71,7 +69,7 @@ class Location {
7169
if (!match)
7270
return null;
7371
const filePath = match[1];
74-
if (filePath === __filename || filePath === filename)
72+
if (filePath === __filename || filePath.startsWith(ignorePrefix))
7573
continue;
7674

7775
location._filePath = filePath;

utils/testrunner/Matchers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class MatchError extends Error {
4040
super(message);
4141
this.name = this.constructor.name;
4242
this.formatter = formatter;
43-
this.location = Location.getCallerLocation(__filename);
43+
this.location = Location.getCallerLocation();
4444
Error.captureStackTrace(this, this.constructor);
4545
}
4646
}

utils/testrunner/Test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const TestExpectation = {
2323
};
2424

2525
function createHook(callback, name) {
26-
const location = Location.getCallerLocation(__filename);
26+
const location = Location.getCallerLocation();
2727
return { name, body: callback, location };
2828
}
2929

utils/testrunner/TestCollector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class TestCollector {
136136
this._currentSuite = new Suite(null, '', new Location());
137137

138138
this._api.describe = specBuilder(this._suiteModifiers, this._suiteAttributes, (specs, name, suiteCallback, ...suiteArgs) => {
139-
const location = Location.getCallerLocation(__filename);
139+
const location = Location.getCallerLocation();
140140
const suite = new Suite(this._currentSuite, name, location);
141141
for (const { callback, args } of specs)
142142
callback(suite, ...args);
@@ -146,7 +146,7 @@ class TestCollector {
146146
this._currentSuite = suite.parentSuite();
147147
});
148148
this._api.it = specBuilder(this._testModifiers, this._testAttributes, (specs, name, testCallback) => {
149-
const location = Location.getCallerLocation(__filename);
149+
const location = Location.getCallerLocation();
150150
const test = new Test(this._currentSuite, name, testCallback, location);
151151
test.setTimeout(timeout);
152152
for (const { callback, args } of specs)

0 commit comments

Comments
 (0)