Skip to content

Commit

Permalink
Merge pull request #145 from pomerantsev/protractor
Browse files Browse the repository at this point in the history
Use Protractor for testing
  • Loading branch information
sroze committed Dec 2, 2014
2 parents 7c2047e + a7b3e7e commit 99f2a95
Show file tree
Hide file tree
Showing 19 changed files with 300 additions and 21,902 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
compile/*
node_modules
.tmp
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
language: node_js
node_js:
- 0.10

install:
- npm install

before_script:
- npm install -g grunt-cli

script:
- grunt test:protractor-travis
66 changes: 57 additions & 9 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ module.exports = (grunt) ->
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-concat'
grunt.loadNpmTasks 'grunt-contrib-connect'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-karma'
grunt.loadNpmTasks 'grunt-protractor-runner'

sauceUser = 'pomerantsevp'
sauceKey = '497ab04e-f31b-4a7b-9b18-ae3fbe023222'

grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
Expand Down Expand Up @@ -49,14 +53,58 @@ module.exports = (grunt) ->
dist:
src: ['build/ng-infinite-scroll.js']
dest: 'build/ng-infinite-scroll.min.js'
karma:
unit:
connect:
testserver:
options:
port: 8000
hostname: '0.0.0.0'
middleware: (connect, options) ->
base = if Array.isArray(options.base) then options.base[options.base.length - 1] else options.base
[connect.static(base)]
protractor:
local:
options:
configFile: 'test/protractor-local.conf.js'
args:
params:
testThrottleValue: 500
travis:
options:
configFile: 'test/karma.conf.js'
reporters: ['dots']
browsers: ['PhantomJS', 'Chrome']
runnerPort: 9101
keepalive: true
configFile: 'test/protractor-travis.conf.js'
args:
params:
# When using Sauce Connect, we should use a large timeout
# since everything is generally much slower than when testing locally.
testThrottleValue: 10000
sauceUser: sauceUser
sauceKey: sauceKey

grunt.registerTask 'webdriver', () ->
done = this.async()
p = require('child_process').spawn('node', ['node_modules/protractor/bin/webdriver-manager', 'update'])
p.stdout.pipe(process.stdout)
p.stderr.pipe(process.stderr)
p.on 'exit', (code) ->
if code isnt 0 then grunt.fail.warn('Webdriver failed to update')
done()

grunt.registerTask 'sauce-connect', () ->
done = this.async()
require('sauce-connect-launcher')({username: sauceUser, accessKey: sauceKey}, (err, sauceConnectProcess) ->
if err then console.error(err.message)
else done()
)

grunt.registerTask 'default', ['coffeelint', 'clean', 'coffee', 'concat', 'uglify']
grunt.registerTask 'test', ['karma']
grunt.registerTask 'test:protractor-local', [
'default',
'webdriver',
'connect:testserver',
'protractor:local'
]

grunt.registerTask 'test:protractor-travis', [
'connect:testserver',
'sauce-connect',
'protractor:travis'
]
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ ngInfiniteScroll is licensed under the MIT license. See the LICENSE file for mor
Testing
-------

ngInfiniteScroll uses Testacular for its unit tests. Note that you will need [PhantomJS](http://phantomjs.org/) on your path, and the `grunt-cli` npm package installed globally if you wish to use grunt (`npm install -g grunt-cli`). Then, install the dependencies with `npm install`.
ngInfiniteScroll uses Protractor for testing. Note that you will need to have Chrome browser, and the `grunt-cli` npm package installed globally if you wish to use grunt (`npm install -g grunt-cli`). Then, install the dependencies with `npm install`.

* `grunt test` - continually watch for changes and run tests in PhantomJS and Chrome
* `npm test` - run tests once in PhantomJS only
* `grunt test:protractor-local` - run tests
14 changes: 7 additions & 7 deletions build/ng-infinite-scroll.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ng-infinite-scroll - v1.1.2 - 2014-11-24 */
/* ng-infinite-scroll - v1.1.2 - 2014-12-01 */
var mod;

mod = angular.module('infinite-scroll', []);

mod.value('THROTTLE_MILLISECONDS', null);

