-
-
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?
Changes from all commits
02f5a97
2bd1301
5d6355a
6738303
69370c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -84,3 +84,24 @@ Context.prototype.retries = function (n) { | |||||||||||
this.runnable().retries(n); | ||||||||||||
return this; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Defines a global read-only property `mochaVar` that provides access to Mocha's name and version. | ||||||||||||
* It is accessible globally within the Node.js environment or in the browser | ||||||||||||
* @example | ||||||||||||
* console.log(globalThis.mochaVar); // Outputs: { name: "mocha", version: "X.Y.Z" } | ||||||||||||
* | ||||||||||||
* @property {Object} mochaVar - The global property containing Mocha's name and version. | ||||||||||||
* @property {string} mochaVar.name - The name of the Mocha package. | ||||||||||||
* @property {string} mochaVar.version - The current version of the Mocha package. | ||||||||||||
*/ | ||||||||||||
var mochaPackageJson = require('../package.json'); | ||||||||||||
var version = mochaPackageJson.version; | ||||||||||||
var name = mochaPackageJson.name; | ||||||||||||
|
||||||||||||
Object.defineProperty(globalThis, 'mochaVar', { | ||||||||||||
get: () => ({ | ||||||||||||
name, | ||||||||||||
version | ||||||||||||
}) | ||||||||||||
}); | ||||||||||||
Comment on lines
+102
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Let's wrap this in a try/catch the same way Lines 43 to 47 in 3f13bbc
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
var mochaPackageJson = require('../../package.json'); | ||
var version = mochaPackageJson.version; | ||
var name = mochaPackageJson.name; | ||
|
||
describe('Global "mocha" object', function () { | ||
it('should have the properties name and version', function () { | ||
expect(globalThis.mochaVar.name, 'to equal', name); | ||
expect(globalThis.mochaVar.version, 'to equal', 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.
Unrelated permissions change, could you please revert?