From 314933479e306d4862526c98cc9787aa2c37a969 Mon Sep 17 00:00:00 2001 From: balazs4 Date: Mon, 17 May 2021 22:26:40 +0200 Subject: [PATCH] fix: caller filename in dynamic testcases --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 89bcc25..d85ddbf 100644 --- a/index.js +++ b/index.js @@ -15,14 +15,19 @@ module.exports.test = async (description, assertion = null) => { : txt ); }; - const [, , caller] = new Error().stack.split('at '); - const [, filename] = caller.match(/\((.*)\)/); + const [, caller] = new Error().stack + .split('\n') + .filter((x) => x.startsWith(' at')); + const [, filename] = caller.match(/\((.*)\)/) || [ + , + caller.replace(' at', '').trim(), + ]; const origin = process.stdout.hasColors && process.stdout.hasColors() === true ? `\x1b[2m${filename}\x1b[0m` : filename; - const name = + const name = process.stdout.hasColors && process.stdout.hasColors() === true ? `\x1b[1m${description}\x1b[0m` : description;