-
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.
Merge pull request #48 from TheSharpieOne/master
Refactoring, Tests, and More
- Loading branch information
Showing
14 changed files
with
1,152 additions
and
87 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,8 @@ results | |
|
||
npm-debug.log | ||
node_modules | ||
bower_components | ||
build | ||
|
||
.tern-project | ||
.tern-project | ||
.idea |
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,13 @@ | ||
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-js | ||
- gulp test-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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,81 @@ | ||
// fix for phantomjs < 2.0 | ||
if (!Function.prototype.bind) { | ||
Function.prototype.bind = function(oThis) { | ||
if (typeof this !== 'function') { | ||
// closest thing possible to the ECMAScript 5 | ||
// internal IsCallable function | ||
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); | ||
} | ||
|
||
var aArgs = Array.prototype.slice.call(arguments, 1), | ||
fToBind = this, | ||
fNOP = function() {}, | ||
fBound = function() { | ||
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, | ||
aArgs.concat(Array.prototype.slice.call(arguments))); | ||
}; | ||
|
||
fNOP.prototype = this.prototype; | ||
fBound.prototype = new fNOP(); | ||
|
||
return fBound; | ||
}; | ||
} | ||
|
||
function io() { | ||
var mockSocketObject = createMockSocketObject(); | ||
return mockSocketObject.connect(); | ||
} | ||
|
||
function createMockSocketObject() { | ||
|
||
var socket = { | ||
on: function(ev, fn) { | ||
(this._listeners[ev] = this._listeners[ev] || []).push(fn); | ||
}, | ||
once: function(ev, fn) { | ||
(this._raw._listeners[ev] = this._raw._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() { | ||
this.connected = false; | ||
this.emit('disconnect'); | ||
}, | ||
connect: function() { | ||
this.connected = true; | ||
this.emit('connect'); | ||
return this; | ||
} | ||
}; | ||
|
||
return socket; | ||
} |
Oops, something went wrong.