Skip to content

Commit

Permalink
add ctrl di test. references #45
Browse files Browse the repository at this point in the history
  • Loading branch information
lynndylanhurley committed Oct 9, 2014
1 parent 08a56c0 commit 6baafa9
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 10 deletions.
40 changes: 37 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ var lazypipe = require('lazypipe');
var nib = require('nib');
var ngAnnotate = require('gulp-ng-annotate');

var appDir = 'test/app/'
var appDir = 'test/app/'
var distDir = 'test/dist/'
var tmpDir = 'test/.tmp/'
var tmpDir = 'test/.tmp/'
var testDir = 'test/test/'

var componentSrcDir = 'src/'
var componentDistDir = 'dist/'
Expand Down Expand Up @@ -208,7 +209,40 @@ var injectGlobals = lazypipe()
}
]);

console.log('@-->config', config);

gulp.task('inject-test-js', ['build-dev'], function() {
return gulp.src([
testDir+'karma.conf.coffee',
testDir+'karma-ci.conf.coffee'
])
.pipe($.inject($.bowerFiles({
paths: {bowerJson: "test/bower.json"},
read: false
}), {
ignorePath: [testDir],
starttag: '# bower:js',
endtag: '# endbower',
transform: function(filepath, file, i, length) {
return '"'+filepath.substr(1)+'"';
}
}))
.pipe($.inject(gulp.src(
[
tmpDir+'/views/**/*.js',
tmpDir+'/scripts/**/*.js'
],
{read: false}
), {
ignorePath: [testDir],
starttag: '# inject:js',
endtag: '# endinject',
transform: function(filepath, file, i, length) {
return '"'+filepath.substr(1)+'"';
}
}))
.pipe(gulp.dest(testDir))
.pipe($.size());
});

