From 31dbffde6564b67814027d0bb9b6beb4c25a3a65 Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Tue, 29 Oct 2013 11:57:31 +0000 Subject: [PATCH 1/3] Test framework and jshint adjustments --- .jshintrc | 17 ++++++++++++ .travis.yml | 11 ++++++++ Imager.js | 5 ++-- karma.conf.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 19 +++++++++++-- test/unit/core.js | 11 ++++++++ 6 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 .jshintrc create mode 100644 .travis.yml create mode 100644 karma.conf.js create mode 100644 test/unit/core.js 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..b34c738 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: node_js +node_js: + - "0.10" +notifications: + email: + recipients: + - thomas.parisot@bbc.co.uk + on_failure: change + on_success: never +before_script: + - npm install -g grunt-cli 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..212ef6f --- /dev/null +++ b/test/unit/core.js @@ -0,0 +1,11 @@ +'use strict'; + +describe('Imager.js', function(){ + describe('constructor', function(){ + + it('should work', function(){ + + }); + + }); +}); \ No newline at end of file From 2a3f3b588e8e9ecd75cd0e0f57f1b8c9f2bd6919 Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Tue, 29 Oct 2013 11:59:53 +0000 Subject: [PATCH 2/3] We don't even use grunt for testing --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b34c738..7b9fbae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,3 @@ notifications: - thomas.parisot@bbc.co.uk on_failure: change on_success: never -before_script: - - npm install -g grunt-cli From 7087c02fa738c892c042762bb3e53166c0d972e6 Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Tue, 29 Oct 2013 15:40:15 +0000 Subject: [PATCH 3/3] Testing constructor. --- test/unit/core.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/unit/core.js b/test/unit/core.js index 212ef6f..c612bc2 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -3,8 +3,16 @@ describe('Imager.js', function(){ describe('constructor', function(){ - it('should work', 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); }); });