missing file
This commit is contained in:
parent
4a9db0f52f
commit
c5a833adda
32
utils/testrunner/utils.js
Normal file
32
utils/testrunner/utils.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
getLocation: function(filename) {
|
||||
const error = new Error();
|
||||
const stackFrames = error.stack.split('\n').slice(1);
|
||||
// Find first stackframe that doesn't point to this file.
|
||||
for (let frame of stackFrames) {
|
||||
frame = frame.trim();
|
||||
if (!frame.startsWith('at '))
|
||||
return null;
|
||||
if (frame.endsWith(')')) {
|
||||
const from = frame.indexOf('(');
|
||||
frame = frame.substring(from + 1, frame.length - 1);
|
||||
} else {
|
||||
frame = frame.substring('at '.length);
|
||||
}
|
||||
|
||||
const match = frame.match(/^(.*):(\d+):(\d+)$/);
|
||||
if (!match)
|
||||
return null;
|
||||
const filePath = match[1];
|
||||
const lineNumber = parseInt(match[2], 10);
|
||||
const columnNumber = parseInt(match[3], 10);
|
||||
if (filePath === __filename || filePath === filename)
|
||||
continue;
|
||||
const fileName = filePath.split(path.sep).pop();
|
||||
return { fileName, filePath, lineNumber, columnNumber };
|
||||
}
|
||||
return null;
|
||||
},
|
||||
};
|
||||
Loading…
Reference in a new issue