// Jade to HTML
gulp.task('base-tmpl', function() {
Expand Down
3 changes: 3 additions & 0 deletions test/app/scripts/controllers/pages/index.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
angular.module('ngTokenAuthTestApp')
.controller 'IndexCtrl', ($scope, $auth, $http, $q) ->
Prism.highlightAll()

# this method tests controller injection sanity
$scope.test = -> 'bang'
46 changes: 43 additions & 3 deletions test/test/karma-ci.conf.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,49 @@ module.exports = (config) ->
'test/test/**/*.coffee': ['coffee']

files : [
'test/app/bower_components/angular/angular.js'
'test/app/bower_components/angular-cookies/angular-cookies.js'
'test/app/bower_components/angular-mocks/angular-mocks.js'
# bower:js
"test/app/bower_components/jquery/dist/jquery.js"
"test/app/bower_components/angular/angular.js"
"test/app/bower_components/angular-animate/angular-animate.js"
"test/app/bower_components/Faker/Faker.js"
"test/app/bower_components/lodash/dist/lodash.compat.js"
"test/app/bower_components/bootstrap-additions/dist/bootstrap-additions.min.css"
"test/app/bower_components/angular-sanitize/angular-sanitize.js"
"test/app/bower_components/angular-cookies/angular-cookies.js"
"test/app/bower_components/angular-resource/angular-resource.js"
"test/app/bower_components/angular-mocks/angular-mocks.js"
"test/app/bower_components/matchmedia/matchMedia.js"
"test/app/bower_components/spin.js/spin.js"
"test/app/bower_components/respond/dest/respond.src.js"
"test/app/bower_components/angular-ui-router/release/angular-ui-router.js"
"test/app/bower_components/angular-motion/dist/angular-motion.min.css"
"test/app/bower_components/matchmedia-ng/matchmedia-ng.js"
"test/app/bower_components/angular-spinner/angular-spinner.js"
"test/app/bower_components/angular-strap/dist/angular-strap.min.js"
"test/app/bower_components/angular-strap/dist/angular-strap.tpl.min.js"
# endbower

# inject:js
"test/.tmp/views/404.js"
"test/.tmp/views/index.js"
"test/.tmp/views/multi-user.js"
"test/.tmp/views/style-guide.js"
"test/.tmp/views/terms.js"
"test/.tmp/views/partials/password-change-error-modal.js"
"test/.tmp/views/partials/password-reset-modal.js"
"test/.tmp/views/partials/style-guide/popover.js"
"test/.tmp/scripts/app.js"
"test/.tmp/scripts/ng-token-auth.js"
"test/.tmp/scripts/controllers/main.js"
"test/.tmp/scripts/directives/scroll-to.js"
"test/.tmp/scripts/plugins/prism.js"
"test/.tmp/scripts/polyfills/navigator.js"
"test/.tmp/scripts/polyfills/trim.js"
"test/.tmp/scripts/controllers/pages/alt-user.js"
"test/.tmp/scripts/controllers/pages/index.js"
"test/.tmp/scripts/controllers/pages/style-guide.js"
# endinject

'src/*.coffee'
'test/test/unit/test-helper.coffee'
'test/test/unit/ng-token-auth/**/*.coffee'
Expand Down
49 changes: 46 additions & 3 deletions test/test/karma.conf.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,57 @@ module.exports = (config) ->
preprocessors:
'src/*.coffee': ['coverage']
'test/test/**/*.coffee': ['coffee']
'test/app/scripts/**/*.coffee': ['coffee']

files : [
'test/app/bower_components/angular/angular.js'
'test/app/bower_components/angular-cookies/angular-cookies.js'
'test/app/bower_components/angular-mocks/angular-mocks.js'
# bower:js
"test/app/bower_components/jquery/dist/jquery.js"
"test/app/bower_components/angular/angular.js"
"test/app/bower_components/angular-animate/angular-animate.js"
"test/app/bower_components/Faker/Faker.js"
"test/app/bower_components/lodash/dist/lodash.compat.js"
"test/app/bower_components/bootstrap-additions/dist/bootstrap-additions.min.css"
"test/app/bower_components/angular-sanitize/angular-sanitize.js"
"test/app/bower_components/angular-cookies/angular-cookies.js"
"test/app/bower_components/angular-resource/angular-resource.js"
"test/app/bower_components/angular-mocks/angular-mocks.js"
"test/app/bower_components/matchmedia/matchMedia.js"
"test/app/bower_components/spin.js/spin.js"
"test/app/bower_components/respond/dest/respond.src.js"
"test/app/bower_components/angular-ui-router/release/angular-ui-router.js"
"test/app/bower_components/angular-motion/dist/angular-motion.min.css"
"test/app/bower_components/matchmedia-ng/matchmedia-ng.js"
"test/app/bower_components/angular-spinner/angular-spinner.js"
"test/app/bower_components/angular-strap/dist/angular-strap.min.js"
"test/app/bower_components/angular-strap/dist/angular-strap.tpl.min.js"
# endbower

# inject:js
"test/.tmp/views/404.js"
"test/.tmp/views/index.js"
"test/.tmp/views/multi-user.js"
"test/.tmp/views/style-guide.js"
"test/.tmp/views/terms.js"
"test/.tmp/views/partials/password-change-error-modal.js"
"test/.tmp/views/partials/password-reset-modal.js"
"test/.tmp/views/partials/style-guide/popover.js"
"test/.tmp/scripts/app.js"
"test/.tmp/scripts/ng-token-auth.js"
"test/.tmp/scripts/controllers/main.js"
"test/.tmp/scripts/directives/scroll-to.js"
"test/.tmp/scripts/plugins/prism.js"
"test/.tmp/scripts/polyfills/navigator.js"
"test/.tmp/scripts/polyfills/trim.js"
"test/.tmp/scripts/controllers/pages/alt-user.js"
"test/.tmp/scripts/controllers/pages/index.js"
"test/.tmp/scripts/controllers/pages/style-guide.js"
# endinject

'src/*.coffee'
'test/app/scripts/**/*.coffee'
'test/test/unit/test-helper.coffee'
'test/test/unit/ng-token-auth/**/*.coffee'
'test/test/unit/demo-site/**/*.coffee'
]

autoWatch: true
Expand Down
17 changes: 17 additions & 0 deletions test/test/unit/demo-site/index-ctrl.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
suite 'IndexCtrl', ->
createController = null
scope = null

setup ->
scope = $rootScope.$new()

createController = ->
$controller('IndexCtrl', {
'$scope': scope
})


test.only 'sanity', ->
ctrl = createController()
assert(ctrl)
assert.equal('bang', scope.test())
9 changes: 8 additions & 1 deletion test/test/unit/test-helper.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# global config
CONFIG =
apiUrl: '/api'


# global injectors
$locationProvider = null
$authProvider = null
$cookieStore = null
$httpBackend = null
$controller = null
$rootScope = null
$location = null
$provider = null
Expand Down Expand Up @@ -37,7 +43,7 @@ validUser =

# run before each test
setup ->
module 'ng-token-auth', (_$authProvider_, _$locationProvider_, $provide) ->
module 'ngTokenAuthTestApp', (_$authProvider_, _$locationProvider_, $provide) ->
$authProvider = _$authProvider_
$locationProvider = _$locationProvider_
$authProvider.configure({
Expand All @@ -49,6 +55,7 @@ setup ->
$httpBackend = $injector.get('$httpBackend')
$cookieStore = $injector.get('$cookieStore')
$rootScope = $injector.get('$rootScope')
$controller = $injector.get('$controller')
$location = $injector.get('$location')
$timeout = $injector.get('$timeout')
$window = $injector.get('$window')
Expand Down

0 comments on commit 6baafa9

Please sign in to comment.