Skip to content

Commit 24b65e8

Browse files
authored
Merge branch 'master' into master
2 parents 760b4db + 709a09e commit 24b65e8

File tree

13 files changed

+69
-127
lines changed

13 files changed

+69
-127
lines changed

.github/stale.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ exemptLabels:
2525
- reporter
2626
- common-mistake
2727
- developer-experience
28+
- good-first-issue
2829
# Label to use when marking an issue as stale
2930
staleLabel: stale
3031
# Comment to post when marking an issue as stale. Set to `false` to disable

README.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
*Thank you* :kissing_heart: to all of you interested in helping. These are Mocha's immediate needs:
1010

1111
1. Increase test coverage on Node.js and browser
12-
- Increase integration coverage for all reporters
13-
- `html` reporter must be tested in browser
14-
- ~~Basic console reporters (*not* `nyan`, `landing`, etc.) must be tested in **both** browser and Node.js contexts; PhantomJS can consume all console reporters~~
15-
- ~~Filesystem-based reporters must be tested in Node.js context~~
16-
- **UPDATE - May 24 2017**: Thanks to [community contributions](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#mag-coverage), the coverage on most reporters has increased dramatically! The `html` reporter is still in [dire need of coverage](https://coveralls.io/builds/11674428/source?filename=lib%2Freporters%2Fhtml.js).
17-
- Increase coverage against all interfaces (`exports` in particular). Ideally this becomes a "matrix" where we repeat sets of integration tests across all interfaces.
18-
- Refactor non-Node.js-specific tests to allow them to run in a browser context. Node.js-specific tests include those which *require* the CLI or filesystem. Most everything else is fair game.
12+
- Increase integration coverage for all reporters
13+
- `html` reporter must be tested in browser
14+
- ~~Basic console reporters (*not* `nyan`, `landing`, etc.) must be tested in **both** browser and Node.js contexts; PhantomJS can consume all console reporters~~
15+
- ~~Filesystem-based reporters must be tested in Node.js context~~
16+
- **UPDATE - May 24 2017**: Thanks to [community contributions](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#mag-coverage), the coverage on most reporters has increased dramatically! The `html` reporter is still in [dire need of coverage](https://coveralls.io/builds/11674428/source?filename=lib%2Freporters%2Fhtml.js).
17+
- Increase coverage against all interfaces (`exports` in particular). Ideally this becomes a "matrix" where we repeat sets of integration tests across all interfaces.
18+
- Refactor non-Node.js-specific tests to allow them to run in a browser context. Node.js-specific tests include those which *require* the CLI or filesystem. Most everything else is fair game.
1919
2. Review current open pull requests
20-
- We need individuals familiar with Mocha's codebase. Got questions? Ask them in [our chat room](https://gitter.im/mochajs/mocha).
21-
- Pull requests **must** have supporting tests. The only exceptions are pure cosmetic or non-functional changes.
22-
- Pull request contributors must sign [the CLA](https://cla.js.foundation/mochajs/mocha).
20+
- We need individuals familiar with Mocha's codebase. Got questions? Ask them in [our chat room](https://gitter.im/mochajs/mocha).
21+
- Pull requests **must** have supporting tests. The only exceptions are pure cosmetic or non-functional changes.
22+
- Pull request contributors must sign [the CLA](https://cla.js.foundation/mochajs/mocha).
2323
3. Close old, inactive issues and pull requests
24-
- ~~A bot should do this. We need a bot. Got a bot?~~ We now use GitHub's own [probot-stale](https://www.npmjs.com/package/probot-stale).
24+
- ~~A bot should do this. We need a bot. Got a bot?~~ We now use GitHub's own [probot-stale](https://www.npmjs.com/package/probot-stale).
2525
4. Triage issues
26-
- If we run into "critical" bugs, they need fixing.
27-
- "Critical" means Mocha is broken w/o workarounds for a *large percentage* of users
28-
- Otherwise: respond to issues, close new dupe issues, confirm bugs, ask for more info, etc.
26+
- If we run into "critical" bugs, they need fixing.
27+
- "Critical" means Mocha is broken w/o workarounds for a *large percentage* of users
28+
- Otherwise: respond to issues, close new dupe issues, confirm bugs, ask for more info, etc.
2929

3030
Once we gain ground on the above items, we can work together formalize our contribution guidelines and governance. For further info & ideas, please see our [projects](https://github.com/mochajs/mocha/projects/).
3131

lib/context.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Context.prototype.runnable = function (runnable) {
2929
};
3030

3131
/**
32-
* Set test timeout `ms`.
32+
* Set or get test timeout `ms`.
3333
*
3434
* @api private
3535
* @param {number} ms
@@ -51,18 +51,24 @@ Context.prototype.timeout = function (ms) {
5151
* @return {Context} self
5252
*/
5353
Context.prototype.enableTimeouts = function (enabled) {
54+
if (!arguments.length) {
55+
return this.runnable().enableTimeouts();
56+
}
5457
this.runnable().enableTimeouts(enabled);
5558
return this;
5659
};
5760

5861
/**
59-
* Set test slowness threshold `ms`.
62+
* Set or get test slowness threshold `ms`.
6063
*
6164
* @api private
6265
* @param {number} ms
6366
* @return {Context} self
6467
*/
6568
Context.prototype.slow = function (ms) {
69+
if (!arguments.length) {
70+
return this.runnable().slow();
71+
}
6672
this.runnable().slow(ms);
6773
return this;
6874
};
@@ -78,7 +84,7 @@ Context.prototype.skip = function () {
7884
};
7985

8086
/**
81-
* Allow a number of retries on failed tests
87+
* Set or get a number of allowed retries on failed tests
8288
*
8389
* @api private
8490
* @param {number} n

lib/mocha.js

+8
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,14 @@ Mocha.prototype.forbidPending = function () {
505505
/**
506506
* Run tests and invoke `fn()` when complete.
507507
*
508+
* Note that `loadFiles` relies on Node's `require` to execute
509+
* the test interface functions and will be subject to the
510+
* cache - if the files are already in the `require` cache,
511+
* they will effectively be skipped. Therefore, to run tests
512+
* multiple times or to run tests in files that are already
513+
* in the `require` cache, make sure to clear them from the
514+
* cache first in whichever manner best suits your needs.
515+
*
508516
* @api public
509517
* @param {Function} fn
510518
* @return {Runner}

lib/ms.js

+4-44
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,15 @@ var y = d * 365.25;
1313
/**
1414
* Parse or format the given `val`.
1515
*
16-
* Options:
17-
*
18-
* - `long` verbose formatting [false]
19-
*
2016
* @api public
2117
* @param {string|number} val
22-
* @param {Object} options
2318
* @return {string|number}
2419
*/
25-
module.exports = function (val, options) {
26-
options = options || {};
20+
module.exports = function (val) {
2721
if (typeof val === 'string') {
2822
return parse(val);
2923
}
30-
// https://github.com/mochajs/mocha/pull/1035
31-
return options['long'] ? longFormat(val) : shortFormat(val);
24+
return format(val);
3225
};
3326

3427
/**
@@ -74,13 +67,13 @@ function parse (str) {
7467
}
7568

7669
/**
77-
* Short format for `ms`.
70+
* Format for `ms`.
7871
*
7972
* @api private
8073
* @param {number} ms
8174
* @return {string}
8275
*/
83-
function shortFormat (ms) {
76+
function format (ms) {
8477
if (ms >= d) {
8578
return Math.round(ms / d) + 'd';
8679
}
@@ -95,36 +88,3 @@ function shortFormat (ms) {
9588
}
9689
return ms + 'ms';
9790
}
98-
99-
/**
100-
* Long format for `ms`.
101-
*
102-
* @api private
103-
* @param {number} ms
104-
* @return {string}
105-
*/
106-
function longFormat (ms) {
107-
return plural(ms, d, 'day') ||
108-
plural(ms, h, 'hour') ||
109-
plural(ms, m, 'minute') ||
110-
plural(ms, s, 'second') ||
111-
ms + ' ms';
112-
}
113-
114-
/**
115-
* Pluralization helper.
116-
*
117-
* @api private
118-
* @param {number} ms
119-
* @param {number} n
120-
* @param {string} name
121-
*/
122-
function plural (ms, n, name) {
123-
if (ms < n) {
124-
return;
125-
}
126-
if (ms < n * 1.5) {
127-
return Math.floor(ms / n) + ' ' + name;
128-
}
129-
return Math.ceil(ms / n) + ' ' + name + 's';
130-
}

lib/reporters/base.js

+7-31
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ exports.list = function (failures) {
194194
}
195195
var stack = err.stack || message;
196196
var index = message ? stack.indexOf(message) : -1;
197-
var escape = true;
198197

199198
if (index === -1) {
200199
msg = message;
@@ -212,15 +211,14 @@ exports.list = function (failures) {
212211
// explicitly show diff
213212
if (showDiff(err)) {
214213
stringifyDiffObjs(err);
215-
escape = false;
216214
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
217215
var match = message.match(/^([^:]+): expected/);
218216
msg = '\n ' + color('error message', match ? match[1] : msg);
219217

220218
if (exports.inlineDiffs) {
221-
msg += inlineDiff(err, escape);
219+
msg += inlineDiff(err);
222220
} else {
223-
msg += unifiedDiff(err, escape);
221+
msg += unifiedDiff(err);
224222
}
225223
}
226224

@@ -374,11 +372,10 @@ function pad (str, len) {
374372
*
375373
* @api private
376374
* @param {Error} err with actual/expected
377-
* @param {boolean} escape
378375
* @return {string} Diff
379376
*/
380-
function inlineDiff (err, escape) {
381-
var msg = errorDiff(err, 'WordsWithSpace', escape);
377+
function inlineDiff (err) {
378+
var msg = errorDiff(err);
382379

383380
// linenos
384381
var lines = msg.split('\n');
@@ -408,15 +405,11 @@ function inlineDiff (err, escape) {
408405
*
409406
* @api private
410407
* @param {Error} err with actual/expected
411-
* @param {boolean} escape
412408
* @return {string} The diff.
413409
*/
414-
function unifiedDiff (err, escape) {
410+
function unifiedDiff (err) {
415411
var indent = ' ';
416412
function cleanUp (line) {
417-
if (escape) {
418-
line = escapeInvisibles(line);
419-
}
420413
if (line[0] === '+') {
421414
return indent + colorLines('diff added', line);
422415
}
@@ -448,14 +441,10 @@ function unifiedDiff (err, escape) {
448441
*
449442
* @api private
450443
* @param {Error} err
451-
* @param {string} type
452-
* @param {boolean} escape
453444
* @return {string}
454445
*/
455-
function errorDiff (err, type, escape) {
456-
var actual = escape ? escapeInvisibles(err.actual) : err.actual;
457-
var expected = escape ? escapeInvisibles(err.expected) : err.expected;
458-
return diff['diff' + type](actual, expected).map(function (str) {
446+
function errorDiff (err) {
447+
return diff.diffWordsWithSpace(err.actual, err.expected).map(function (str) {
459448
if (str.added) {
460449
return colorLines('diff added', str.value);
461450
}
@@ -466,19 +455,6 @@ function errorDiff (err, type, escape) {
466455
}).join('');
467456
}
468457

469-
/**
470-
* Returns a string with all invisible characters in plain text
471-
*
472-
* @api private
473-
* @param {string} line
474-
* @return {string}
475-
*/
476-
function escapeInvisibles (line) {
477-
return line.replace(/\t/g, '<tab>')
478-
.replace(/\r/g, '<CR>')
479-
.replace(/\n/g, '<LF>\n');
480-
}
481-
482458
/**
483459
* Color lines for `str`, using the color `name`.
484460
*

lib/runnable.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ Runnable.prototype.timeout = function (ms) {
9191
};
9292

9393
/**
94-
* Set & get slow `ms`.
94+
* Set or get slow `ms`.
9595
*
9696
* @api private
9797
* @param {number|string} ms
9898
* @return {Runnable|number} ms or Runnable instance.
9999
*/
100100
Runnable.prototype.slow = function (ms) {
101-
if (typeof ms === 'undefined') {
101+
if (!arguments.length || typeof ms === 'undefined') {
102102
return this._slow;
103103
}
104104
if (typeof ms === 'string') {
@@ -144,7 +144,7 @@ Runnable.prototype.isPending = function () {
144144
};
145145

146146
/**
147-
* Set number of retries.
147+
* Set or get number of retries.
148148
*
149149
* @api private
150150
*/
@@ -156,7 +156,7 @@ Runnable.prototype.retries = function (n) {
156156
};
157157

158158
/**
159-
* Get current retry
159+
* Set or get current retry
160160
*
161161
* @api private
162162
*/
@@ -242,7 +242,7 @@ Runnable.prototype.resetTimeout = function () {
242242
};
243243

244244
/**
245-
* Whitelist a list of globals for this test run.
245+
* Set or get a list of whitelisted globals for this test run.
246246
*
247247
* @api private
248248
* @param {string[]} globals

lib/suite.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Suite.prototype.clone = function () {
9292
};
9393

9494
/**
95-
* Set timeout `ms` or short-hand such as "2s".
95+
* Set or get timeout `ms` or short-hand such as "2s".
9696
*
9797
* @api private
9898
* @param {number|string} ms
@@ -114,7 +114,7 @@ Suite.prototype.timeout = function (ms) {
114114
};
115115

116116
/**
117-
* Set number of times to retry a failed test.
117+
* Set or get number of times to retry a failed test.
118118
*
119119
* @api private
120120
* @param {number|string} n
@@ -130,7 +130,7 @@ Suite.prototype.retries = function (n) {
130130
};
131131

132132
/**
133-
* Set timeout to `enabled`.
133+
* Set or get timeout to `enabled`.
134134
*
135135
* @api private
136136
* @param {boolean} enabled
@@ -146,7 +146,7 @@ Suite.prototype.enableTimeouts = function (enabled) {
146146
};
147147

148148
/**
149-
* Set slow `ms` or short-hand such as "2s".
149+
* Set or get slow `ms` or short-hand such as "2s".
150150
*
151151
* @api private
152152
* @param {number|string} ms
@@ -165,7 +165,7 @@ Suite.prototype.slow = function (ms) {
165165
};
166166

167167
/**
168-
* Sets whether to bail after first error.
168+
* Set or get whether to bail after first error.
169169
*
170170
* @api private
171171
* @param {boolean} bail

test/browser/array.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Array', function () {
2323

2424
describe('Array', function () {
2525
describe('#pop()', function () {
26-
it('should remove and return the last value', function () {
26+
it('should remove and return the last value with expected error', function () {
2727
var arr = [1, 2, 3];
2828
assert(arr.pop() === 3);
2929
assert(arr.pop() === 2);

test/browser/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
}
1313
</script>
1414
<script src="array.spec.js"></script>
15-
<script src="../acceptance/duration.spec.js"></script>
16-
<script src="../acceptance/timeout.spec.js"></script>
15+
<script src="../unit/duration.spec.js"></script>
16+
<script src="../unit/timeout.spec.js"></script>
1717
<script src="multiple-done.spec.js"></script>
1818
<script>
1919
onload = function(){

test/browser/large.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
if (!expr) throw new Error(msg || 'failed');
1212
}
1313
</script>
14-
<script src="large.js"></script>
14+
<script src="large.spec.js"></script>
1515
<script>
1616
onload = function(){
1717
mocha.run();

0 commit comments

Comments
 (0)