Skip to content
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

Add ability to query Mocha version programmatically #3535

Merged
merged 5 commits into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/mocha.js
Original file line number Diff line number Diff line change
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW these are the default values for configurable and writable and could be omitted.

Is there a reasoning behind enumerable: true?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @plroebuck

Copy link
Contributor Author

@plroebuck plroebuck Nov 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaults were explicit to imply intent (as there were only three boolean properties) rather than oversight. Found various examples (like this) within Node.js itself that did same. Airbnb doesn't mention one way or the other.
enumerable: true allows it to show up in a for loop over properties.

You feel otherwise concerning the style?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ORESoftware, don't know how to interpret your "thumbs up"...

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
Original file line number Diff line number Diff line change
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/"
}
}