From 7e88f490599ea3afe1f258241e04f61e1d9300c7 Mon Sep 17 00:00:00 2001 From: Douglas Duteil Date: Tue, 31 Dec 2013 13:43:17 +0100 Subject: [PATCH] feat(test): Run tests with jQuery present Following #8 --- bower.json | 3 +- gruntFile.js | 12 ++-- test/helpers/jquery_alias.js | 4 ++ test/helpers/jquery_remove.js | 4 ++ test/{karma.conf.js => karma-jqlite.conf.js} | 2 + test/karma-jquery.conf.js | 75 ++++++++++++++++++++ 6 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 test/helpers/jquery_alias.js create mode 100644 test/helpers/jquery_remove.js rename test/{karma.conf.js => karma-jqlite.conf.js} (95%) create mode 100644 test/karma-jquery.conf.js diff --git a/bower.json b/bower.json index 4489992..3113fb0 100644 --- a/bower.json +++ b/bower.json @@ -19,6 +19,7 @@ "angular": "~1.2.1" }, "devDependencies": { - "angular-mocks": "~1.2.1" + "angular-mocks": "~1.2.1", + "jquery": "~2.0.3" } } diff --git a/gruntFile.js b/gruntFile.js index 7c38632..31126b6 100644 --- a/gruntFile.js +++ b/gruntFile.js @@ -9,6 +9,9 @@ module.exports = function (grunt) { grunt.registerTask('serve', ['connect:continuous', 'karma:continuous', 'watch']); grunt.registerTask('dist', ['ngmin', 'uglify']); + grunt.registerTask('karma:continuous', ['karma:wjqlite_bg', 'karma:wjquery_bg']); + grunt.registerTask('karma:unit', ['karma:wjqlite:unit', 'karma:wjquery:unit']); + grunt.registerTask('karma:unit:run', ['karma:wjqlite:unit:run', 'karma:wjquery:unit:run']); var testConfig = function (configFile, customOptions) { var options = { configFile: configFile, singleRun: true }; @@ -44,9 +47,10 @@ module.exports = function (grunt) { // TESTER // ======= karma: { - unit: testConfig('test/karma.conf.js'), - server: {configFile: 'test/karma.conf.js'}, - continuous: {configFile: 'test/karma.conf.js', background: true } + wjquery: testConfig('test/karma-jquery.conf.js'), + wjqlite: testConfig('test/karma-jqlite.conf.js'), + wjquery_bg: {configFile: 'test/karma-jquery.conf.js', background: true }, + wjqlite_bg: {configFile: 'test/karma-jqlite.conf.js', background: true } }, @@ -58,7 +62,7 @@ module.exports = function (grunt) { tasks: ['jshint:src', 'karma:unit:run', 'dist'] }, test: { - files: ['test/*.js'], + files: ['test/*.spec.js'], tasks: ['jshint:test', 'karma:unit:run'] }, demo: { diff --git a/test/helpers/jquery_alias.js b/test/helpers/jquery_alias.js new file mode 100644 index 0000000..dadfa33 --- /dev/null +++ b/test/helpers/jquery_alias.js @@ -0,0 +1,4 @@ +'use strict'; +/* global jQuery */ + +var _jQuery = jQuery; diff --git a/test/helpers/jquery_remove.js b/test/helpers/jquery_remove.js new file mode 100644 index 0000000..6f0ef4b --- /dev/null +++ b/test/helpers/jquery_remove.js @@ -0,0 +1,4 @@ +'use strict'; +/* global jQuery */ + +var _jQuery = jQuery.noConflict(true); diff --git a/test/karma.conf.js b/test/karma-jqlite.conf.js similarity index 95% rename from test/karma.conf.js rename to test/karma-jqlite.conf.js index d496352..1f9a1db 100644 --- a/test/karma.conf.js +++ b/test/karma-jqlite.conf.js @@ -16,6 +16,8 @@ module.exports = function (config) { // list of files / patterns to load in the browser files: [ + 'bower_components/jquery/jquery.js', + 'test/helpers/jquery_remove.js', 'bower_components/angular/angular.js', 'bower_components/angular-mocks/angular-mocks.js', 'src/*', diff --git a/test/karma-jquery.conf.js b/test/karma-jquery.conf.js new file mode 100644 index 0000000..3216dc8 --- /dev/null +++ b/test/karma-jquery.conf.js @@ -0,0 +1,75 @@ +// Karma configuration +// Generated on Thu Nov 21 2013 15:01:01 GMT+0100 (CET) + +module.exports = function (config) { + 'use strict'; + + config.set({ + + // base path, that will be used to resolve files and exclude + basePath: '..', + + + // frameworks to use + frameworks: ['jasmine'], + + + // list of files / patterns to load in the browser + files: [ + 'bower_components/jquery/jquery.js', + 'test/helpers/jquery_alias.js', + 'bower_components/angular/angular.js', + 'bower_components/angular-mocks/angular-mocks.js', + 'src/*', + 'test/*.spec.js' + ], + + + // list of files to exclude + exclude: [ + + ], + + + // test results reporter to use + // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' + reporters: ['dots'], + + + // web server port + port: 5432, + + + // 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: false, + + + // 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: ['Chrome', 'Firefox', '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 + }); +};