Open nicojs opened 3 years ago
Let me do a proposal.
I want to create and maintain a good package that provides you with the most accurate location of the call site. I've already started it here: https://github.com/nicojs/call-id. It will support all actively used browsers (as long as sauce labs or BrowserStack allows me to test them). It can be used as an ESM or CJS module, so it should be easily bundled in browser packages.
I want to implement this feature in both here in mocha and jasmine (https://github.com/jasmine/jasmine/issues/1884). What do you think?
@nicojs is this still relevant given https://github.com/stryker-mutator/stryker-js/pull/3504?
Hi Josh 🙋♂️. It's very cool to see you here! 😄
@nicojs is this still relevant given stryker-mutator/stryker-js#3504?
Yes, it's still very relevant. Since we only know in which file the test was declared, not its location.
About the implementation. There are a couple of open questions:
--testlocationinresults
.esbuild
or tsc
). Is resolving source files part of this feature?
--enable-source-maps
or source-map-support.call-id
as a dependency of mocha?area: nodejs
. This feature could also work in the browser. That was my goal originally with call-id
.
Is your feature request related to a problem or a nice-to-have?? Please describe. I would love a way to discover where tests live inside the files. Could we attach this metadata to a
Test
, orRunnable
?Describe the solution you'd like The only generic way I can think of how to discover the location of the caller of our
it
ortest
functions is by usingnew Error().stack
. This might come with a performance penalty, so we might want to add it behind a new configuration option. Similar to Jest's--testlocationinresults
.Describe alternatives you've considered
This workaround works:
There are numerous libraries available that can parse the stack for us. Jest and tabjs are using stack-utils.
Additional context
You might have guessed it, but we want to use this new
callSite
to improve Stryker's reporting and performance 😅