diff --git a/.travis.yml b/.travis.yml index 340b431c..60e681f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,16 @@ language: node_js + node_js: - 0.10 + +env: + global: + - secure: XMNK8GVxkwKa6oLl7nJwgg/wmY1YDk5rrMd+UXz26EDCsMDbiy1P7GhN2fEiBSLaQ7YfEuvaDcmzQxTrT0YTHp1PDzb2o9J4tIDdEkqPcv1y8xMaYDfmsN0rBPdBwZEg9H5zUgi7OdUbrGswSYxsKCE3x8EOqK89104HyOo1LN4= + - secure: BU5BPRx6H4O3WJ509YPixjUxg+hDF3z2BVJX6NiGmKWweqvCEYFfiiHLwDEgp/ynRcF9vGVi1V4Ly1jq7f8NIajbDZ5q443XchZFYFg78K/EwD5mK6LYt16zb7+Jn0KbzwHeGRGzc9AvcEYlW6i634cSCm4n3BnqtF5PpogSzdw= + script: - - grunt compile test + - grunt ci + notifications: email: false irc: diff --git a/Gruntfile.js b/Gruntfile.js index ea3c9d94..ddf853ca 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,6 +29,21 @@ module.exports = function (grunt) { cwd: 'src/js' }, 'select2/i18n/*.js'); + var testFiles = grunt.file.expand('tests/**/*.html'); + var testUrls = testFiles.map(function (filePath) { + return 'http://localhost:9999/' + filePath; + }); + + var testBuildNumber = "unknown"; + + if (process.env.TRAVIS_JOB_ID) { + testBuildNumber = "travis-" + process.env.TRAVIS_JOB_ID; + } else { + var currentTime = new Date(); + + testBuildNumber = "manual-" + currentTime.getTime(); + } + for (var i = 0; i < i18nFiles.length; i++) { var file = i18nFiles[i]; var name = file.split('.')[0]; @@ -45,6 +60,16 @@ module.exports = function (grunt) { docs: ['docs/_site'] }, + connect: { + tests: { + options: { + base: '.', + hostname: '127.0.0.1', + port: 9999 + } + } + }, + uglify: { 'dist': { src: 'dist/js/select2.js', @@ -57,9 +82,36 @@ module.exports = function (grunt) { }, qunit: { - all: [ - 'tests/**/*.html' - ] + all: { + options: { + urls: testUrls + } + } + }, + + 'saucelabs-qunit': { + all: { + options: { + build: testBuildNumber, + tags: ['tests', 'qunit'], + urls: testUrls, + testname: 'QUnit test for Select2', + browsers: [ + { + browserName: 'internet explorer', + version: '9' + }, + + { + browserName: 'firefox' + }, + + { + browserName: 'chrome' + } + ] + } + } }, 'gh-pages': { @@ -234,6 +286,7 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-qunit'); grunt.loadNpmTasks('grunt-contrib-requirejs'); @@ -243,6 +296,7 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-gh-pages'); grunt.loadNpmTasks('grunt-jekyll'); + grunt.loadNpmTasks('grunt-saucelabs'); grunt.loadNpmTasks('grunt-sass'); grunt.registerTask('default', ['compile', 'test', 'minify']); @@ -251,6 +305,8 @@ module.exports = function (grunt) { grunt.registerTask('minify', ['uglify', 'sass:dist']); grunt.registerTask('test', ['qunit', 'jshint']); + grunt.registerTask('ci', ['compile', 'saucelabs-qunit', 'test']); + grunt.registerTask('docs', ['symlink:docs', 'jekyll:serve']); grunt.registerTask('docs-release', ['default', 'clean:docs', 'gh-pages']); diff --git a/package.json b/package.json index fe29eb41..180f7a74 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "grunt-cli": "^0.1.13", "grunt-contrib-clean": "^0.6.0", "grunt-contrib-concat": "^0.4.0", + "grunt-contrib-connect": "^0.9.0", "grunt-contrib-jshint": "^0.10.0", "grunt-contrib-nodeunit": "~0.3.3", "grunt-contrib-qunit": "~0.4.0", @@ -52,6 +53,7 @@ "grunt-gh-pages": "^0.9.1", "grunt-jekyll": "^0.4.2", "grunt-sass": "~0.12.0", + "grunt-saucelabs": "^8.5.0", "node-sass": "~0.8.6" } } diff --git a/src/js/select2/compat/initSelection.js b/src/js/select2/compat/initSelection.js index d6d3ca69..cac869c8 100644 --- a/src/js/select2/compat/initSelection.js +++ b/src/js/select2/compat/initSelection.js @@ -2,7 +2,7 @@ define([ 'jquery' ], function ($) { function InitSelection (decorated, $element, options) { - if (console && console.warn) { + if (window.console && console.warn) { console.warn( 'Select2: The `initSelection` option has been deprecated in favor' + ' of a custom data adapter that overrides the `current` method. ' + diff --git a/src/js/select2/compat/query.js b/src/js/select2/compat/query.js index a6ad669f..88a0b3b9 100644 --- a/src/js/select2/compat/query.js +++ b/src/js/select2/compat/query.js @@ -2,7 +2,7 @@ define([ ], function () { function Query (decorated, $element, options) { - if (console && console.warn) { + if (window.console && console.warn) { console.warn( 'Select2: The `query` option has been deprecated in favor of a ' + 'custom data adapter that overrides the `query` method. Support ' + diff --git a/src/js/select2/core.js b/src/js/select2/core.js index 411999a8..56b689ee 100644 --- a/src/js/select2/core.js +++ b/src/js/select2/core.js @@ -391,7 +391,7 @@ define([ }; Select2.prototype.enable = function (args) { - if (console && console.warn) { + if (window.console && console.warn) { console.warn( 'Select2: The `select2("enable")` method has been deprecated and will' + ' be removed in later Select2 versions. Use $element.prop("disabled")' + @@ -409,7 +409,7 @@ define([ }; Select2.prototype.data = function () { - if (arguments.length > 0 && console && console.warn) { + if (arguments.length > 0 && window.console && console.warn) { console.warn( 'Select2: Data can no longer be set using `select2("data")`. You ' + 'should consider setting the value instead using `$element.val()`.' @@ -426,7 +426,7 @@ define([ }; Select2.prototype.val = function (args) { - if (console && console.warn) { + if (window.console && console.warn) { console.warn( 'Select2: The `select2("val")` method has been deprecated and will be' + ' removed in later Select2 versions. Use $element.val() instead.' diff --git a/src/js/select2/data/ajax.js b/src/js/select2/data/ajax.js index 3c24643b..3a1af16a 100644 --- a/src/js/select2/data/ajax.js +++ b/src/js/select2/data/ajax.js @@ -64,7 +64,7 @@ define([ var $request = options.transport(options, function (data) { var results = self.processResults(data, params); - if (console && console.error) { + if (window.console && console.error) { // Check to make sure that the response included a `results` key. if (!results || !results.results || !$.isArray(results.results)) { console.error( diff --git a/src/js/select2/defaults.js b/src/js/select2/defaults.js index 74d4810e..d23e6301 100644 --- a/src/js/select2/defaults.js +++ b/src/js/select2/defaults.js @@ -237,7 +237,7 @@ define([ // The translation could not be loaded at all. Sometimes this is // because of a configuration problem, other times this can be // because of how Select2 helps load all possible translation files. - if (console && console.warn) { + if (window.console && console.warn) { console.warn( 'Select2: The lanugage file for "' + name + '" could not be ' + 'automatically loaded. A fallback will be used instead.' diff --git a/src/js/select2/options.js b/src/js/select2/options.js index f57ae80a..adbf4b0c 100644 --- a/src/js/select2/options.js +++ b/src/js/select2/options.js @@ -46,7 +46,7 @@ define([ $e.prop('multiple', this.options.multiple); if ($e.data('select2-tags')) { - if (console && console.warn) { + if (window.console && console.warn) { console.warn( 'Select2: The `data-select2-tags` attribute has been changed to ' + 'use the `data-data` and `data-tags="true"` attributes and will be ' + @@ -59,7 +59,7 @@ define([ } if ($e.data('ajax-url')) { - if (console && console.warn) { + if (window.console && console.warn) { console.warn( 'Select2: The `data-ajax-url` attribute has been changed to ' + '`data-ajax--url` and support for the old attribute will be removed' + diff --git a/src/js/select2/selection/allowClear.js b/src/js/select2/selection/allowClear.js index 52ab3866..e0794ecf 100644 --- a/src/js/select2/selection/allowClear.js +++ b/src/js/select2/selection/allowClear.js @@ -9,7 +9,7 @@ define([ decorated.call(this, container, $container); if (self.placeholder == null) { - if (console && console.error) { + if (window.console && console.error) { console.error( 'Select2: The `allowClear` option should be used in combination ' + 'with the `placeholder` option.' diff --git a/tests/helpers.js b/tests/helpers.js index 16fc3297..e0c9fa22 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -16,3 +16,31 @@ Utils.Extend(MockContainer, Utils.Observable); MockContainer.prototype.isOpen = function () { return this.isOpen; }; + +var log = []; +var testName; + +QUnit.done(function (test_results) { + var tests = []; + for(var i = 0, len = log.length; i < len; i++) { + var details = log[i]; + tests.push({ + name: details.name, + result: details.result, + expected: details.expected, + actual: details.actual, + source: details.source + }); + } + test_results.tests = tests; + + window.global_test_results = test_results; +}); +QUnit.testStart(function(testDetails){ + QUnit.log(function(details){ + if (!details.result) { + details.name = testDetails.name; + log.push(details); + } + }); +});