-
-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: add a global mocha variable #5089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Marking as draft pending triage of #5084. Thanks for sending it in the meantime! ❤️ |
Oop, I missed that #5084 was marked as accepting PRs. Un-drafting this 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very reasonable to me, thanks for the patience on it not being reviewed for a while! Just a couple small changes requested -really only one behavioral one- WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated permissions change, could you please revert?
Object.defineProperty(globalThis, 'mochaVar', { | ||
get: () => ({ | ||
name, | ||
version | ||
}) | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for most JS environments, but some sandboxed ones disallow changing globalThis
and might even throw. https://github.com/endojs/endo exists today; https://github.com/tc39/proposal-shadowrealm will hopefully exist eventually.
Let's wrap this in a try/catch the same way Error.stackTraceLimit = Infinity;
is wrapped:
Lines 43 to 47 in 3f13bbc
try { | |
Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit? | |
} catch (err) { | |
debug('unable to set Error.stackTraceLimit = Infinity', err); | |
} |
PR Checklist
status: accepting prs
Overview
Mocha now has the mochaVar (open to different name) property in the global scope, including its current name and version. This global property enables external testing utilities to statically identify both the version of Mocha in use and the specific testing framework being utilized.
