Skip to content
Open
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
28 changes: 16 additions & 12 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
/**
* @module Context
*/
/**
* Expose `Context`.
*/

module.exports = Context;

/**
* Initialize a new `Context`.
*
*/
class Context {
/**
* @private
*/
function Context() {}
constructor() {}

/**
* Set or get the context `Runnable` to `runnable`.
Expand All @@ -27,7 +24,7 @@ function Context() {}
* @param {Runnable} runnable
* @return {Context} context
*/
Context.prototype.runnable = function (runnable) {
runnable(runnable) {
if (!arguments.length) {
return this._runnable;
}
Expand All @@ -42,7 +39,7 @@ Context.prototype.runnable = function (runnable) {
* @param {number} ms
* @return {Context} self
*/
Context.prototype.timeout = function (ms) {
timeout(ms) {
if (!arguments.length) {
return this.runnable().timeout();
}
Expand All @@ -57,7 +54,7 @@ Context.prototype.timeout = function (ms) {
* @param {number} ms
* @return {Context} self
*/
Context.prototype.slow = function (ms) {
slow(ms) {
if (!arguments.length) {
return this.runnable().slow();
}
Expand All @@ -71,7 +68,7 @@ Context.prototype.slow = function (ms) {
* @private
* @throws Pending
*/
Context.prototype.skip = function () {
skip() {
this.runnable().skip();
};

Expand All @@ -82,10 +79,17 @@ Context.prototype.skip = function () {
* @param {number} n
* @return {Context} self
*/
Context.prototype.retries = function (n) {
retries(n) {
if (!arguments.length) {
return this.runnable().retries();
}
this.runnable().retries(n);
return this;
};
}

/**
* Expose `Context`.
*/

module.exports = Context;
27 changes: 13 additions & 14 deletions lib/hook.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
'use strict';

var Runnable = require('./runnable');
const {inherits, constants} = require('./utils');
const {constants} = require('./utils');
const {MOCHA_ID_PROP_NAME} = constants;

/**
* Expose `Hook`.
*/

module.exports = Hook;

/**
* Initialize a new `Hook` with the given `title` and callback `fn`
*
* @class
* @extends Runnable
*/
class Hook extends Runnable {
/**
* @param {String} title
* @param {Function} fn
*/
function Hook(title, fn) {
Runnable.call(this, title, fn);
constructor(title, fn) {
super(title, fn);
this.type = 'hook';
}

/**
* Inherit from `Runnable.prototype`.
*/
inherits(Hook, Runnable);

/**
* Resets the state for a next run.
*/
Hook.prototype.reset = function () {
Runnable.prototype.reset.call(this);
reset() {
super.reset();
delete this._error;
};

Expand All @@ -44,7 +40,7 @@ Hook.prototype.reset = function () {
* @param {Error} err
* @return {Error}
*/
Hook.prototype.error = function (err) {
error(err) {
if (!arguments.length) {
err = this._error;
this._error = null;
Expand All @@ -60,7 +56,7 @@ Hook.prototype.error = function (err) {
* @private
* @returns {Object}
*/
Hook.prototype.serialize = function serialize() {
serialize() {
return {
$$currentRetry: this.currentRetry(),
$$fullTitle: this.fullTitle(),
Expand All @@ -87,3 +83,6 @@ Hook.prototype.serialize = function serialize() {
[MOCHA_ID_PROP_NAME]: this.id
};
};
}

module.exports = Hook;
11 changes: 7 additions & 4 deletions lib/pending.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
@module Pending
*/

module.exports = Pending;

/**
* Initialize a new `Pending` error with the given message.
*
*/
class Pending {
/**
* @param {string} message
*/
function Pending(message) {
constructor(message) {
this.message = message;
}
}

module.exports = Pending;
20 changes: 12 additions & 8 deletions lib/reporters/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,21 @@ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
var EVENT_SUITE_END = constants.EVENT_SUITE_END;

/**
* Expose `Doc`.
*/

exports = module.exports = Doc;

/**
* Constructs a new `Doc` reporter instance.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
*/
class Doc extends Base {
/**
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function Doc(runner, options) {
Base.call(this, runner, options);
constructor(runner, options) {
super(runner, options);

var indents = 2;

Expand Down Expand Up @@ -96,5 +93,12 @@ function Doc(runner, options) {
);
});
}
}

/**
* Expose `Doc`.
*/

exports = module.exports = Doc;

Doc.description = 'HTML documentation';
20 changes: 9 additions & 11 deletions lib/reporters/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,28 @@
*/

var Base = require('./base');
var inherits = require('../utils').inherits;
var constants = require('../runner').constants;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
var EVENT_RUN_END = constants.EVENT_RUN_END;

/**
* Expose `Dot`.
*/

exports = module.exports = Dot;

/**
* Constructs a new `Dot` reporter instance.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
*/
class Dot extends Base {
/**
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function Dot(runner, options) {
Base.call(this, runner, options);
constructor(runner, options) {
super(runner, options);

var self = this;
var width = (Base.window.width * 0.75) | 0;
Expand Down Expand Up @@ -77,10 +73,12 @@ function Dot(runner, options) {
self.epilogue();
});
}
}

/**
* Inherit from `Base.prototype`.
* Expose `Dot`.
*/
inherits(Dot, Base);

exports = module.exports = Dot;

Dot.description = 'dot matrix representation';
70 changes: 37 additions & 33 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ var escape = utils.escape;

var Date = global.Date;

/**
* Expose `HTML`.
*/

exports = module.exports = HTML;

/**
* Stats template: Result, progress, passes, failures, and duration.
*/
Expand All @@ -57,11 +51,14 @@ var playIcon = '‣';
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
*/
class HTML extends Base {
/**
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function HTML(runner, options) {
Base.call(this, runner, options);
constructor(runner, options) {
super(runner, options);

var self = this;
var stats = this.stats;
Expand Down Expand Up @@ -279,34 +276,12 @@ function HTML(runner, options) {
}
}

/**
* Makes a URL, preserving querystring ("search") parameters.
*
* @param {string} s
* @return {string} A new URL.
*/
function makeUrl(s) {
var search = window.location.search;

// Remove previous {grep, fgrep, invert} query parameters if present
if (search) {
search = search.replace(/[?&](?:f?grep|invert)=[^&\s]*/g, '').replace(/^&/, '?');
}

return (
window.location.pathname +
(search ? search + '&' : '?') +
'grep=' +
encodeURIComponent(s)
);
}

/**
* Provide suite URL.
*
* @param {Object} [suite]
*/
HTML.prototype.suiteURL = function (suite) {
suiteURL(suite) {
return makeUrl('^' + escapeRe(suite.fullTitle()) + ' ');
};

Expand All @@ -315,7 +290,7 @@ HTML.prototype.suiteURL = function (suite) {
*
* @param {Object} [test]
*/
HTML.prototype.testURL = function (test) {
testURL(test) {
return makeUrl('^' + escapeRe(test.fullTitle()) + '$');
};

Expand All @@ -325,7 +300,7 @@ HTML.prototype.testURL = function (test) {
* @param {HTMLLIElement} el
* @param {string} contents
*/
HTML.prototype.addCodeToggle = function (el, contents) {
addCodeToggle(el, contents) {
var h2 = el.getElementsByTagName('h2')[0];

on(h2, 'click', function () {
Expand All @@ -336,6 +311,29 @@ HTML.prototype.addCodeToggle = function (el, contents) {
el.appendChild(pre);
pre.style.display = 'none';
};
}

/**
* Makes a URL, preserving querystring ("search") parameters.
*
* @param {string} s
* @return {string} A new URL.
*/
function makeUrl(s) {
var search = window.location.search;

// Remove previous {grep, fgrep, invert} query parameters if present
if (search) {
search = search.replace(/[?&](?:f?grep|invert)=[^&\s]*/g, '').replace(/^&/, '?');
}

return (
window.location.pathname +
(search ? search + '&' : '?') +
'grep=' +
encodeURIComponent(s)
);
}

/**
* Display error `msg`.
Expand Down Expand Up @@ -420,4 +418,10 @@ function on(el, event, fn) {
}
}

/**
* Expose `HTML`.
*/

exports = module.exports = HTML;

HTML.browserOnly = true;
Loading
Loading