Skip to content

Commit

Permalink
Hook up with SauceLabs
Browse files Browse the repository at this point in the history
This sets up Select2 to be able to run tests on the SauceLabs
environment. This will allow us to run the tests on different
browsers in the future, though at the moment we need to start
combining test files.

This required adding a snippet of code for reporting QUnit test
results to SauceLabs within the global test helper file.

The tests currently cannot be run on IE 8 because all of the tests
are using jQuery 2.x, which is not compatible.
  • Loading branch information
kevin-brown committed Feb 14, 2015
1 parent d51570e commit a0c26e1
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 14 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
62 changes: 59 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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',
Expand All @@ -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': {
Expand Down Expand Up @@ -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');
Expand All @@ -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']);
Expand All @@ -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']);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/js/select2/compat/initSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. ' +
Expand Down
2 changes: 1 addition & 1 deletion src/js/select2/compat/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down
6 changes: 3 additions & 3 deletions src/js/select2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")' +
Expand All @@ -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()`.'
Expand All @@ -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.'
Expand Down
2 changes: 1 addition & 1 deletion src/js/select2/data/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/js/select2/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
4 changes: 2 additions & 2 deletions src/js/select2/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand All @@ -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' +
Expand Down
2 changes: 1 addition & 1 deletion src/js/select2/selection/allowClear.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
28 changes: 28 additions & 0 deletions tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});

0 comments on commit a0c26e1

Please sign in to comment.