Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit e782eba

Browse files
Sulabh Bistadasilvacontin
Sulabh Bista
authored andcommitted
Adds tests for loading reporters w/ relative/absolute paths (mochajs#2773)
* Adds tests for loading reporters w/ relative/absolute paths * Fixes the test based on CR * Replaces '+' with path.join()
1 parent 8a2053e commit e782eba

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var baseReporter = require('../../../lib/reporters/base');
2+
module.exports = simplereporter;
3+
4+
function simplereporter (runner) {
5+
baseReporter.call(this, runner);
6+
7+
runner.on('suite', function (suite) {
8+
console.log('on(\'suite\') called');
9+
});
10+
11+
runner.on('fail', function (test, err) {
12+
console.log('on(\'fail\') called');
13+
});
14+
15+
runner.on('pass', function (test) {
16+
console.log('on(\'pass\') called');
17+
});
18+
19+
runner.on('test end', function (test, err) {
20+
console.log('on(\'test end\') called');
21+
});
22+
23+
runner.on('end', function () {
24+
console.log('on(\'end\') called');
25+
});
26+
}

test/integration/reporters.spec.js

+27
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,31 @@ describe('reporters', function () {
6060
});
6161
});
6262
});
63+
64+
describe('loader', function () {
65+
it('loads a reporter from a path relative to the current working directory', function (done) {
66+
var reporterAtARelativePath = 'test/integration/fixtures/simple-reporter.js';
67+
68+
var args = ['--reporter=' + reporterAtARelativePath];
69+
70+
run('passing.fixture.js', args, function (err, result) {
71+
assert(!err);
72+
assert.equal(result.code, 0);
73+
done();
74+
});
75+
});
76+
77+
it('loads a reporter from an absolute path', function (done) {
78+
// Generates an absolute path string
79+
var reporterAtAnAbsolutePath = path.join(process.cwd(), 'test/integration/fixtures/simple-reporter.js');
80+
81+
var args = ['--reporter=' + reporterAtAnAbsolutePath];
82+
83+
run('passing.fixture.js', args, function (err, result) {
84+
assert(!err);
85+
assert.equal(result.code, 0);
86+
done();
87+
});
88+
});
89+
});
6390
});

0 commit comments

Comments
 (0)