Skip to content

Commit

Permalink
tests unit && e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsouche committed Sep 15, 2014
1 parent b98a2a4 commit 0397fc9
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 142 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
Debug/
Release/
Release/
.idea/
228 changes: 96 additions & 132 deletions .idea/workspace.xml

Large diffs are not rendered by default.

19 changes: 17 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);

grunt.initConfig({
jasmine_node: {
options: {
forceExit: true,
specNameMatcher: 'Spec'
},
unit: ['test/unit/'],
e2e: ['test/e2e/']
},
jshint: {
module: {
options: {
Expand All @@ -24,12 +32,19 @@ module.exports = function(grunt) {
},
js: {
files: ['*.js'],
tasks: ['jshint:module']
tasks: ['jshint:module','test:unit']
},
test: {
files: ['test/**/*.js'],
tasks: ['jshint:test']
tasks: ['jshint:test','test:unit']
}
}
});

grunt.registerTask('dev',['watch']);
grunt.registerTask('test:unit', ['jasmine_node:unit']);
grunt.registerTask('test:e2e', ['jasmine_node:e2e']);



};
7 changes: 7 additions & 0 deletions build/twainDll.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//Mock file to pass test
/*jslint node: true */
'use strict';

exports.goScan = function() {
console.log('OMG IT WORKS');
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-jasmine-node": "^0.2.1",
"load-grunt-tasks": "~0.2.0"
"load-grunt-tasks": "~0.2.0",
"proxyquire": "^1.0.1"
},
"engines": {
"node": ">= 0.8.0"
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/twainDllSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe('twainDll',function() {
'use strict';

var TwainDll = require('../../twainDll').TwainDll,
scanDll = new TwainDll();

beforeEach(function() {
//here is the function call
scanDll.goScan();
});

it('should do the amazing',function() {
expect(1 + 1).toBe(2);
});

});
Empty file added test/unit/mockModules.js
Empty file.
73 changes: 70 additions & 3 deletions test/unit/twainDllSpec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,78 @@
describe('twainDll',function() {
'use strict';

var twainDll = require('../../twainDll');
var proxyquire = require('proxyquire'),module,mockUtil,mockBinding,mockEvents,mockStream;

it('should return a function',function() {
expect(typeof twainDll).toBe('function');
beforeEach(function() {
mockEvents = {
EventEmitter: {foo:'bar'}
};
mockStream = {
Stream: {foo:'bar'}
};
mockUtil = jasmine.createSpyObj('util',['inherits']);
mockBinding = jasmine.createSpyObj('binding',['goScan']);
module = proxyquire('../../twainDll', {
'./build/twainDll.node': mockBinding,
'events': mockEvents,
'stream': mockStream,
'util': mockUtil
});
});

it('should return an instance of TwainDllFactory',function() {
expect(typeof module).toBe('object');
expect(module.constructor.name).toBe('TwainDllFactory');
});

it('should inherits from events',function() {
expect(mockUtil.inherits).toHaveBeenCalledWith(module.constructor,mockEvents.EventEmitter);
});

it('should provide the binding',function() {
expect(module.binding).toBe(mockBinding);
});

describe('TwainDllConstructor', function() {

it('should provide a TwainDll constructor',function() {
expect(typeof module.TwainDll).toBe('function');
});

it('should inherits from stream',function() {
expect(mockUtil.inherits).toHaveBeenCalledWith(module.TwainDll,mockStream.Stream);
});

describe('Instance', function() {
var scanObj;

beforeEach(function() {
scanObj = new module.TwainDll();
});

it('should create an instance of TwainDll',function() {
expect(typeof scanObj).toBe('object');
expect(scanObj.constructor.name).toBe('TwainDll');
});

it('should provide the api',function() {
expect(typeof scanObj.goScan).toBe('function');
});

describe('goScan',function() {

beforeEach(function() {
scanObj.goScan();
});

it('should call the binding',function() {
expect(mockBinding.goScan).toHaveBeenCalled();
});

});

});

});

});
12 changes: 9 additions & 3 deletions twainDll.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@

var util = require('util'),
stream = require('stream'),
EventEmitter = require('events').EventEmitter;
EventEmitter = require('events').EventEmitter,
binding = require('./build/twainDll.node');


function TwainDllFactory() {
var factory = this;

function TwainDll(options) {


}

}

util.inherits(TwainDll, stream.Stream);

factory.TwainDll = TwainDll;
TwainDll.prototype.goScan = function() {
factory.binding.goScan();
};

factory.TwainDll = TwainDll;
factory.binding = binding;
}

util.inherits(TwainDllFactory,EventEmitter);
Expand Down

0 comments on commit 0397fc9

Please sign in to comment.