Skip to content

Commit 63462dd

Browse files
dfberryboneskull
authored andcommitted
Implement API documentation using npm:documantation.
Fixes #3138 Replaces and closes #3239 basically working Suite and utils work Runner and Suite datatypes work Hook extends Runnable - at least link in description hook is child of mocha and has error first solid pass Remove attempted module link from Hook to Runnable because of documentationjs/documentation#820 Switch API documenation to html output, link to them, include in site build Update TOC Bring lock file in sync with package.json Linting Update package-lock.json
1 parent 741b0bd commit 63462dd

28 files changed

+5885
-1645
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ yarn.lock
2121
*_REMOTE_*
2222
docs/_site
2323
docs/_dist
24+
docs/api
2425
.vscode/
25-

docs/index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js](https://n
5252

5353
- [Installation](#installation)
5454
- [Getting Started](#getting-started)
55+
- [Detects Multiple Calls to `done()`](#detects-multiple-calls-to-done)
5556
- [Assertions](#assertions)
5657
- [Asynchronous Code](#asynchronous-code)
5758
- [Synchronous Code](#synchronous-code)
@@ -1343,4 +1344,4 @@ $ REPORTER=nyan npm test
13431344

13441345
## More Information
13451346

1346-
In addition to chatting with us on [Gitter](https://gitter.im/mochajs/mocha), for additional information such as using spies, mocking, and shared behaviours be sure to check out the [Mocha Wiki](https://github.com/mochajs/mocha/wiki) on GitHub. For discussions join the [Google Group](https://groups.google.com/group/mochajs). For a running example of Mocha, view [example/tests.html](example/tests.html). For the JavaScript API, view the [source](https://github.com/mochajs/mocha/blob/master/lib/mocha.js#L51).
1347+
In addition to chatting with us on [Gitter](https://gitter.im/mochajs/mocha), for additional information such as using spies, mocking, and shared behaviours be sure to check out the [Mocha Wiki](https://github.com/mochajs/mocha/wiki) on GitHub. For discussions join the [Google Group](https://groups.google.com/group/mochajs). For a running example of Mocha, view [example/tests.html](example/tests.html). For the JavaScript API, view the [API documentation](api/) or the [source](https://github.com/mochajs/mocha/blob/master/lib/mocha.js#L51).

lib/context.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
2-
2+
/**
3+
* @module Context
4+
*/
35
/**
46
* Expose `Context`.
57
*/
@@ -18,7 +20,7 @@ function Context () {}
1820
*
1921
* @api private
2022
* @param {Runnable} runnable
21-
* @return {Context}
23+
* @return {Context} context
2224
*/
2325
Context.prototype.runnable = function (runnable) {
2426
if (!arguments.length) {

lib/hook.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
'use strict';
2-
2+
/**
3+
* @module Hook
4+
*
5+
*/
36
/**
47
* Module dependencies.
58
*/
@@ -14,8 +17,12 @@ var inherits = require('./utils').inherits;
1417
module.exports = Hook;
1518

1619
/**
17-
* Initialize a new `Hook` with the given `title` and callback `fn`.
20+
* Initialize a new `Hook` with the given `title` and callback `fn`. Derived from
21+
* `Runnable`.
1822
*
23+
* @memberof Mocha
24+
* @public
25+
* @class
1926
* @param {String} title
2027
* @param {Function} fn
2128
* @api private
@@ -33,6 +40,8 @@ inherits(Hook, Runnable);
3340
/**
3441
* Get or set the test `err`.
3542
*
43+
* @memberof Mocha.Hook
44+
* @public
3645
* @param {Error} err
3746
* @return {Error}
3847
* @api public

lib/mocha.js

+43-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
* Copyright(c) 2011 TJ Holowaychuk <[email protected]>
66
* MIT Licensed
77
*/
8-
8+
/**
9+
* @namespace Mocha
10+
* @module Mocha
11+
*/
912
/**
1013
* Module dependencies.
1114
*/
@@ -34,11 +37,25 @@ if (!process.browser) {
3437
* Expose internals.
3538
*/
3639

40+
/**
41+
* @public
42+
* @class utils
43+
* @memberof Mocha
44+
*/
3745
exports.utils = utils;
3846
exports.interfaces = require('./interfaces');
47+
/**
48+
*
49+
* @memberof Mocha
50+
* @public
51+
*/
3952
exports.reporters = reporters;
4053
exports.Runnable = require('./runnable');
4154
exports.Context = require('./context');
55+
/**
56+
*
57+
* @memberof Mocha
58+
*/
4259
exports.Runner = require('./runner');
4360
exports.Suite = require('./suite');
4461
exports.Hook = require('./hook');
@@ -71,6 +88,8 @@ function image (name) {
7188
* - `fullTrace` display the full stack-trace on failing
7289
* - `grep` string or regexp to filter tests with
7390
*
91+
* @public
92+
* @class Mocha
7493
* @param {Object} options
7594
* @api public
7695
*/
@@ -106,6 +125,7 @@ function Mocha (options) {
106125
/**
107126
* Enable or disable bailing on the first failure.
108127
*
128+
* @public
109129
* @api public
110130
* @param {boolean} [bail]
111131
*/
@@ -120,6 +140,7 @@ Mocha.prototype.bail = function (bail) {
120140
/**
121141
* Add test `file`.
122142
*
143+
* @public
123144
* @api public
124145
* @param {string} file
125146
*/
@@ -131,6 +152,7 @@ Mocha.prototype.addFile = function (file) {
131152
/**
132153
* Set reporter to `reporter`, defaults to "spec".
133154
*
155+
* @public
134156
* @param {String|Function} reporter name or constructor
135157
* @param {Object} reporterOptions optional options
136158
* @api public
@@ -181,7 +203,7 @@ Mocha.prototype.reporter = function (reporter, reporterOptions) {
181203

182204
/**
183205
* Set test UI `name`, defaults to "bdd".
184-
*
206+
* @public
185207
* @api public
186208
* @param {string} bdd
187209
*/
@@ -260,6 +282,7 @@ Mocha.prototype._growl = function (runner, reporter) {
260282
/**
261283
* Escape string and add it to grep as a regexp.
262284
*
285+
* @public
263286
* @api public
264287
* @param str
265288
* @returns {Mocha}
@@ -271,6 +294,7 @@ Mocha.prototype.fgrep = function (str) {
271294
/**
272295
* Add regexp to grep, if `re` is a string it is escaped.
273296
*
297+
* @public
274298
* @param {RegExp|String} re
275299
* @return {Mocha}
276300
* @api public
@@ -290,6 +314,7 @@ Mocha.prototype.grep = function (re) {
290314
/**
291315
* Invert `.grep()` matches.
292316
*
317+
* @public
293318
* @return {Mocha}
294319
* @api public
295320
*/
@@ -301,6 +326,7 @@ Mocha.prototype.invert = function () {
301326
/**
302327
* Ignore global leaks.
303328
*
329+
* @public
304330
* @param {Boolean} ignore
305331
* @return {Mocha}
306332
* @api public
@@ -317,6 +343,7 @@ Mocha.prototype.ignoreLeaks = function (ignore) {
317343
*
318344
* @return {Mocha}
319345
* @api public
346+
* @public
320347
*/
321348
Mocha.prototype.checkLeaks = function () {
322349
this.options.ignoreLeaks = false;
@@ -328,6 +355,7 @@ Mocha.prototype.checkLeaks = function () {
328355
*
329356
* @return {Mocha}
330357
* @api public
358+
* @public
331359
*/
332360
Mocha.prototype.fullTrace = function () {
333361
this.options.fullStackTrace = true;
@@ -339,6 +367,7 @@ Mocha.prototype.fullTrace = function () {
339367
*
340368
* @return {Mocha}
341369
* @api public
370+
* @public
342371
*/
343372
Mocha.prototype.growl = function () {
344373
this.options.growl = true;
@@ -351,6 +380,7 @@ Mocha.prototype.growl = function () {
351380
* @param {Array|String} globals
352381
* @return {Mocha}
353382
* @api public
383+
* @public
354384
* @param {Array|string} globals
355385
* @return {Mocha}
356386
*/
@@ -365,6 +395,7 @@ Mocha.prototype.globals = function (globals) {
365395
* @param {Boolean} colors
366396
* @return {Mocha}
367397
* @api public
398+
* @public
368399
* @param {boolean} colors
369400
* @return {Mocha}
370401
*/
@@ -381,6 +412,7 @@ Mocha.prototype.useColors = function (colors) {
381412
* @param {Boolean} inlineDiffs
382413
* @return {Mocha}
383414
* @api public
415+
* @public
384416
* @param {boolean} inlineDiffs
385417
* @return {Mocha}
386418
*/
@@ -395,6 +427,7 @@ Mocha.prototype.useInlineDiffs = function (inlineDiffs) {
395427
* @param {Boolean} hideDiff
396428
* @return {Mocha}
397429
* @api public
430+
* @public
398431
* @param {boolean} hideDiff
399432
* @return {Mocha}
400433
*/
@@ -409,6 +442,7 @@ Mocha.prototype.hideDiff = function (hideDiff) {
409442
* @param {Number} timeout
410443
* @return {Mocha}
411444
* @api public
445+
* @public
412446
* @param {number} timeout
413447
* @return {Mocha}
414448
*/
@@ -423,6 +457,7 @@ Mocha.prototype.timeout = function (timeout) {
423457
* @param {Number} retry times
424458
* @return {Mocha}
425459
* @api public
460+
* @public
426461
*/
427462
Mocha.prototype.retries = function (n) {
428463
this.suite.retries(n);
@@ -435,6 +470,7 @@ Mocha.prototype.retries = function (n) {
435470
* @param {Number} slow
436471
* @return {Mocha}
437472
* @api public
473+
* @public
438474
* @param {number} slow
439475
* @return {Mocha}
440476
*/
@@ -449,6 +485,7 @@ Mocha.prototype.slow = function (slow) {
449485
* @param {Boolean} enabled
450486
* @return {Mocha}
451487
* @api public
488+
* @public
452489
* @param {boolean} enabled
453490
* @return {Mocha}
454491
*/
@@ -462,6 +499,7 @@ Mocha.prototype.enableTimeouts = function (enabled) {
462499
*
463500
* @return {Mocha}
464501
* @api public
502+
* @public
465503
*/
466504
Mocha.prototype.asyncOnly = function () {
467505
this.options.asyncOnly = true;
@@ -472,6 +510,7 @@ Mocha.prototype.asyncOnly = function () {
472510
* Disable syntax highlighting (in browser).
473511
*
474512
* @api public
513+
* @public
475514
*/
476515
Mocha.prototype.noHighlighting = function () {
477516
this.options.noHighlighting = true;
@@ -483,6 +522,7 @@ Mocha.prototype.noHighlighting = function () {
483522
*
484523
* @return {Mocha}
485524
* @api public
525+
* @public
486526
*/
487527
Mocha.prototype.allowUncaught = function () {
488528
this.options.allowUncaught = true;
@@ -528,6 +568,7 @@ Mocha.prototype.forbidPending = function () {
528568
* cache first in whichever manner best suits your needs.
529569
*
530570
* @api public
571+
* @public
531572
* @param {Function} fn
532573
* @return {Runner}
533574
*/

lib/ms.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
2-
2+
/**
3+
* @module milliseconds
4+
*/
35
/**
46
* Helpers.
57
*/
@@ -13,6 +15,8 @@ var y = d * 365.25;
1315
/**
1416
* Parse or format the given `val`.
1517
*
18+
* @memberof Mocha
19+
* @public
1620
* @api public
1721
* @param {string|number} val
1822
* @return {string|number}

lib/reporters/base.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
2-
2+
/**
3+
* @module Base
4+
*/
35
/**
46
* Module dependencies.
57
*/
@@ -185,6 +187,9 @@ var generateDiff = exports.generateDiff = function (actual, expected) {
185187
/**
186188
* Output the given `failures` as a list.
187189
*
190+
* @public
191+
* @memberof Mocha.reporters.Base
192+
* @variation 1
188193
* @param {Array} failures
189194
* @api public
190195
*/
@@ -261,6 +266,9 @@ exports.list = function (failures) {
261266
* stats such as test duration, number
262267
* of tests passed / failed etc.
263268
*
269+
* @memberof Mocha.reporters
270+
* @public
271+
* @class
264272
* @param {Runner} runner
265273
* @api public
266274
*/
@@ -328,6 +336,8 @@ function Base (runner) {
328336
* Output common epilogue used by many of
329337
* the bundled reporters.
330338
*
339+
* @memberof Mocha.reporters.Base
340+
* @public
331341
* @api public
332342
*/
333343
Base.prototype.epilogue = function () {

lib/reporters/doc.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
2-
2+
/**
3+
* @module Doc
4+
*/
35
/**
46
* Module dependencies.
57
*/
@@ -16,6 +18,10 @@ exports = module.exports = Doc;
1618
/**
1719
* Initialize a new `Doc` reporter.
1820
*
21+
* @class
22+
* @memberof Mocha.reporters
23+
* @extends {Base}
24+
* @public
1925
* @param {Runner} runner
2026
* @api public
2127
*/

lib/reporters/dot.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
2-
2+
/**
3+
* @module Dot
4+
*/
35
/**
46
* Module dependencies.
57
*/
@@ -17,6 +19,10 @@ exports = module.exports = Dot;
1719
/**
1820
* Initialize a new `Dot` matrix test reporter.
1921
*
22+
* @class
23+
* @memberof Mocha.reporters
24+
* @extends Mocha.reporters.Base
25+
* @public
2026
* @api public
2127
* @param {Runner} runner
2228
*/

0 commit comments

Comments
 (0)