mocha 3.5.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +134 -0
- package/README.md +14 -14
- package/bin/.eslintrc.yml +3 -0
- package/bin/_mocha +162 -151
- package/bin/mocha +12 -10
- package/bin/options.js +8 -6
- package/browser-entry.js +3 -3
- package/lib/browser/{.eslintrc.yaml → .eslintrc.yml} +0 -0
- package/lib/browser/growl.js +5 -0
- package/lib/context.js +10 -23
- package/lib/interfaces/bdd.js +1 -1
- package/lib/interfaces/common.js +0 -3
- package/lib/mocha.js +23 -1
- package/lib/ms.js +4 -44
- package/lib/reporters/base.js +40 -44
- package/lib/reporters/base.js.orig +498 -0
- package/lib/reporters/json-stream.js +0 -1
- package/lib/reporters/progress.js +7 -5
- package/lib/reporters/xunit.js +21 -6
- package/lib/runnable.js +17 -11
- package/lib/runner.js +42 -31
- package/lib/suite.js +25 -13
- package/lib/test.js +3 -5
- package/lib/utils.js +20 -199
- package/mocha.js +7630 -8884
- package/package.json +37 -34
- package/bower.json +0 -38
- package/lib/browser/debug.js +0 -7
- package/lib/browser/events.js +0 -195
- package/lib/to-iso-string/LICENSE +0 -19
- package/lib/to-iso-string/index.js +0 -37
package/bin/mocha
CHANGED
|
@@ -7,17 +7,17 @@
|
|
|
7
7
|
* when found, before invoking the "real" _mocha(1) executable.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const spawn = require('child_process').spawn;
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const getOptions = require('./options');
|
|
13
|
+
const args = [path.join(__dirname, '_mocha')];
|
|
14
14
|
|
|
15
15
|
// Load mocha.opts into process.argv
|
|
16
16
|
// Must be loaded here to handle node-specific options
|
|
17
17
|
getOptions();
|
|
18
18
|
|
|
19
|
-
process.argv.slice(2).forEach(
|
|
20
|
-
|
|
19
|
+
process.argv.slice(2).forEach(arg => {
|
|
20
|
+
const flag = arg.split('=')[0];
|
|
21
21
|
|
|
22
22
|
switch (flag) {
|
|
23
23
|
case '-d':
|
|
@@ -69,9 +69,11 @@ process.argv.slice(2).forEach(function (arg) {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
const proc = spawn(process.execPath, args, {
|
|
73
|
+
stdio: 'inherit'
|
|
74
|
+
});
|
|
75
|
+
proc.on('exit', (code, signal) => {
|
|
76
|
+
process.on('exit', () => {
|
|
75
77
|
if (signal) {
|
|
76
78
|
process.kill(process.pid, signal);
|
|
77
79
|
} else {
|
|
@@ -81,7 +83,7 @@ proc.on('exit', function (code, signal) {
|
|
|
81
83
|
});
|
|
82
84
|
|
|
83
85
|
// terminate children.
|
|
84
|
-
process.on('SIGINT',
|
|
86
|
+
process.on('SIGINT', () => {
|
|
85
87
|
proc.kill('SIGINT'); // calls runner.abort()
|
|
86
88
|
proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
|
|
87
89
|
});
|
package/bin/options.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Dependencies.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const fs = require('fs');
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Export `getOptions`.
|
|
@@ -17,18 +17,20 @@ module.exports = getOptions;
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
function getOptions () {
|
|
20
|
-
|
|
20
|
+
if (process.argv.length === 3 && (process.argv[2] === '-h' || process.argv[2] === '--help')) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const optsPath = process.argv.indexOf('--opts') === -1
|
|
21
25
|
? 'test/mocha.opts'
|
|
22
26
|
: process.argv[process.argv.indexOf('--opts') + 1];
|
|
23
27
|
|
|
24
28
|
try {
|
|
25
|
-
|
|
29
|
+
const opts = fs.readFileSync(optsPath, 'utf8')
|
|
26
30
|
.replace(/\\\s/g, '%20')
|
|
27
31
|
.split(/\s/)
|
|
28
32
|
.filter(Boolean)
|
|
29
|
-
.map(
|
|
30
|
-
return value.replace(/%20/g, ' ');
|
|
31
|
-
});
|
|
33
|
+
.map(value => value.replace(/%20/g, ' '));
|
|
32
34
|
|
|
33
35
|
process.argv = process.argv
|
|
34
36
|
.slice(0, 2)
|
package/browser-entry.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Shim process.stdout.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
process.stdout = require('browser-stdout')();
|
|
10
|
+
process.stdout = require('browser-stdout')({level: false});
|
|
11
11
|
|
|
12
12
|
var Mocha = require('./lib/mocha');
|
|
13
13
|
|
|
@@ -45,7 +45,7 @@ process.removeListener = function (e, fn) {
|
|
|
45
45
|
} else {
|
|
46
46
|
global.onerror = function () {};
|
|
47
47
|
}
|
|
48
|
-
var i =
|
|
48
|
+
var i = uncaughtExceptionHandlers.indexOf(fn);
|
|
49
49
|
if (i !== -1) {
|
|
50
50
|
uncaughtExceptionHandlers.splice(i, 1);
|
|
51
51
|
}
|
|
@@ -103,7 +103,7 @@ Mocha.Runner.immediately = function (callback) {
|
|
|
103
103
|
* only receive the 'message' attribute of the Error.
|
|
104
104
|
*/
|
|
105
105
|
mocha.throwError = function (err) {
|
|
106
|
-
|
|
106
|
+
uncaughtExceptionHandlers.forEach(function (fn) {
|
|
107
107
|
fn(err);
|
|
108
108
|
});
|
|
109
109
|
throw err;
|
|
File without changes
|
package/lib/context.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var JSON = require('json3');
|
|
8
|
-
|
|
9
3
|
/**
|
|
10
4
|
* Expose `Context`.
|
|
11
5
|
*/
|
|
@@ -35,7 +29,7 @@ Context.prototype.runnable = function (runnable) {
|
|
|
35
29
|
};
|
|
36
30
|
|
|
37
31
|
/**
|
|
38
|
-
* Set test timeout `ms`.
|
|
32
|
+
* Set or get test timeout `ms`.
|
|
39
33
|
*
|
|
40
34
|
* @api private
|
|
41
35
|
* @param {number} ms
|
|
@@ -57,18 +51,24 @@ Context.prototype.timeout = function (ms) {
|
|
|
57
51
|
* @return {Context} self
|
|
58
52
|
*/
|
|
59
53
|
Context.prototype.enableTimeouts = function (enabled) {
|
|
54
|
+
if (!arguments.length) {
|
|
55
|
+
return this.runnable().enableTimeouts();
|
|
56
|
+
}
|
|
60
57
|
this.runnable().enableTimeouts(enabled);
|
|
61
58
|
return this;
|
|
62
59
|
};
|
|
63
60
|
|
|
64
61
|
/**
|
|
65
|
-
* Set test slowness threshold `ms`.
|
|
62
|
+
* Set or get test slowness threshold `ms`.
|
|
66
63
|
*
|
|
67
64
|
* @api private
|
|
68
65
|
* @param {number} ms
|
|
69
66
|
* @return {Context} self
|
|
70
67
|
*/
|
|
71
68
|
Context.prototype.slow = function (ms) {
|
|
69
|
+
if (!arguments.length) {
|
|
70
|
+
return this.runnable().slow();
|
|
71
|
+
}
|
|
72
72
|
this.runnable().slow(ms);
|
|
73
73
|
return this;
|
|
74
74
|
};
|
|
@@ -77,15 +77,14 @@ Context.prototype.slow = function (ms) {
|
|
|
77
77
|
* Mark a test as skipped.
|
|
78
78
|
*
|
|
79
79
|
* @api private
|
|
80
|
-
* @
|
|
80
|
+
* @throws Pending
|
|
81
81
|
*/
|
|
82
82
|
Context.prototype.skip = function () {
|
|
83
83
|
this.runnable().skip();
|
|
84
|
-
return this;
|
|
85
84
|
};
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
|
-
*
|
|
87
|
+
* Set or get a number of allowed retries on failed tests
|
|
89
88
|
*
|
|
90
89
|
* @api private
|
|
91
90
|
* @param {number} n
|
|
@@ -98,15 +97,3 @@ Context.prototype.retries = function (n) {
|
|
|
98
97
|
this.runnable().retries(n);
|
|
99
98
|
return this;
|
|
100
99
|
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Inspect the context void of `._runnable`.
|
|
104
|
-
*
|
|
105
|
-
* @api private
|
|
106
|
-
* @return {string}
|
|
107
|
-
*/
|
|
108
|
-
Context.prototype.inspect = function () {
|
|
109
|
-
return JSON.stringify(this, function (key, val) {
|
|
110
|
-
return key === 'runnable' || key === 'test' ? undefined : val;
|
|
111
|
-
}, 2);
|
|
112
|
-
};
|
package/lib/interfaces/bdd.js
CHANGED
package/lib/interfaces/common.js
CHANGED
|
@@ -74,7 +74,6 @@ module.exports = function (suites, context, mocha) {
|
|
|
74
74
|
* @returns {Suite}
|
|
75
75
|
*/
|
|
76
76
|
only: function only (opts) {
|
|
77
|
-
mocha.options.hasOnly = true;
|
|
78
77
|
opts.isOnly = true;
|
|
79
78
|
return this.create(opts);
|
|
80
79
|
},
|
|
@@ -108,7 +107,6 @@ module.exports = function (suites, context, mocha) {
|
|
|
108
107
|
suites.unshift(suite);
|
|
109
108
|
if (opts.isOnly) {
|
|
110
109
|
suite.parent._onlySuites = suite.parent._onlySuites.concat(suite);
|
|
111
|
-
mocha.options.hasOnly = true;
|
|
112
110
|
}
|
|
113
111
|
if (typeof opts.fn === 'function') {
|
|
114
112
|
opts.fn.call(suite);
|
|
@@ -132,7 +130,6 @@ module.exports = function (suites, context, mocha) {
|
|
|
132
130
|
*/
|
|
133
131
|
only: function (mocha, test) {
|
|
134
132
|
test.parent._onlyTests = test.parent._onlyTests.concat(test);
|
|
135
|
-
mocha.options.hasOnly = true;
|
|
136
133
|
return test;
|
|
137
134
|
},
|
|
138
135
|
|
package/lib/mocha.js
CHANGED
|
@@ -389,6 +389,20 @@ Mocha.prototype.useInlineDiffs = function (inlineDiffs) {
|
|
|
389
389
|
return this;
|
|
390
390
|
};
|
|
391
391
|
|
|
392
|
+
/**
|
|
393
|
+
* Do not show diffs at all.
|
|
394
|
+
*
|
|
395
|
+
* @param {Boolean} hideDiff
|
|
396
|
+
* @return {Mocha}
|
|
397
|
+
* @api public
|
|
398
|
+
* @param {boolean} hideDiff
|
|
399
|
+
* @return {Mocha}
|
|
400
|
+
*/
|
|
401
|
+
Mocha.prototype.hideDiff = function (hideDiff) {
|
|
402
|
+
this.options.hideDiff = hideDiff !== undefined && hideDiff;
|
|
403
|
+
return this;
|
|
404
|
+
};
|
|
405
|
+
|
|
392
406
|
/**
|
|
393
407
|
* Set the timeout in milliseconds.
|
|
394
408
|
*
|
|
@@ -505,6 +519,14 @@ Mocha.prototype.forbidPending = function () {
|
|
|
505
519
|
/**
|
|
506
520
|
* Run tests and invoke `fn()` when complete.
|
|
507
521
|
*
|
|
522
|
+
* Note that `loadFiles` relies on Node's `require` to execute
|
|
523
|
+
* the test interface functions and will be subject to the
|
|
524
|
+
* cache - if the files are already in the `require` cache,
|
|
525
|
+
* they will effectively be skipped. Therefore, to run tests
|
|
526
|
+
* multiple times or to run tests in files that are already
|
|
527
|
+
* in the `require` cache, make sure to clear them from the
|
|
528
|
+
* cache first in whichever manner best suits your needs.
|
|
529
|
+
*
|
|
508
530
|
* @api public
|
|
509
531
|
* @param {Function} fn
|
|
510
532
|
* @return {Runner}
|
|
@@ -520,7 +542,6 @@ Mocha.prototype.run = function (fn) {
|
|
|
520
542
|
var reporter = new this._reporter(runner, options);
|
|
521
543
|
runner.ignoreLeaks = options.ignoreLeaks !== false;
|
|
522
544
|
runner.fullStackTrace = options.fullStackTrace;
|
|
523
|
-
runner.hasOnly = options.hasOnly;
|
|
524
545
|
runner.asyncOnly = options.asyncOnly;
|
|
525
546
|
runner.allowUncaught = options.allowUncaught;
|
|
526
547
|
runner.forbidOnly = options.forbidOnly;
|
|
@@ -538,6 +559,7 @@ Mocha.prototype.run = function (fn) {
|
|
|
538
559
|
exports.reporters.Base.useColors = options.useColors;
|
|
539
560
|
}
|
|
540
561
|
exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
|
|
562
|
+
exports.reporters.Base.hideDiff = options.hideDiff;
|
|
541
563
|
|
|
542
564
|
function done (failures) {
|
|
543
565
|
if (reporter.done) {
|
package/lib/ms.js
CHANGED
|
@@ -13,22 +13,15 @@ var y = d * 365.25;
|
|
|
13
13
|
/**
|
|
14
14
|
* Parse or format the given `val`.
|
|
15
15
|
*
|
|
16
|
-
* Options:
|
|
17
|
-
*
|
|
18
|
-
* - `long` verbose formatting [false]
|
|
19
|
-
*
|
|
20
16
|
* @api public
|
|
21
17
|
* @param {string|number} val
|
|
22
|
-
* @param {Object} options
|
|
23
18
|
* @return {string|number}
|
|
24
19
|
*/
|
|
25
|
-
module.exports = function (val
|
|
26
|
-
options = options || {};
|
|
20
|
+
module.exports = function (val) {
|
|
27
21
|
if (typeof val === 'string') {
|
|
28
22
|
return parse(val);
|
|
29
23
|
}
|
|
30
|
-
|
|
31
|
-
return options['long'] ? longFormat(val) : shortFormat(val);
|
|
24
|
+
return format(val);
|
|
32
25
|
};
|
|
33
26
|
|
|
34
27
|
/**
|
|
@@ -74,13 +67,13 @@ function parse (str) {
|
|
|
74
67
|
}
|
|
75
68
|
|
|
76
69
|
/**
|
|
77
|
-
*
|
|
70
|
+
* Format for `ms`.
|
|
78
71
|
*
|
|
79
72
|
* @api private
|
|
80
73
|
* @param {number} ms
|
|
81
74
|
* @return {string}
|
|
82
75
|
*/
|
|
83
|
-
function
|
|
76
|
+
function format (ms) {
|
|
84
77
|
if (ms >= d) {
|
|
85
78
|
return Math.round(ms / d) + 'd';
|
|
86
79
|
}
|
|
@@ -95,36 +88,3 @@ function shortFormat (ms) {
|
|
|
95
88
|
}
|
|
96
89
|
return ms + 'ms';
|
|
97
90
|
}
|
|
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
|
-
}
|
package/lib/reporters/base.js
CHANGED
|
@@ -120,8 +120,8 @@ exports.window = {
|
|
|
120
120
|
|
|
121
121
|
if (isatty) {
|
|
122
122
|
exports.window.width = process.stdout.getWindowSize
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
? process.stdout.getWindowSize(1)[0]
|
|
124
|
+
: tty.getWindowSize()[1];
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/**
|
|
@@ -155,6 +155,17 @@ exports.cursor = {
|
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
+
function showDiff (err) {
|
|
159
|
+
return err && err.showDiff !== false && sameType(err.actual, err.expected) && err.expected !== undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function stringifyDiffObjs (err) {
|
|
163
|
+
if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
|
|
164
|
+
err.actual = utils.stringify(err.actual);
|
|
165
|
+
err.expected = utils.stringify(err.expected);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
158
169
|
/**
|
|
159
170
|
* Output the given `failures` as a list.
|
|
160
171
|
*
|
|
@@ -183,9 +194,6 @@ exports.list = function (failures) {
|
|
|
183
194
|
}
|
|
184
195
|
var stack = err.stack || message;
|
|
185
196
|
var index = message ? stack.indexOf(message) : -1;
|
|
186
|
-
var actual = err.actual;
|
|
187
|
-
var expected = err.expected;
|
|
188
|
-
var escape = true;
|
|
189
197
|
|
|
190
198
|
if (index === -1) {
|
|
191
199
|
msg = message;
|
|
@@ -201,28 +209,35 @@ exports.list = function (failures) {
|
|
|
201
209
|
msg = 'Uncaught ' + msg;
|
|
202
210
|
}
|
|
203
211
|
// explicitly show diff
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
if (!(utils.isString(actual) && utils.isString(expected))) {
|
|
207
|
-
err.actual = actual = utils.stringify(actual);
|
|
208
|
-
err.expected = expected = utils.stringify(expected);
|
|
209
|
-
}
|
|
210
|
-
|
|
212
|
+
if (!exports.hideDiff && showDiff(err)) {
|
|
213
|
+
stringifyDiffObjs(err);
|
|
211
214
|
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
|
|
212
215
|
var match = message.match(/^([^:]+): expected/);
|
|
213
216
|
msg = '\n ' + color('error message', match ? match[1] : msg);
|
|
214
217
|
|
|
215
218
|
if (exports.inlineDiffs) {
|
|
216
|
-
msg += inlineDiff(err
|
|
219
|
+
msg += inlineDiff(err);
|
|
217
220
|
} else {
|
|
218
|
-
msg += unifiedDiff(err
|
|
221
|
+
msg += unifiedDiff(err);
|
|
219
222
|
}
|
|
220
223
|
}
|
|
221
224
|
|
|
222
225
|
// indent stack trace
|
|
223
226
|
stack = stack.replace(/^/gm, ' ');
|
|
224
227
|
|
|
225
|
-
|
|
228
|
+
// indented test title
|
|
229
|
+
var testTitle = '';
|
|
230
|
+
test.titlePath().forEach(function (str, index) {
|
|
231
|
+
if (index !== 0) {
|
|
232
|
+
testTitle += '\n ';
|
|
233
|
+
}
|
|
234
|
+
for (var i = 0; i < index; i++) {
|
|
235
|
+
testTitle += ' ';
|
|
236
|
+
}
|
|
237
|
+
testTitle += str;
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
console.log(fmt, (i + 1), testTitle, msg, stack);
|
|
226
241
|
});
|
|
227
242
|
};
|
|
228
243
|
|
|
@@ -280,6 +295,9 @@ function Base (runner) {
|
|
|
280
295
|
runner.on('fail', function (test, err) {
|
|
281
296
|
stats.failures = stats.failures || 0;
|
|
282
297
|
stats.failures++;
|
|
298
|
+
if (showDiff(err)) {
|
|
299
|
+
stringifyDiffObjs(err);
|
|
300
|
+
}
|
|
283
301
|
test.err = err;
|
|
284
302
|
failures.push(test);
|
|
285
303
|
});
|
|
@@ -354,11 +372,10 @@ function pad (str, len) {
|
|
|
354
372
|
*
|
|
355
373
|
* @api private
|
|
356
374
|
* @param {Error} err with actual/expected
|
|
357
|
-
* @param {boolean} escape
|
|
358
375
|
* @return {string} Diff
|
|
359
376
|
*/
|
|
360
|
-
function inlineDiff (err
|
|
361
|
-
var msg = errorDiff(err
|
|
377
|
+
function inlineDiff (err) {
|
|
378
|
+
var msg = errorDiff(err);
|
|
362
379
|
|
|
363
380
|
// linenos
|
|
364
381
|
var lines = msg.split('\n');
|
|
@@ -388,15 +405,11 @@ function inlineDiff (err, escape) {
|
|
|
388
405
|
*
|
|
389
406
|
* @api private
|
|
390
407
|
* @param {Error} err with actual/expected
|
|
391
|
-
* @param {boolean} escape
|
|
392
408
|
* @return {string} The diff.
|
|
393
409
|
*/
|
|
394
|
-
function unifiedDiff (err
|
|
410
|
+
function unifiedDiff (err) {
|
|
395
411
|
var indent = ' ';
|
|
396
412
|
function cleanUp (line) {
|
|
397
|
-
if (escape) {
|
|
398
|
-
line = escapeInvisibles(line);
|
|
399
|
-
}
|
|
400
413
|
if (line[0] === '+') {
|
|
401
414
|
return indent + colorLines('diff added', line);
|
|
402
415
|
}
|
|
@@ -404,7 +417,7 @@ function unifiedDiff (err, escape) {
|
|
|
404
417
|
return indent + colorLines('diff removed', line);
|
|
405
418
|
}
|
|
406
419
|
if (line.match(/@@/)) {
|
|
407
|
-
return
|
|
420
|
+
return '--';
|
|
408
421
|
}
|
|
409
422
|
if (line.match(/\\ No newline/)) {
|
|
410
423
|
return null;
|
|
@@ -415,7 +428,7 @@ function unifiedDiff (err, escape) {
|
|
|
415
428
|
return typeof line !== 'undefined' && line !== null;
|
|
416
429
|
}
|
|
417
430
|
var msg = diff.createPatch('string', err.actual, err.expected);
|
|
418
|
-
var lines = msg.split('\n').splice(
|
|
431
|
+
var lines = msg.split('\n').splice(5);
|
|
419
432
|
return '\n ' +
|
|
420
433
|
colorLines('diff added', '+ expected') + ' ' +
|
|
421
434
|
colorLines('diff removed', '- actual') +
|
|
@@ -428,14 +441,10 @@ function unifiedDiff (err, escape) {
|
|
|
428
441
|
*
|
|
429
442
|
* @api private
|
|
430
443
|
* @param {Error} err
|
|
431
|
-
* @param {string} type
|
|
432
|
-
* @param {boolean} escape
|
|
433
444
|
* @return {string}
|
|
434
445
|
*/
|
|
435
|
-
function errorDiff (err
|
|
436
|
-
|
|
437
|
-
var expected = escape ? escapeInvisibles(err.expected) : err.expected;
|
|
438
|
-
return diff['diff' + type](actual, expected).map(function (str) {
|
|
446
|
+
function errorDiff (err) {
|
|
447
|
+
return diff.diffWordsWithSpace(err.actual, err.expected).map(function (str) {
|
|
439
448
|
if (str.added) {
|
|
440
449
|
return colorLines('diff added', str.value);
|
|
441
450
|
}
|
|
@@ -446,19 +455,6 @@ function errorDiff (err, type, escape) {
|
|
|
446
455
|
}).join('');
|
|
447
456
|
}
|
|
448
457
|
|
|
449
|
-
/**
|
|
450
|
-
* Returns a string with all invisible characters in plain text
|
|
451
|
-
*
|
|
452
|
-
* @api private
|
|
453
|
-
* @param {string} line
|
|
454
|
-
* @return {string}
|
|
455
|
-
*/
|
|
456
|
-
function escapeInvisibles (line) {
|
|
457
|
-
return line.replace(/\t/g, '<tab>')
|
|
458
|
-
.replace(/\r/g, '<CR>')
|
|
459
|
-
.replace(/\n/g, '<LF>\n');
|
|
460
|
-
}
|
|
461
|
-
|
|
462
458
|
/**
|
|
463
459
|
* Color lines for `str`, using the color `name`.
|
|
464
460
|
*
|