diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..018b46f --- /dev/null +++ b/.jshintrc @@ -0,0 +1,17 @@ +{ + "curly": true, + "eqeqeq": true, + "immed": true, + "latedef": true, + "newcap": true, + "noarg": true, + "sub": true, + "undef": true, + "unused": true, + "boss": true, + "eqnull": true, + "browser": true, + "globalstrict": true, + "es3": true, + "globals": {} +} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7b9fbae --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - "0.10" +notifications: + email: + recipients: + - thomas.parisot@bbc.co.uk + on_failure: change + on_success: never diff --git a/Imager.js b/Imager.js index ffa500e..6786c7b 100644 --- a/Imager.js +++ b/Imager.js @@ -117,7 +117,7 @@ gif.setAttribute('data-src', element.getAttribute('data-src')); element.parentNode.replaceChild(gif, element); - } + }; Imager.prototype.changeDivsToEmptyImages = function(){ var divs = this.divs, @@ -152,8 +152,7 @@ }; Imager.prototype.checkImagesNeedReplacing = function(){ - var self = this, - images = $(this.className), + var images = $(this.className), i = images.length, currentImage; diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..56b1fc4 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,69 @@ +// Karma configuration +// Generated on Tue Oct 29 2013 11:45:20 GMT+0000 (GMT) + +module.exports = function(config) { + config.set({ + + // base path, that will be used to resolve files and exclude + basePath: '', + + + // frameworks to use + frameworks: ['mocha', 'chai'], + + + // list of files / patterns to load in the browser + files: [ + 'Imager.js', + 'test/unit/**/*.js' + ], + + + // list of files to exclude + exclude: [ + + ], + + + // test results reporter to use + // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' + reporters: ['progress'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // Start these browsers, currently available: + // - Chrome + // - ChromeCanary + // - Firefox + // - 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'], + + + // If browser does not capture in given timeout [ms], kill it + captureTimeout: 60000, + + + // Continuous Integration mode + // if true, it capture browsers, run tests and exit + singleRun: false + }); +}; diff --git a/package.json b/package.json index 087b717..d310a20 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "Imager.js is an alternative solution to the issue of how to handle responsive image loading, created by developers at BBC News.", "private": true, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "jshint Imager.js && karma start --single-run", + "test-watch": "karma start" }, "repository": { "type": "git", @@ -25,6 +26,20 @@ "gitHead": "8d192cf0224a705e463b4dca18041168d491a6e9", "devDependencies": { "grunt": "~0.4.1", - "grunt-responsive-images": "0.0.3" + "grunt-responsive-images": "0.0.3", + "karma-chai": "0.0.2", + "karma-mocha": "~0.1.0", + "chai": "~1.8.1", + "mocha": "~1.13.0", + "karma-phantomjs-launcher": "~0.1.0", + "karma-script-launcher": "~0.1.0", + "karma-chrome-launcher": "~0.1.0", + "karma-firefox-launcher": "~0.1.0", + "karma-html2js-preprocessor": "~0.1.0", + "karma-jasmine": "~0.1.3", + "karma-requirejs": "~0.1.0", + "karma-coffee-preprocessor": "~0.1.0", + "karma": "~0.10.4", + "jshint": "~2.3.0" } } diff --git a/test/unit/core.js b/test/unit/core.js new file mode 100644 index 0000000..c612bc2 --- /dev/null +++ b/test/unit/core.js @@ -0,0 +1,19 @@ +'use strict'; + +describe('Imager.js', function(){ + describe('constructor', function(){ + + it('should initialise without arguments', function(done){ + var imgr = new Imager(); + + setTimeout(function(){ + expect(imgr.initialized).to.be.true; + expect(imgr.scrolled).to.be.false; + expect(imgr.cache).to.be.empty; + + done(); + }, 100); + }); + + }); +}); \ No newline at end of file