Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions utils/testrunner/Location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion utils/testrunner/Matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion utils/testrunner/Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const TestExpectation = {
};

function createHook(callback, name) {
const location = Location.getCallerLocation(__filename);
const location = Location.getCallerLocation();
return { name, body: callback, location };
}

Expand Down
4 changes: 2 additions & 2 deletions utils/testrunner/TestCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down