Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Misc: complitly replace hooker with sinon
Browse files Browse the repository at this point in the history
  • Loading branch information
markelog committed Jan 9, 2015
1 parent 3fe2a92 commit 67f6e8d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 55 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 19 additions & 21 deletions test/cli.js
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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/');
Expand All @@ -114,6 +110,8 @@ describe('modules/cli', function() {
});

assert(typeof result === 'object');

console.error.restore();
});

it('should set presets', function() {
Expand Down
61 changes: 28 additions & 33 deletions test/reporters/junit.js
Original file line number Diff line number Diff line change
@@ -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'] });
Expand Down

0 comments on commit 67f6e8d

Please sign in to comment.