Skip to content

Commit d892bd7

Browse files
committed
Fix test failures from v5 upgrade
1 parent 809edff commit d892bd7

File tree

3 files changed

+72
-55
lines changed

3 files changed

+72
-55
lines changed

test/helpers/mock-runner.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,52 @@
1-
'use strict';
1+
"use strict"
22

3-
var EventEmitter = require('events').EventEmitter;
4-
var util = require('util');
3+
var EventEmitter = require("events").EventEmitter
4+
var util = require("util")
55

66
// mock test runner
77
function Runner() {
8-
Runner.super_.call(this);
8+
Runner.super_.call(this)
99
}
1010

11-
util.inherits(Runner, EventEmitter);
11+
util.inherits(Runner, EventEmitter)
1212

1313
Runner.prototype.start = function() {
14-
this.emit('start');
15-
};
14+
this.emit("start")
15+
}
1616

1717
Runner.prototype.end = function() {
18-
this.emit('end');
19-
};
18+
this.emit("end")
19+
}
2020

2121
Runner.prototype.startSuite = function(suite) {
22-
this.emit('suite', suite);
23-
};
22+
suite.suites = suite.suites || []
23+
suite.tests = suite.tests || []
24+
25+
if (this._currentSuite) {
26+
suite.parent = this._currentSuite
27+
}
28+
29+
this._currentSuite = suite
30+
this.emit("suite", suite)
31+
}
2432

2533
Runner.prototype.pass = function(test) {
26-
this.emit('pass', test);
27-
this.endTest();
28-
};
34+
this.emit("pass", test)
35+
this.endTest()
36+
}
2937

3038
Runner.prototype.fail = function(test, reason) {
31-
this.emit('fail', test, reason);
32-
this.endTest();
33-
};
39+
this.emit("fail", test, reason)
40+
this.endTest()
41+
}
42+
43+
Runner.prototype.pending = function(test) {
44+
this.emit("pending", test)
45+
this.endTest()
46+
}
3447

3548
Runner.prototype.endTest = function() {
36-
this.emit('end test');
37-
};
49+
this.emit("end test")
50+
}
3851

39-
module.exports = Runner;
52+
module.exports = Runner

test/helpers/mock-test.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
'use strict';
1+
"use strict"
22

33
function Test(fullTitle, title, duration) {
4-
5-
this.title = title;
6-
this.duration = duration;
7-
8-
this.fullTitle = function() {
9-
return fullTitle;
10-
};
11-
12-
this.slow = function() { };
4+
return {
5+
title: title,
6+
duration: duration,
7+
fullTitle: function() {
8+
return fullTitle
9+
},
10+
titlePath: function() {
11+
return [fullTitle]
12+
},
13+
slow: function() {},
14+
}
1315
}
1416

15-
module.exports = Test
17+
module.exports = Test

test/index.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,76 @@ var fs = require('fs');
1010

1111

1212
describe('mocha-circleci-reporter', function() {
13-
13+
1414
var runner;
15-
var file = './test/output/console.xml';
16-
15+
var file = __dirname + '/output/console.xml';
16+
1717
beforeEach(function() {
1818
runner = new Runner();
1919
});
20-
20+
2121
afterEach(function(){
22-
fs.unlinkSync(file);
22+
if (fs.existsSync(file)) {
23+
fs.unlinkSync(file);
24+
}
2325
})
24-
26+
2527
it('should output spec to stdout', function() {
26-
28+
2729
new Reporter(runner, {
28-
reporterOptions: { mochaFile: 'test/output/console.xml' }
30+
reporterOptions: { mochaFile: file }
2931
});
30-
32+
3133
var stdout = testConsole.stdout.inspect();
3234
try{
3335
executeTestRunner();
3436
}
35-
finally{
37+
finally{
3638
stdout.restore();
3739
}
38-
40+
3941
assert(stdout.output[1], '\u001b[0mFoo Bar module\u001b[0m\n');
4042
});
41-
43+
4244
it('should output junit file', function() {
43-
45+
4446
new Reporter(runner, {
45-
reporterOptions: { mochaFile: 'test/output/console.xml' }
47+
reporterOptions: { mochaFile: file }
4648
});
47-
49+
4850
var stdout = testConsole.stdout.inspect();
4951
try{
5052
executeTestRunner();
51-
53+
5254
assert(fs.existsSync(file));
5355
}
54-
finally{
56+
finally{
5557
stdout.restore();
5658
}
5759
});
58-
60+
5961
function executeTestRunner(char){
60-
62+
6163
char = char || '';
6264
runner.start();
6365

6466
runner.startSuite({
6567
title: 'Foo Bar module',
6668
tests: [1, 2]
6769
});
68-
70+
6971
runner.pass(new Test('Foo can weez the juice', 'can weez the juice', 1));
7072
runner.fail(new Test('Bar can narfle the garthog', 'can narfle the garthog', 1), {
7173
message: char + 'expected garthog to be dead' + char
7274
});
73-
75+
7476
runner.startSuite({
7577
title: 'Another suite!',
7678
tests: [1]
7779
});
7880
runner.pass(new Test('Another suite', 'works', 4));
79-
81+
8082
runner.end();
8183
}
82-
83-
});
84+
85+
});

0 commit comments

Comments
 (0)