From 0a93024b475e58e75c5def6b2f5228bd363874de Mon Sep 17 00:00:00 2001 From: Sulabh Bista Date: Mon, 24 Apr 2017 01:45:04 -0700 Subject: [PATCH] Adds tests for loading reporters w/ relative/absolute paths (#2773) * Adds tests for loading reporters w/ relative/absolute paths * Fixes the test based on CR * Replaces '+' with path.join() --- test/integration/fixtures/simple-reporter.js | 26 +++++++++++++++++++ test/integration/reporters.spec.js | 27 ++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 test/integration/fixtures/simple-reporter.js diff --git a/test/integration/fixtures/simple-reporter.js b/test/integration/fixtures/simple-reporter.js new file mode 100644 index 0000000000..c2b4e53cd7 --- /dev/null +++ b/test/integration/fixtures/simple-reporter.js @@ -0,0 +1,26 @@ +var baseReporter = require('../../../lib/reporters/base'); +module.exports = simplereporter; + +function simplereporter (runner) { + baseReporter.call(this, runner); + + runner.on('suite', function (suite) { + console.log('on(\'suite\') called'); + }); + + runner.on('fail', function (test, err) { + console.log('on(\'fail\') called'); + }); + + runner.on('pass', function (test) { + console.log('on(\'pass\') called'); + }); + + runner.on('test end', function (test, err) { + console.log('on(\'test end\') called'); + }); + + runner.on('end', function () { + console.log('on(\'end\') called'); + }); +} diff --git a/test/integration/reporters.spec.js b/test/integration/reporters.spec.js index 5cfee57037..15b7e6533b 100644 --- a/test/integration/reporters.spec.js +++ b/test/integration/reporters.spec.js @@ -60,4 +60,31 @@ describe('reporters', function () { }); }); }); + + describe('loader', function () { + it('loads a reporter from a path relative to the current working directory', function (done) { + var reporterAtARelativePath = 'test/integration/fixtures/simple-reporter.js'; + + var args = ['--reporter=' + reporterAtARelativePath]; + + run('passing.fixture.js', args, function (err, result) { + assert(!err); + assert.equal(result.code, 0); + done(); + }); + }); + + it('loads a reporter from an absolute path', function (done) { + // Generates an absolute path string + var reporterAtAnAbsolutePath = path.join(process.cwd(), 'test/integration/fixtures/simple-reporter.js'); + + var args = ['--reporter=' + reporterAtAnAbsolutePath]; + + run('passing.fixture.js', args, function (err, result) { + assert(!err); + assert.equal(result.code, 0); + done(); + }); + }); + }); });