mocha 2.2.5 → 2.3.3
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/HISTORY.md +1034 -0
- package/bin/.eslintrc +3 -0
- package/bin/_mocha +12 -15
- package/bin/mocha +3 -10
- package/bin/options.js +6 -5
- package/lib/browser/debug.js +3 -3
- package/lib/browser/events.js +42 -26
- package/lib/browser/progress.js +37 -45
- package/lib/browser/tty.js +4 -5
- package/lib/context.js +26 -32
- package/lib/hook.js +5 -7
- package/lib/interfaces/bdd.js +21 -26
- package/lib/interfaces/common.js +33 -15
- package/lib/interfaces/exports.js +7 -7
- package/lib/interfaces/qunit.js +16 -17
- package/lib/interfaces/tdd.js +24 -28
- package/lib/mocha.js +140 -99
- package/lib/ms.js +43 -24
- package/lib/pending.js +2 -3
- package/lib/reporters/base.js +159 -138
- package/lib/reporters/doc.js +13 -13
- package/lib/reporters/dot.js +23 -19
- package/lib/reporters/html-cov.js +25 -19
- package/lib/reporters/html.js +130 -91
- package/lib/reporters/index.js +19 -17
- package/lib/reporters/json-cov.js +39 -41
- package/lib/reporters/json-stream.js +14 -17
- package/lib/reporters/json.js +16 -19
- package/lib/reporters/landing.js +20 -24
- package/lib/reporters/list.js +14 -16
- package/lib/reporters/markdown.js +17 -20
- package/lib/reporters/min.js +4 -5
- package/lib/reporters/nyan.js +49 -48
- package/lib/reporters/progress.js +20 -23
- package/lib/reporters/spec.js +23 -22
- package/lib/reporters/tap.js +15 -19
- package/lib/reporters/xunit.js +83 -63
- package/lib/runnable.js +134 -94
- package/lib/runner.js +291 -167
- package/lib/suite.js +105 -95
- package/lib/template.html +1 -1
- package/lib/test.js +3 -4
- package/lib/utils.js +227 -199
- package/mocha.css +35 -0
- package/mocha.js +8324 -2471
- package/package.json +250 -10
- package/lib/browser/escape-string-regexp.js +0 -11
- package/lib/browser/fs.js +0 -0
- package/lib/browser/glob.js +0 -0
- package/lib/browser/path.js +0 -0
package/lib/interfaces/bdd.js
CHANGED
|
@@ -2,33 +2,31 @@
|
|
|
2
2
|
* Module dependencies.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var Suite = require('../suite')
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
, escapeRe = require('escape-string-regexp');
|
|
5
|
+
var Suite = require('../suite');
|
|
6
|
+
var Test = require('../test');
|
|
7
|
+
var escapeRe = require('escape-string-regexp');
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* BDD-style interface:
|
|
12
11
|
*
|
|
13
|
-
* describe('Array', function(){
|
|
14
|
-
* describe('#indexOf()', function(){
|
|
15
|
-
* it('should return -1 when not present', function(){
|
|
16
|
-
*
|
|
12
|
+
* describe('Array', function() {
|
|
13
|
+
* describe('#indexOf()', function() {
|
|
14
|
+
* it('should return -1 when not present', function() {
|
|
15
|
+
* // ...
|
|
17
16
|
* });
|
|
18
17
|
*
|
|
19
|
-
* it('should return the index when present', function(){
|
|
20
|
-
*
|
|
18
|
+
* it('should return the index when present', function() {
|
|
19
|
+
* // ...
|
|
21
20
|
* });
|
|
22
21
|
* });
|
|
23
22
|
* });
|
|
24
23
|
*
|
|
24
|
+
* @param {Suite} suite Root suite.
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
|
-
module.exports = function(suite){
|
|
26
|
+
module.exports = function(suite) {
|
|
28
27
|
var suites = [suite];
|
|
29
28
|
|
|
30
|
-
suite.on('pre-require', function(context, file, mocha){
|
|
31
|
-
|
|
29
|
+
suite.on('pre-require', function(context, file, mocha) {
|
|
32
30
|
var common = require('./common')(suites, context);
|
|
33
31
|
|
|
34
32
|
context.before = common.before;
|
|
@@ -42,7 +40,7 @@ module.exports = function(suite){
|
|
|
42
40
|
* and/or tests.
|
|
43
41
|
*/
|
|
44
42
|
|
|
45
|
-
context.describe = context.context = function(title, fn){
|
|
43
|
+
context.describe = context.context = function(title, fn) {
|
|
46
44
|
var suite = Suite.create(suites[0], title);
|
|
47
45
|
suite.file = file;
|
|
48
46
|
suites.unshift(suite);
|
|
@@ -55,9 +53,7 @@ module.exports = function(suite){
|
|
|
55
53
|
* Pending describe.
|
|
56
54
|
*/
|
|
57
55
|
|
|
58
|
-
context.xdescribe =
|
|
59
|
-
context.xcontext =
|
|
60
|
-
context.describe.skip = function(title, fn){
|
|
56
|
+
context.xdescribe = context.xcontext = context.describe.skip = function(title, fn) {
|
|
61
57
|
var suite = Suite.create(suites[0], title);
|
|
62
58
|
suite.pending = true;
|
|
63
59
|
suites.unshift(suite);
|
|
@@ -69,7 +65,7 @@ module.exports = function(suite){
|
|
|
69
65
|
* Exclusive suite.
|
|
70
66
|
*/
|
|
71
67
|
|
|
72
|
-
context.describe.only = function(title, fn){
|
|
68
|
+
context.describe.only = function(title, fn) {
|
|
73
69
|
var suite = context.describe(title, fn);
|
|
74
70
|
mocha.grep(suite.fullTitle());
|
|
75
71
|
return suite;
|
|
@@ -81,9 +77,11 @@ module.exports = function(suite){
|
|
|
81
77
|
* acting as a thunk.
|
|
82
78
|
*/
|
|
83
79
|
|
|
84
|
-
context.it = context.specify = function(title, fn){
|
|
80
|
+
context.it = context.specify = function(title, fn) {
|
|
85
81
|
var suite = suites[0];
|
|
86
|
-
if (suite.pending)
|
|
82
|
+
if (suite.pending) {
|
|
83
|
+
fn = null;
|
|
84
|
+
}
|
|
87
85
|
var test = new Test(title, fn);
|
|
88
86
|
test.file = file;
|
|
89
87
|
suite.addTest(test);
|
|
@@ -94,7 +92,7 @@ module.exports = function(suite){
|
|
|
94
92
|
* Exclusive test-case.
|
|
95
93
|
*/
|
|
96
94
|
|
|
97
|
-
context.it.only = function(title, fn){
|
|
95
|
+
context.it.only = function(title, fn) {
|
|
98
96
|
var test = context.it(title, fn);
|
|
99
97
|
var reString = '^' + escapeRe(test.fullTitle()) + '$';
|
|
100
98
|
mocha.grep(new RegExp(reString));
|
|
@@ -105,11 +103,8 @@ module.exports = function(suite){
|
|
|
105
103
|
* Pending test case.
|
|
106
104
|
*/
|
|
107
105
|
|
|
108
|
-
context.xit =
|
|
109
|
-
context.xspecify =
|
|
110
|
-
context.it.skip = function(title){
|
|
106
|
+
context.xit = context.xspecify = context.it.skip = function(title) {
|
|
111
107
|
context.it(title);
|
|
112
108
|
};
|
|
113
|
-
|
|
114
109
|
});
|
|
115
110
|
};
|
package/lib/interfaces/common.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Functions common to more than one interface
|
|
3
|
-
* @module lib/interfaces/common
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
1
|
'use strict';
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Functions common to more than one interface.
|
|
5
|
+
*
|
|
6
|
+
* @param {Suite[]} suites
|
|
7
|
+
* @param {Context} context
|
|
8
|
+
* @return {Object} An object containing common functions.
|
|
9
|
+
*/
|
|
10
|
+
module.exports = function(suites, context) {
|
|
10
11
|
return {
|
|
11
12
|
/**
|
|
12
|
-
* This is only present if flag --delay is passed into Mocha.
|
|
13
|
-
* root suite execution.
|
|
13
|
+
* This is only present if flag --delay is passed into Mocha. It triggers
|
|
14
|
+
* root suite execution.
|
|
15
|
+
*
|
|
16
|
+
* @param {Suite} suite The root wuite.
|
|
17
|
+
* @return {Function} A function which runs the root suite
|
|
14
18
|
*/
|
|
15
19
|
runWithSuite: function runWithSuite(suite) {
|
|
16
20
|
return function run() {
|
|
@@ -20,39 +24,53 @@ module.exports = function (suites, context) {
|
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Execute before running tests.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} name
|
|
29
|
+
* @param {Function} fn
|
|
23
30
|
*/
|
|
24
|
-
before: function
|
|
31
|
+
before: function(name, fn) {
|
|
25
32
|
suites[0].beforeAll(name, fn);
|
|
26
33
|
},
|
|
27
34
|
|
|
28
35
|
/**
|
|
29
36
|
* Execute after running tests.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} name
|
|
39
|
+
* @param {Function} fn
|
|
30
40
|
*/
|
|
31
|
-
after: function
|
|
41
|
+
after: function(name, fn) {
|
|
32
42
|
suites[0].afterAll(name, fn);
|
|
33
43
|
},
|
|
34
44
|
|
|
35
45
|
/**
|
|
36
46
|
* Execute before each test case.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} name
|
|
49
|
+
* @param {Function} fn
|
|
37
50
|
*/
|
|
38
|
-
beforeEach: function
|
|
51
|
+
beforeEach: function(name, fn) {
|
|
39
52
|
suites[0].beforeEach(name, fn);
|
|
40
53
|
},
|
|
41
54
|
|
|
42
55
|
/**
|
|
43
56
|
* Execute after each test case.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} name
|
|
59
|
+
* @param {Function} fn
|
|
44
60
|
*/
|
|
45
|
-
afterEach: function
|
|
61
|
+
afterEach: function(name, fn) {
|
|
46
62
|
suites[0].afterEach(name, fn);
|
|
47
63
|
},
|
|
48
64
|
|
|
49
65
|
test: {
|
|
50
66
|
/**
|
|
51
67
|
* Pending test case.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} title
|
|
52
70
|
*/
|
|
53
|
-
skip: function
|
|
71
|
+
skip: function(title) {
|
|
54
72
|
context.test(title);
|
|
55
73
|
}
|
|
56
74
|
}
|
|
57
|
-
}
|
|
75
|
+
};
|
|
58
76
|
};
|
|
@@ -2,27 +2,27 @@
|
|
|
2
2
|
* Module dependencies.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var Suite = require('../suite')
|
|
6
|
-
|
|
5
|
+
var Suite = require('../suite');
|
|
6
|
+
var Test = require('../test');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* TDD-style interface:
|
|
10
10
|
*
|
|
11
11
|
* exports.Array = {
|
|
12
12
|
* '#indexOf()': {
|
|
13
|
-
* 'should return -1 when the value is not present': function(){
|
|
13
|
+
* 'should return -1 when the value is not present': function() {
|
|
14
14
|
*
|
|
15
15
|
* },
|
|
16
16
|
*
|
|
17
|
-
* 'should return the correct index when the value is present': function(){
|
|
17
|
+
* 'should return the correct index when the value is present': function() {
|
|
18
18
|
*
|
|
19
19
|
* }
|
|
20
20
|
* }
|
|
21
21
|
* };
|
|
22
22
|
*
|
|
23
|
+
* @param {Suite} suite Root suite.
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
-
module.exports = function(suite){
|
|
25
|
+
module.exports = function(suite) {
|
|
26
26
|
var suites = [suite];
|
|
27
27
|
|
|
28
28
|
suite.on('require', visit);
|
|
@@ -30,7 +30,7 @@ module.exports = function(suite){
|
|
|
30
30
|
function visit(obj, file) {
|
|
31
31
|
var suite;
|
|
32
32
|
for (var key in obj) {
|
|
33
|
-
if (
|
|
33
|
+
if (typeof obj[key] === 'function') {
|
|
34
34
|
var fn = obj[key];
|
|
35
35
|
switch (key) {
|
|
36
36
|
case 'before':
|
package/lib/interfaces/qunit.js
CHANGED
|
@@ -2,22 +2,21 @@
|
|
|
2
2
|
* Module dependencies.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var Suite = require('../suite')
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
, utils = require('../utils');
|
|
5
|
+
var Suite = require('../suite');
|
|
6
|
+
var Test = require('../test');
|
|
7
|
+
var escapeRe = require('escape-string-regexp');
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* QUnit-style interface:
|
|
12
11
|
*
|
|
13
12
|
* suite('Array');
|
|
14
13
|
*
|
|
15
|
-
* test('#length', function(){
|
|
14
|
+
* test('#length', function() {
|
|
16
15
|
* var arr = [1,2,3];
|
|
17
16
|
* ok(arr.length == 3);
|
|
18
17
|
* });
|
|
19
18
|
*
|
|
20
|
-
* test('#indexOf()', function(){
|
|
19
|
+
* test('#indexOf()', function() {
|
|
21
20
|
* var arr = [1,2,3];
|
|
22
21
|
* ok(arr.indexOf(1) == 0);
|
|
23
22
|
* ok(arr.indexOf(2) == 1);
|
|
@@ -26,17 +25,16 @@ var Suite = require('../suite')
|
|
|
26
25
|
*
|
|
27
26
|
* suite('String');
|
|
28
27
|
*
|
|
29
|
-
* test('#length', function(){
|
|
28
|
+
* test('#length', function() {
|
|
30
29
|
* ok('foo'.length == 3);
|
|
31
30
|
* });
|
|
32
31
|
*
|
|
32
|
+
* @param {Suite} suite Root suite.
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
module.exports = function(suite){
|
|
34
|
+
module.exports = function(suite) {
|
|
36
35
|
var suites = [suite];
|
|
37
36
|
|
|
38
|
-
suite.on('pre-require', function(context, file, mocha){
|
|
39
|
-
|
|
37
|
+
suite.on('pre-require', function(context, file, mocha) {
|
|
40
38
|
var common = require('./common')(suites, context);
|
|
41
39
|
|
|
42
40
|
context.before = common.before;
|
|
@@ -48,8 +46,10 @@ module.exports = function(suite){
|
|
|
48
46
|
* Describe a "suite" with the given `title`.
|
|
49
47
|
*/
|
|
50
48
|
|
|
51
|
-
context.suite = function(title){
|
|
52
|
-
if (suites.length > 1)
|
|
49
|
+
context.suite = function(title) {
|
|
50
|
+
if (suites.length > 1) {
|
|
51
|
+
suites.shift();
|
|
52
|
+
}
|
|
53
53
|
var suite = Suite.create(suites[0], title);
|
|
54
54
|
suite.file = file;
|
|
55
55
|
suites.unshift(suite);
|
|
@@ -60,7 +60,7 @@ module.exports = function(suite){
|
|
|
60
60
|
* Exclusive test-case.
|
|
61
61
|
*/
|
|
62
62
|
|
|
63
|
-
context.suite.only = function(title, fn){
|
|
63
|
+
context.suite.only = function(title, fn) {
|
|
64
64
|
var suite = context.suite(title, fn);
|
|
65
65
|
mocha.grep(suite.fullTitle());
|
|
66
66
|
};
|
|
@@ -71,7 +71,7 @@ module.exports = function(suite){
|
|
|
71
71
|
* acting as a thunk.
|
|
72
72
|
*/
|
|
73
73
|
|
|
74
|
-
context.test = function(title, fn){
|
|
74
|
+
context.test = function(title, fn) {
|
|
75
75
|
var test = new Test(title, fn);
|
|
76
76
|
test.file = file;
|
|
77
77
|
suites[0].addTest(test);
|
|
@@ -82,13 +82,12 @@ module.exports = function(suite){
|
|
|
82
82
|
* Exclusive test-case.
|
|
83
83
|
*/
|
|
84
84
|
|
|
85
|
-
context.test.only = function(title, fn){
|
|
85
|
+
context.test.only = function(title, fn) {
|
|
86
86
|
var test = context.test(title, fn);
|
|
87
87
|
var reString = '^' + escapeRe(test.fullTitle()) + '$';
|
|
88
88
|
mocha.grep(new RegExp(reString));
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
context.test.skip = common.test.skip;
|
|
92
|
-
|
|
93
92
|
});
|
|
94
93
|
};
|
package/lib/interfaces/tdd.js
CHANGED
|
@@ -2,41 +2,39 @@
|
|
|
2
2
|
* Module dependencies.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var Suite = require('../suite')
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
, utils = require('../utils');
|
|
5
|
+
var Suite = require('../suite');
|
|
6
|
+
var Test = require('../test');
|
|
7
|
+
var escapeRe = require('escape-string-regexp');
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* TDD-style interface:
|
|
12
11
|
*
|
|
13
|
-
* suite('Array', function(){
|
|
14
|
-
* suite('#indexOf()', function(){
|
|
15
|
-
* suiteSetup(function(){
|
|
12
|
+
* suite('Array', function() {
|
|
13
|
+
* suite('#indexOf()', function() {
|
|
14
|
+
* suiteSetup(function() {
|
|
16
15
|
*
|
|
17
16
|
* });
|
|
18
17
|
*
|
|
19
|
-
* test('should return -1 when not present', function(){
|
|
18
|
+
* test('should return -1 when not present', function() {
|
|
20
19
|
*
|
|
21
20
|
* });
|
|
22
21
|
*
|
|
23
|
-
* test('should return the index when present', function(){
|
|
22
|
+
* test('should return the index when present', function() {
|
|
24
23
|
*
|
|
25
24
|
* });
|
|
26
25
|
*
|
|
27
|
-
* suiteTeardown(function(){
|
|
26
|
+
* suiteTeardown(function() {
|
|
28
27
|
*
|
|
29
28
|
* });
|
|
30
29
|
* });
|
|
31
30
|
* });
|
|
32
31
|
*
|
|
32
|
+
* @param {Suite} suite Root suite.
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
module.exports = function(suite){
|
|
34
|
+
module.exports = function(suite) {
|
|
36
35
|
var suites = [suite];
|
|
37
36
|
|
|
38
|
-
suite.on('pre-require', function(context, file, mocha){
|
|
39
|
-
|
|
37
|
+
suite.on('pre-require', function(context, file, mocha) {
|
|
40
38
|
var common = require('./common')(suites, context);
|
|
41
39
|
|
|
42
40
|
context.setup = common.beforeEach;
|
|
@@ -44,13 +42,12 @@ module.exports = function(suite){
|
|
|
44
42
|
context.suiteSetup = common.before;
|
|
45
43
|
context.suiteTeardown = common.after;
|
|
46
44
|
context.run = mocha.options.delay && common.runWithSuite(suite);
|
|
45
|
+
|
|
47
46
|
/**
|
|
48
|
-
* Describe a "suite" with the given `title`
|
|
49
|
-
*
|
|
50
|
-
* and/or tests.
|
|
47
|
+
* Describe a "suite" with the given `title` and callback `fn` containing
|
|
48
|
+
* nested suites and/or tests.
|
|
51
49
|
*/
|
|
52
|
-
|
|
53
|
-
context.suite = function(title, fn){
|
|
50
|
+
context.suite = function(title, fn) {
|
|
54
51
|
var suite = Suite.create(suites[0], title);
|
|
55
52
|
suite.file = file;
|
|
56
53
|
suites.unshift(suite);
|
|
@@ -73,21 +70,20 @@ module.exports = function(suite){
|
|
|
73
70
|
/**
|
|
74
71
|
* Exclusive test-case.
|
|
75
72
|
*/
|
|
76
|
-
|
|
77
|
-
context.suite.only = function(title, fn){
|
|
73
|
+
context.suite.only = function(title, fn) {
|
|
78
74
|
var suite = context.suite(title, fn);
|
|
79
75
|
mocha.grep(suite.fullTitle());
|
|
80
76
|
};
|
|
81
77
|
|
|
82
78
|
/**
|
|
83
|
-
* Describe a specification or test-case
|
|
84
|
-
*
|
|
85
|
-
* acting as a thunk.
|
|
79
|
+
* Describe a specification or test-case with the given `title` and
|
|
80
|
+
* callback `fn` acting as a thunk.
|
|
86
81
|
*/
|
|
87
|
-
|
|
88
|
-
context.test = function(title, fn){
|
|
82
|
+
context.test = function(title, fn) {
|
|
89
83
|
var suite = suites[0];
|
|
90
|
-
if (suite.pending)
|
|
84
|
+
if (suite.pending) {
|
|
85
|
+
fn = null;
|
|
86
|
+
}
|
|
91
87
|
var test = new Test(title, fn);
|
|
92
88
|
test.file = file;
|
|
93
89
|
suite.addTest(test);
|
|
@@ -98,7 +94,7 @@ module.exports = function(suite){
|
|
|
98
94
|
* Exclusive test-case.
|
|
99
95
|
*/
|
|
100
96
|
|
|
101
|
-
context.test.only = function(title, fn){
|
|
97
|
+
context.test.only = function(title, fn) {
|
|
102
98
|
var test = context.test(title, fn);
|
|
103
99
|
var reString = '^' + escapeRe(test.fullTitle()) + '$';
|
|
104
100
|
mocha.grep(new RegExp(reString));
|