-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Evan Sharp
committed
Jan 16, 2015
1 parent
380e82c
commit 98df613
Showing
10 changed files
with
297 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,5 +50,7 @@ results | |
|
||
npm-debug.log | ||
node_modules | ||
bower_components | ||
build | ||
|
||
.tern-project | ||
.tern-project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
|
||
before_script: | ||
- npm install | ||
- npm install -g gulp | ||
- npm install -g bower | ||
- bower install -F | ||
|
||
script: | ||
- gulp build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var pkg = require('./package.json'); | ||
|
||
var pkgFiles = { | ||
angular: [ | ||
'bower_components/angular/angular.js' | ||
], | ||
karma: [ | ||
'bower_components/angular/angular.js', | ||
'bower_components/angular-mocks/angular-mocks.js', | ||
'mock/socket-io.js', | ||
'bower_components/sails.io.js/sails.io.js' | ||
], | ||
'karma-build': [ | ||
'@karma', | ||
'build/' + pkg.name + '.js', | ||
'@karma-tests' | ||
], | ||
'karma-min': [ | ||
'@karma', | ||
'build/' + pkg.name + '.min.js', | ||
'@karma-tests' | ||
], | ||
'karma-src': [ | ||
'@karma', | ||
'@src', | ||
'@karma-tests' | ||
], | ||
'karma-tests': [ | ||
'test/**/*.spec.js' | ||
], | ||
src: [ | ||
'src/**/*.js', | ||
] | ||
}; | ||
|
||
if (module.exports) { | ||
module.exports.files = pkgFiles; | ||
module.exports.mergeFilesFor = function() { | ||
var files = []; | ||
|
||
Array.prototype.slice.call(arguments, 0).forEach(function(filegroup) { | ||
pkgFiles[filegroup].forEach(function(file) { | ||
// replace @ref | ||
var match = file.match(/^\@(.*)/); | ||
if (match) { | ||
files = files.concat(pkgFiles[match[1]]); | ||
} else { | ||
files.push(file); | ||
} | ||
}); | ||
}); | ||
|
||
return files; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,49 @@ | ||
'use strict'; | ||
|
||
var gulp = require('gulp'), | ||
concat = require('gulp-concat'), | ||
uglify = require('gulp-uglify'), | ||
header = require('gulp-header'), | ||
footer = require('gulp-footer'); | ||
footer = require('gulp-footer'), | ||
ngAnnotate = require('gulp-ng-annotate'), | ||
gulpKarma = require('gulp-karma'), | ||
pkg = require('./package.json'), | ||
files = require('./files'); | ||
|
||
var karmaTestConfig = gulpKarma({configFile: 'karma.conf.js', action: 'run'}); | ||
|
||
|
||
gulp.task('build-js', function () { | ||
gulp.src(['src/ngSails.js', 'src/**/*.js']) | ||
.pipe(concat('angular-sails.js')) | ||
return gulp.src(files.mergeFilesFor('src')) | ||
.pipe(ngAnnotate()) | ||
.pipe(concat(pkg.name+'.js')) | ||
.pipe(header('(function (angular, io) {\n\'use strict\'')) | ||
.pipe(footer('}(angular, io));')) | ||
.pipe(gulp.dest('./dist/')) | ||
.pipe(concat('angular-sails.min.js')) | ||
.pipe(gulp.dest('./build/')) | ||
.pipe(concat(pkg.name+'.min.js')) | ||
.pipe(uglify()) | ||
.pipe(gulp.dest('./dist/')); | ||
.pipe(gulp.dest('./build/')); | ||
}); | ||
|
||
gulp.task('dist-js', ['build-js'], function () { | ||
return gulp.src('./build/*.js') | ||
.pipe(gulp.dest('./dist/')); | ||
}); | ||
|
||
gulp.task('test', function () { | ||
return gulp.src(files.mergeFilesFor('karma-src')).pipe(karmaTestConfig); | ||
}); | ||
|
||
gulp.task('test-build', ['build-js'], function () { | ||
return gulp.src(files.mergeFilesFor('karma-build')).pipe(karmaTestConfig); | ||
}); | ||
|
||
gulp.task('test-min', ['build-js'], function () { | ||
return gulp.src(files.mergeFilesFor('karma-min')).pipe(karmaTestConfig); | ||
}); | ||
|
||
gulp.task('watch', function () { | ||
gulp.watch('src/**/*.js', ['build-js']); | ||
return gulp.watch('src/**/*.js', ['build-js']); | ||
}); | ||
|
||
gulp.task('default', ['build-js', 'watch']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Karma configuration | ||
// Generated on Thu Jan 09 2014 13:59:16 GMT-0500 (EST) | ||
|
||
module.exports = function (config) { | ||
config.set({ | ||
basePath: './', | ||
|
||
frameworks: ['mocha', 'chai-sinon'], | ||
|
||
exclude: [], | ||
|
||
reporters: ['progress'], | ||
|
||
port: 9876, | ||
|
||
runnerPort: 9100, | ||
|
||
colors: true, | ||
|
||
logLevel: config.LOG_INFO, | ||
|
||
autoWatch: true, | ||
|
||
// Start these browsers, currently available: | ||
// - Chrome | ||
// - ChromeCanary (has to be installed with `npm install karma-chrome-canary-launcher`) | ||
// - Firefox (has to be installed with `npm install karma-firefox-launcher`) | ||
// - Opera (has to be installed with `npm install karma-opera-launcher`) | ||
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`) | ||
// - PhantomJS | ||
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`) | ||
browsers: ['PhantomJS'], | ||
|
||
captureTimeout: 60000, | ||
|
||
singleRun: false | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var io = { | ||
connect: createMockSocketObject | ||
}; | ||
|
||
function createMockSocketObject () { | ||
|
||
var socket = { | ||
on: function (ev, fn) { | ||
(this._listeners[ev] = this._listeners[ev] || []).push(fn); | ||
}, | ||
once: function (ev, fn) { | ||
(this._listeners[ev] = this._listeners[ev] || []).push(fn); | ||
fn._once = true; | ||
}, | ||
emit: function (ev, data) { | ||
if (this._listeners[ev]) { | ||
var args = arguments; | ||
this._listeners[ev].forEach(function (listener) { | ||
if (listener._once) { | ||
this.removeListener(ev, listener); | ||
} | ||
listener.apply(null, Array.prototype.slice.call(args, 1)); | ||
}.bind(this)); | ||
} | ||
}, | ||
_listeners: {}, | ||
removeListener: function (ev, fn) { | ||
if (fn) { | ||
var index = this._listeners[ev].indexOf(fn); | ||
if (index > -1) { | ||
this._listeners[ev].splice(index, 1); | ||
} | ||
} else { | ||
delete this._listeners[ev]; | ||
} | ||
}, | ||
removeAllListeners: function (ev) { | ||
if (ev) { | ||
delete this._listeners[ev]; | ||
} else { | ||
this._listeners = {}; | ||
} | ||
}, | ||
disconnect: function () {}, | ||
connect: function () {} | ||
}; | ||
|
||
return socket; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
describe('Agnular Sails', function() { | ||
|
||
var $scope, | ||
$compile, | ||
$timeout, | ||
$sails, | ||
mockIoSocket, | ||
spy; | ||
|
||
beforeEach(module('ngSails')); | ||
|
||
beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_, _$sails_) { | ||
$scope = _$rootScope_.$new(); | ||
$compile = _$compile_; | ||
$timeout = _$timeout_; | ||
$sails = _$sails_; | ||
mockIoSocket = $sails; | ||
spy = sinon.spy(); | ||
})); | ||
|
||
describe('#on', function() { | ||
|
||
it('should apply asynchronously', function () { | ||
$sails.on('event', spy); | ||
mockIoSocket.emit('event'); | ||
|
||
expect(spy).to.have.been.not.called; | ||
$timeout.flush(); | ||
|
||
expect(spy).to.have.been.called; | ||
}); | ||
|
||
}); | ||
|
||
describe('#disconnect', function () { | ||
|
||
it('should call the underlying socket.disconnect', function () { | ||
mockIoSocket.disconnect = spy; | ||
$sails.disconnect(); | ||
expect(spy).to.have.been.called; | ||
}); | ||
|
||
}); | ||
|
||
describe('#connect', function () { | ||
|
||
it('should call the underlying socket.connect', function () { | ||
mockIoSocket.connect = spy; | ||
$sails.connect(); | ||
expect(spy).to.have.been.called; | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('#once', function () { | ||
|
||
it('should apply asynchronously', function () { | ||
$sails.once('event', spy); | ||
|
||
mockIoSocket.emit('event'); | ||
|
||
expect(spy).to.have.been.not.called; | ||
$timeout.flush(); | ||
|
||
expect(spy).to.have.been.called; | ||
}); | ||
|
||
it('should only run once', function () { | ||
var counter = 0; | ||
$sails.once('event', function () { | ||
counter += 1; | ||
}); | ||
|
||
mockIoSocket.emit('event'); | ||
mockIoSocket.emit('event'); | ||
$timeout.flush(); | ||
|
||
expect(counter).to.equal(1); | ||
}); | ||
|
||
}); | ||
|
||
|
||
}); |