From 67f6e8dc6e05cc2fc22ccfa39ef1a7277a82acfe Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Fri, 9 Jan 2015 06:03:27 +0300 Subject: [PATCH] Misc: complitly replace hooker with sinon --- package.json | 1 - test/cli.js | 40 +++++++++++++-------------- test/reporters/junit.js | 61 +++++++++++++++++++---------------------- 3 files changed, 47 insertions(+), 55 deletions(-) diff --git a/package.json b/package.json index 6fb99cae0..99d755cad 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,6 @@ "browserify": "~7.0.3", "coveralls": "~2.11.1", "has-ansi": "~1.0.0", - "hooker": "~0.2.3", "jshint": "~2.5.0", "mocha": "~2.1.0", "rewire": "~2.1.0", diff --git a/test/cli.js b/test/cli.js index e2c857b96..5a9623d19 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,12 +1,12 @@ -var hooker = require('hooker'); +var path = require('path'); + var sinon = require('sinon'); -var glob = require('glob'); var assert = require('assert'); + +var glob = require('glob'); var hasAnsi = require('has-ansi'); var rewire = require('rewire'); -var path = require('path'); - var cli = rewire('../lib/cli'); var startingDir = process.cwd(); @@ -78,33 +78,29 @@ describe('modules/cli', function() { }); }); - it('should correctly exit if no files specified', function() { - hooker.hook(console, 'error', { - pre: function(message) { - assert.equal(message, 'No input files specified. Try option --help for usage information.'); + it('should correctly exit if no files specified', function(done) { + sinon.stub(console, 'error', function(message) { + assert.equal(message, 'No input files specified. Try option --help for usage information.'); - return hooker.preempt(); - }, - once: true + done(); }); cli({ args: [] }); + + console.error.restore(); }); - it('should exit if no custom config is found', function() { - hooker.hook(console, 'error', { - pre: function(arg1, arg2, arg3) { - assert.equal(arg1, 'Configuration source'); - assert.equal(arg2, 'config.js'); - assert.equal(arg3, 'was not found.'); + it('should exit if no custom config is found', function(done) { + sinon.stub(console, 'error', function(arg1, arg2, arg3) { + assert.equal(arg1, 'Configuration source'); + assert.equal(arg2, 'config.js'); + assert.equal(arg3, 'was not found.'); - process.chdir('../'); + process.chdir('../'); - return hooker.preempt(); - }, - once: true + done(); }); process.chdir('./test/'); @@ -114,6 +110,8 @@ describe('modules/cli', function() { }); assert(typeof result === 'object'); + + console.error.restore(); }); it('should set presets', function() { diff --git a/test/reporters/junit.js b/test/reporters/junit.js index 1bcbccc57..6a641f6ec 100644 --- a/test/reporters/junit.js +++ b/test/reporters/junit.js @@ -1,45 +1,40 @@ -var Checker = require('../../lib/checker'); var assert = require('assert'); -var junit = require('../../lib/reporters/junit'); -var hooker = require('hooker'); +var sinon = require('sinon'); + var parser = require('xml2js').parseString; +var Checker = require('../../lib/checker'); +var junit = require('../../lib/reporters/junit'); + describe('reporters/junit', function() { var checker = new Checker(); checker.registerDefaultRules(); it('should correctly report error results', function(done) { - hooker.hook(process.stdout, 'write', { - pre: function(xml) { - process.nextTick(function() { - parser(xml, {trim: true}, function(err, result) { - if (!err) { - var testsuite = result.testsuite; - - assert(!!testsuite); - assert(testsuite.$.name === 'JSCS'); - assert(testsuite.$.tests === '1'); - assert(testsuite.$.failures === '1'); - - var testcase = testsuite.testcase[0]; - assert(!!testcase); - assert(testcase.$.name === 'input'); - assert(testcase.$.failures === '1'); - - assert(testcase.failure[0].length); - } else { - assert(false, err); - } - - done(); - }); - }); - - return hooker.preempt(); - }, - - once: true + sinon.stub(console, 'log', function(xml) { + parser(xml, {trim: true}, function(err, result) { + if (!err) { + var testsuite = result.testsuite; + + assert(!!testsuite); + assert(testsuite.$.name === 'JSCS'); + assert(testsuite.$.tests === '1'); + assert(testsuite.$.failures === '1'); + + var testcase = testsuite.testcase[0]; + assert(!!testcase); + assert(testcase.$.name === 'input'); + assert(testcase.$.failures === '1'); + + assert(testcase.failure[0].length); + } else { + assert(false, err); + } + + console.log.restore(); + done(); + }); }); checker.configure({ disallowKeywords: ['with'] });