mod.directive('infiniteScroll', [
'$rootScope', '$window', '$timeout', 'THROTTLE_MILLISECONDS', function($rootScope, $window, $timeout, THROTTLE_MILLISECONDS) {
'$rootScope', '$window', '$interval', 'THROTTLE_MILLISECONDS', function($rootScope, $window, $interval, THROTTLE_MILLISECONDS) {
return {
scope: {
infiniteScroll: '&',
Expand Down Expand Up @@ -84,7 +84,7 @@ mod.directive('infiniteScroll', [
later = function() {
var context;
previous = new Date().getTime();
$timeout.cancel(timeout);
$interval.cancel(timeout);
timeout = null;
func.call();
return context = null;
Expand All @@ -95,13 +95,13 @@ mod.directive('infiniteScroll', [
remaining = wait - (now - previous);
if (remaining <= 0) {
clearTimeout(timeout);
$timeout.cancel(timeout);
$interval.cancel(timeout);
timeout = null;
previous = now;
return func.call();
} else {
if (!timeout) {
return timeout = $timeout(later, remaining);
return timeout = $interval(later, remaining, 1);
}
}
};
Expand Down Expand Up @@ -166,11 +166,11 @@ mod.directive('infiniteScroll', [
if (attrs.infiniteScrollImmediateCheck != null) {
immediateCheck = scope.$eval(attrs.infiniteScrollImmediateCheck);
}
return $timeout((function() {
return $interval((function() {
if (immediateCheck) {
return handler();
}
}), 0);
}), 0, 1);
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions build/ng-infinite-scroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"browser": "build/ng-infinite-scroll.js",
"scripts": {
"test": "./node_modules/karma/bin/karma start --single-run --browsers=PhantomJS ./test/karma.conf.js"
"test": "grunt test:protractor-local"
},
"author": {
"name": "Brandon Tilley",
Expand All @@ -25,20 +25,17 @@
"license": "MIT",
"readmeFilename": "README.md",
"devDependencies": {
"chai": "~1.10.0",
"coffee-script": "~1.8.0",
"grunt": "~0.4.5",
"grunt-coffeelint": "~0.0.13",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-coffee": "~0.12.0",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-connect": "0.8.0",
"grunt-contrib-uglify": "~0.6.0",
"grunt-karma": "~0.9.0",
"http-proxy": "~1.6.2",
"karma": "~0.12.25",
"karma-chrome-launcher": "~0.1.5",
"karma-coffee-preprocessor": "~0.2.1",
"karma-mocha": "~0.1.9",
"karma-phantomjs-launcher": "~0.1.4"
"grunt-protractor-runner": "1.1.4",
"mkdirp": "0.5.0",
"protractor": "1.4.0",
"sauce-connect-launcher": "0.9.0"
}
}
14 changes: 7 additions & 7 deletions src/infinite-scroll.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ mod = angular.module('infinite-scroll', [])

mod.value('THROTTLE_MILLISECONDS', null)

mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', 'THROTTLE_MILLISECONDS', \
($rootScope, $window, $timeout, THROTTLE_MILLISECONDS) ->
mod.directive 'infiniteScroll', ['$rootScope', '$window', '$interval', 'THROTTLE_MILLISECONDS', \
($rootScope, $window, $interval, THROTTLE_MILLISECONDS) ->
scope:
infiniteScroll: '&'
infiniteScrollContainer: '='
Expand Down Expand Up @@ -82,7 +82,7 @@ mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', 'THROTTLE_
previous = 0
later = ->
previous = new Date().getTime()
$timeout.cancel(timeout)
$interval.cancel(timeout)
timeout = null
func.call()
context = null
Expand All @@ -92,11 +92,11 @@ mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', 'THROTTLE_
remaining = wait - (now - previous)
if remaining <= 0
clearTimeout timeout
$timeout.cancel(timeout)
$interval.cancel(timeout)
timeout = null
previous = now
func.call()
else timeout = $timeout(later, remaining) unless timeout
else timeout = $interval(later, remaining, 1) unless timeout

if THROTTLE_MILLISECONDS?
handler = throttle(handler, THROTTLE_MILLISECONDS)
Expand Down Expand Up @@ -190,8 +190,8 @@ mod.directive 'infiniteScroll', ['$rootScope', '$window', '$timeout', 'THROTTLE_
if attrs.infiniteScrollImmediateCheck?
immediateCheck = scope.$eval(attrs.infiniteScrollImmediateCheck)

$timeout (->
$interval (->
if immediateCheck
handler()
), 0
), 0, 1
]
62 changes: 0 additions & 62 deletions test/karma.conf.js

This file was deleted.

Loading

0 comments on commit 99f2a95

Please sign in to comment.