Closed DavidAnson closed 4 years ago
This may be because of lambda functions. Try using named function expressions instead.
Lambdas do not have names
Arrow functions ("lambdas" can falsely imply traits JS doesn't have) don't have names, indeed - they can infer them, but in this case, they can't, so they're anonymous.
However, that shouldn't affect what line is indicated, only what name is available to help debugging.
I'd be interested in a PR with a failing test case; if you're willing to submit one, it'd be great to compare with a named function as well as an anonymous one, just to eliminate that as the issue.
I can invest more time here, but it’s worth pointing out that the RegExp used by the project (line 304 in the excerpt above) does not successfully match the last line of the sample stack in the relevant comment (line 281) and furthermore that the unmatched sample line has exactly the problematic form that appears in the repro I already provided above. To expand upon my suggestion in the original comment, it seems the RegExp being used requires a trailing )
after the path which may not be present. The following tweak to the end of that RegExp seems to allow it to match all of the lines of the sample: (?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)?
.
Would you be OK making a PR with that fix and regression tests? :-)
My approach would be to start by pulling the stack parsing code out into its own module so that it can be exercised directly by test code, then to add a new test file to verify the sample forms in the comment are all recognized correctly. I think the new function would take as input the stack array and return an object with properties for each of the res
fields it can populate. This would be ideal for destructuring by the caller, though I do not see a minimum Node.js version for this project, so that may not be viable. I would not include negative tests because the input here is not user-controlled. Is that what you have in mind?
I'd prefer not to exercise it directly; instead to write the tests, test them, and validate the output. Check the existing tests for how to do that with tap.
The code inside the following loop seems to fail the
RegExp
match against the non-tape
stack frames in the second case, so theat:
field is missing from the output. (Specifically, theres
object doesn't get itsfunctionName
,file
,line
,column
, orat
properties set.) An update of theRegExp
to match lines likeat /home/pi/tape-issue/tape-issue.js:9:10
would seem to address this problem.https://github.com/substack/tape/blob/0b5804d43068602e1615dfd395a3d85949bb03da/lib/test.js#L268-L328