Skip to content

Commit f371099

Browse files
Fix sauce test failures for IE 8
* IE8 needs "rel" attribute in the link declaration * Add polyfills for IE8 missing features, like Object.keys and Array.forEach * Create custom "addEvent()" function
1 parent 173e2f3 commit f371099

5 files changed

Lines changed: 145 additions & 11 deletions

File tree

‎.travis.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ before_script:
55
- npm install -g grunt-cli
66
script: grunt ci --verbose
77
env:
8+
# Encrypted SAUCE_USERNAME and SAUCE_ACCESS_KEY used by travis
89
global:
9-
- secure: HRae0kyIDDuhonvMi2SfEl1WJb4K/wX8WmzT9YkxFbmWwLjiOMkmqyuEyi76DbTC1cb9o7WwGVgbP1DhSm6n6m0Lz+PSzpprBN4QZuJc56jcc+tBA6gM81hyUufaTT0yUWz112Bu06kWIAs44w5PtG0FYZR0CuIN8fQvZi8fXCQ=
10-
- secure: c+M5ECIfxDcVrr+ZlqgpGjv8kVM/hxiz3ACMCn4ZkDiaeq4Rw0wWIGZYL6aV5fhsoHgzEQ/XQPca8xKs3Umr7R3b6Vr3AEyFnW+LP67K/1Qbz4Pi3PvhDH/h4rvK7fOoTqTDCVVDEH3v4pefsz2VaKemG4iBKxrcof5aR4Rjopk=
10+
- secure: L9cF+B5WiIQyVLWswbl1d7nE+jZIQTQAPiMRwbzvLbFTkUaY9PS9qbdBcVURO/TJSEmXOV6rypMmoFdhAUPmBzlQc5Xe6eZdQmSTPafA78Yf56xBmlCqQWban1cKA7hvPs5IJfIJD7x6FrRl0SiuHFwBz3PGSKCqQgfYtFv2qDk=
11+
- secure: YTvbZ17foXbk1MpykaD0q1h1JO5PGo16Vnb9gLkR+whVONrzZicgXc3ztaBWp8zCVeIrWYxLKXRcR4QNJxwiyAzF4hm4dXU53cQdqq8iiSK0RfpB6bATPoySrGUycVs8dDRaxKLM3GIfVhf1Cw6DRUNl40vtzy7POy9EBMTHsH4=

