Skip to content

Commit

Permalink
Add ability to query Mocha version programmatically (#3535)
Browse files Browse the repository at this point in the history
* Added new public `version` property to `Mocha`, available in both Node and browser.
* Used `browserify` transform to prevent exposing any other package details (for security).
  • Loading branch information
plroebuck committed Nov 10, 2018
1 parent cd87a21 commit 593e9b8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
14 changes: 14 additions & 0 deletions lib/mocha.js
Expand Up @@ -677,6 +677,20 @@ Mocha.prototype.forbidPending = function() {
return this;
};

/**
* Mocha version as specified by "package.json".
*
* @name Mocha#version
* @type string
* @readonly
*/
Object.defineProperty(Mocha.prototype, 'version', {
value: require('../package').version,
configurable: false,
enumerable: true,
writable: false
});

/**
* Callback to be invoked when test execution is complete.
*
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions package.json
Expand Up @@ -446,10 +446,19 @@
"type": "git",
"url": "https://github.com/mochajs/mocha.git"
},
"bugs": {
"url": "https://github.com/mochajs/mocha/issues/"
},
"homepage": "https://mochajs.org/",
"logo": "https://cldup.com/S9uQ-cOLYz.svg",
"bin": {
"mocha": "./bin/mocha",
"_mocha": "./bin/_mocha"
},
"directories": {
"lib": "./lib",
"test": "./test"
},
"engines": {
"node": ">= 6.0.0"
},
Expand Down Expand Up @@ -502,6 +511,7 @@
"markdownlint-cli": "^0.9.0",
"nps": "^5.7.1",
"nyc": "^11.7.3",
"package-json-versionify": "^1.0.4",
"prettier-eslint-cli": "^4.7.1",
"rimraf": "^2.5.2",
"svgo": "^0.7.2",
Expand All @@ -518,9 +528,10 @@
"mocha.js",
"browser-entry.js"
],
"directories": {
"lib": "lib",
"test": "test"
"browserify": {
"transform": [
"package-json-versionify"
]
},
"browser": {
"growl": "./lib/browser/growl.js",
Expand All @@ -531,13 +542,8 @@
"path": false,
"supports-color": false
},
"homepage": "https://mochajs.org/",
"logo": "https://cldup.com/S9uQ-cOLYz.svg",
"prettier": {
"singleQuote": true,
"bracketSpacing": false
},
"bugs": {
"url": "https://github.com/mochajs/mocha/issues/"
}
}

0 comments on commit 593e9b8

Please sign in to comment.