From c5a833addaafde839a8138718a070f6fdf7f66f0 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 20 Feb 2020 21:28:11 -0800 Subject: [PATCH] missing file --- utils/testrunner/utils.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 utils/testrunner/utils.js diff --git a/utils/testrunner/utils.js b/utils/testrunner/utils.js new file mode 100644 index 0000000000..43e655646f --- /dev/null +++ b/utils/testrunner/utils.js @@ -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; + }, +};