From 0873cb53cc9872bf389e0f4356e33508d64710af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Thu, 30 Nov 2017 00:27:08 +0100 Subject: [PATCH] Make the stack trace filter path-independent (auto-detection vs. hardcoded previously) --- ospec/ospec.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ospec/ospec.js b/ospec/ospec.js index a538515a..29f7fdef 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -8,6 +8,13 @@ else window.o = m() if (name != null) spec[name] = ctx = {} + try {throw new Error} catch (e) { + var stackTraceMatcher = new RegExp( + "^(?:(?!Error|" + + e.stack.match(/[\/\\](.*?):\d+:\d+/)[1] + + ").)*$", "gm" + ) + } function o(subject, predicate) { if (predicate === undefined) { if (results == null) throw new Error("Assertions should not occur outside test definitions") @@ -52,7 +59,7 @@ else window.o = m() return spy } o.cleanStackTrace = function(stack) { - return stack.match(/^(?:(?!Error|[\/\\]ospec[\/\\]ospec\.js).)*$/gm).pop() + return stack.match(stackTraceMatcher).pop() } o.run = function(_reporter) { results = []