From 67a59c1791073ba8b40c292a676d898bae20d604 Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Fri, 26 Oct 2018 15:20:01 -0500 Subject: [PATCH 1/4] feat(mocha.js): Add ability to query Mocha version Added new public `version` method so current Mocha version can easily be determined programmatically. --- lib/mocha.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/mocha.js b/lib/mocha.js index 1700fe9ca7..28fcd16355 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -677,6 +677,20 @@ Mocha.prototype.forbidPending = function() { return this; }; +/** + * Returns Mocha's version. + * + * @public + * @returns {string} module version as specified by "package.json". + * @example + * + * mocha.version(); + * // => '5.3.0' + */ +Mocha.prototype.version = function() { + return require('../package').version; +}; + /** * Callback to be invoked when test execution is complete. * From 461499e8440a0d5ac1f0d4d9dbf4b4087c4a1eda Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Sat, 3 Nov 2018 03:11:12 -0500 Subject: [PATCH 2/4] feat(lib/mocha.js): Add ability to query Mocha version Replaced `version` method with readonly property. --- lib/mocha.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/mocha.js b/lib/mocha.js index 28fcd16355..e414040622 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -678,18 +678,18 @@ Mocha.prototype.forbidPending = function() { }; /** - * Returns Mocha's version. - * - * @public - * @returns {string} module version as specified by "package.json". - * @example - * - * mocha.version(); - * // => '5.3.0' - */ -Mocha.prototype.version = function() { - return require('../package').version; -}; + * 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. From 7bf8e41bac416fab85db85acd37d0384690f96df Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Sat, 3 Nov 2018 12:59:15 -0500 Subject: [PATCH 3/4] feat(package.json): Add ability to query Mocha version (in browser) Uses `browserify` transform to provide the version number without exposing other package details (for security). --- package.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package.json b/package.json index 002b55e32b..c704f632af 100644 --- a/package.json +++ b/package.json @@ -502,6 +502,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", @@ -518,6 +519,11 @@ "mocha.js", "browser-entry.js" ], + "browserify": { + "transform": [ + "package-json-versionify" + ] + }, "browser": { "growl": "./lib/browser/growl.js", "tty": "./lib/browser/tty.js", From abe2d7684c9b71e69ef47698a19e439508f7f4df Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Sat, 3 Nov 2018 13:15:37 -0500 Subject: [PATCH 4/4] build(package-lock.json): Fix CI setup CI setup doesn't use `npm install`, so "package.json" and "package-lock.json" must remain in sync. --- package-lock.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/package-lock.json b/package-lock.json index 782bb42830..5d4ccfe722 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1316,6 +1316,12 @@ "inherits": "^2.0.1" } }, + "browserify-package-json": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/browserify-package-json/-/browserify-package-json-1.0.1.tgz", + "integrity": "sha1-mN3oqlxWH9bT/km7qhArdLOW/eo=", + "dev": true + }, "browserify-rsa": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz", @@ -13680,6 +13686,15 @@ "thunkify": "^2.1.2" } }, + "package-json-versionify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/package-json-versionify/-/package-json-versionify-1.0.4.tgz", + "integrity": "sha1-WGBYepRIc6a35tJujlH/siMVvxc=", + "dev": true, + "requires": { + "browserify-package-json": "^1.0.0" + } + }, "pako": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.6.tgz",