‎Gruntfile.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ module.exports = function (grunt) {
6767
all: {
6868
options: {
6969
urls: ['http://127.0.0.1:9999'],
70+
testname: 'Sauce Test for js-cookie',
7071
build: process.env.TRAVIS_JOB_ID,
7172
browsers: [
7273
// iOS

‎test/index.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
<head>
44
<meta charset="utf-8">
55
<title>Javascript Cookie Test Suite</title>
6-
<link href="http://code.jquery.com/qunit/qunit-1.14.0.css">
6+
<link href="http://code.jquery.com/qunit/qunit-1.14.0.css" rel="stylesheet">
77
<script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
88
<script src="../src/js.cookie.js"></script>
9+
<script src="polyfill.js"></script>
910
<script src="tests.js"></script>
1011
</head>
1112
<body>

‎test/polyfill.js‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
2+
Object.keys = Object.keys || (function() {
3+
'use strict';
4+
var hasOwnProperty = Object.prototype.hasOwnProperty,
5+
hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
6+
dontEnums = [
7+
'toString',
8+
'toLocaleString',
9+
'valueOf',
10+
'hasOwnProperty',
11+
'isPrototypeOf',
12+
'propertyIsEnumerable',
13+
'constructor'
14+
],
15+
dontEnumsLength = dontEnums.length;
16+
17+
return function(obj) {
18+
if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
19+
throw new TypeError('Object.keys called on non-object');
20+
}
21+
22+
var result = [], prop, i;
23+
24+
for (prop in obj) {
25+
if (hasOwnProperty.call(obj, prop)) {
26+
result.push(prop);
27+
}
28+
}
29+
30+
if (hasDontEnumBug) {
31+
for (i = 0; i < dontEnumsLength; i++) {
32+
if (hasOwnProperty.call(obj, dontEnums[i])) {
33+
result.push(dontEnums[i]);
34+
}
35+
}
36+
}
37+
return result;
38+
};
39+
}());
40+
41+
// Reproducing steps of ECMA-262, Edition 5, 15.4.4.18
42+
// Reference: http://es5.github.com/#x15.4.4.18
43+
Array.prototype.forEach = Array.prototype.forEach || function( callback, thisArg ) {
44+
45+
var T, k;
46+
47+
if ( this === null || this === undefined ) {
48+
throw new TypeError( "this is null or not defined" );
49+
}
50+
51+
// 1. Let O be the result of calling ToObject passing the |this| value as the argument.
52+
var O = Object(this);
53+
54+
// 2. Let lenValue be the result of calling the Get internal method of O with the argument
55+
// "length".
56+
// 3. Let len be ToUint32(lenValue).
57+
var len = O.length >>> 0; // Hack to convert O.length to a UInt32
58+
59+
// 4. If IsCallable(callback) is false, throw a TypeError exception.
60+
// See: http://es5.github.com/#x9.11
61+
if ( {}.toString.call(callback) !== "[object Function]" ) {
62+
throw new TypeError( callback + " is not a function" );
63+
}
64+
65+
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
66+
if ( thisArg ) {
67+
T = thisArg;
68+
}
69+
70+
// 6. Let k be 0
71+
k = 0;
72+
73+
// 7. Repeat, while k < len
74+
while( k < len ) {
75+
76+
var kValue;
77+
78+
// a. Let Pk be ToString(k).
79+
// This is implicit for LHS operands of the in operator
80+
// b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
81+
// This step can be combined with c
82+
// c. If kPresent is true, then
83+
if ( Object.prototype.hasOwnProperty.call(O, k) ) {
84+
85+
// i. Let kValue be the result of calling the Get internal method of O with argument Pk.
86+
kValue = O[ k ];
87+
88+
// ii. Call the Call internal method of callback with T as the this value and
89+
// argument list containing kValue, k, and O.
90+
callback.call( T, kValue, k, O );
91+
}
92+
// d. Increase k by 1.
93+
k++;
94+
}
95+
// 8. return undefined
96+
};

‎test/tests.js‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
1-
// Required for exposing test results to the Sauce Labs API.
2-
// Can be removed when the following issue is fixed:
3-
// https://github.com/axemclion/grunt-saucelabs/issues/84
4-
QUnit.done(function (details) {
5-
window.global_test_results = details;
6-
});
1+
// https://github.com/axemclion/grunt-saucelabs#test-result-details-with-qunit
2+
(function() {
3+
"use strict";
4+
5+
var log = [];
6+
7+
QUnit.done(function (test_results) {
8+
var tests = [];
9+
for (var i = 0, len = log.length; i < len; i++) {
10+
var details = log[i];
11+
tests.push({
12+
name: details.name,
13+
result: details.result,
14+
expected: details.expected,
15+
actual: details.actual,
16+
source: details.source
17+
});
18+
}
19+
test_results.tests = tests;
20+
// Required for exposing test results to the Sauce Labs API.
21+
// Can be removed when the following issue is fixed:
22+
// https://github.com/axemclion/grunt-saucelabs/issues/84
23+
window.global_test_results = test_results;
24+
});
725

26+
QUnit.testStart(function (testDetails) {
27+
QUnit.log(function (details) {
28+
if (!details.result) {
29+
details.name = testDetails.name;
30+
log.push(details);
31+
}
32+
});
33+
});
34+
}());
835

936
var lifecycle = {
1037
teardown: function () {
@@ -127,8 +154,16 @@ asyncTest('malformed cookie value in IE (#88, #117)', function () {
127154
expect(1);
128155
// Sandbox in an iframe so that we can poke around with document.cookie.
129156
var iframe = document.createElement('iframe');
130-
iframe.src = "malformed_cookie.html";
131-
iframe.addEventListener('load', function () {
157+
var addEvent = function (element, eventName, fn) {
158+
var method = "addEventListener";
159+
if (element.attachEvent) {
160+
eventName = 'on' + eventName;
161+
method = "attachEvent";
162+
}
163+
element[ method ](eventName, fn);
164+
};
165+
iframe.src = 'malformed_cookie.html';
166+
addEvent(iframe, 'load', function () {
132167
start();
133168
if (iframe.contentWindow.ok) {
134169
strictEqual(iframe.contentWindow.testValue, 'two', 'reads all cookie values, skipping duplicate occurences of "; "');

0 commit comments

Comments
 (0)