js-cookie 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/node.js DELETED
@@ -1,29 +0,0 @@
1
- /*jshint node:true */
2
- exports.node = {
3
- should_load_js_cookie: function (test) {
4
- test.expect(1);
5
- var Cookies = require('../src/js.cookie');
6
- test.ok(!!Cookies.get, 'should load the Cookies API');
7
- test.done();
8
- },
9
- should_not_throw_error_for_set_call_in_node: function (test) {
10
- test.expect(0);
11
- var Cookies = require('../src/js.cookie');
12
- Cookies.set('anything');
13
- Cookies.set('anything', { path: '' });
14
- test.done();
15
- },
16
- should_not_throw_error_for_get_call_in_node: function (test) {
17
- test.expect(0);
18
- var Cookies = require('../src/js.cookie');
19
- Cookies.get('anything');
20
- test.done();
21
- },
22
- should_not_throw_error_for_remove_call_in_node: function (test) {
23
- test.expect(0);
24
- var Cookies = require('../src/js.cookie');
25
- Cookies.remove('anything');
26
- Cookies.remove('anything', { path: '' });
27
- test.done();
28
- }
29
- };
package/test/polyfill.js DELETED
@@ -1,11 +0,0 @@
1
- // Object.keys()
2
- // developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
3
- Object.keys||(Object.keys=function(){"use strict";var a=Object.prototype.hasOwnProperty,b=!{toString:null}.propertyIsEnumerable("toString"),c=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],d=c.length;return function(e){if("object"!=typeof e&&("function"!=typeof e||null===e))throw new TypeError("Object.keys called on non-object");var g,h,f=[];for(g in e)a.call(e,g)&&f.push(g);if(b)for(h=0;d>h;h++)a.call(e,c[h])&&f.push(c[h]);return f}}());
4
-
5
- // Array.forEach()
6
- // developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
7
- Array.prototype.forEach||(Array.prototype.forEach=function(a,b){var c,d;if(null==this)throw new TypeError(" this is null or not defined");var e=Object(this),f=e.length>>>0;if("function"!=typeof a)throw new TypeError(a+" is not a function");for(arguments.length>1&&(c=b),d=0;f>d;){var g;d in e&&(g=e[d],a.call(c,g,d,e)),d++}});
8
-
9
- // JSON
10
- // github.com/douglascrockford/JSON-js/tree/c07c287e39ab5a1726818e0436490bf071b7c838
11
- "object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(a){return 10>a?"0"+a:a}function this_value(){return this.valueOf()}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,h,g=gap,i=b[a];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,h=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;f>c;c+=1)h[c]=str(c,i)||"null";return e=0===h.length?"[]":gap?"[\n"+gap+h.join(",\n"+gap)+"\n"+g+"]":"["+h.join(",")+"]",gap=g,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;f>c;c+=1)"string"==typeof rep[c]&&(d=rep[c],e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e));return e=0===h.length?"{}":gap?"{\n"+gap+h.join(",\n"+gap)+"\n"+g+"}":"{"+h.join(",")+"}",gap=g,e}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},Boolean.prototype.toJSON=this_value,Number.prototype.toJSON=this_value,String.prototype.toJSON=this_value);var cx,escapable,gap,indent,meta,rep;"function"!=typeof JSON.stringify&&(escapable=/[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},JSON.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;c>d;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})}),"function"!=typeof JSON.parse&&(cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}();
package/test/tests.js DELETED
@@ -1,403 +0,0 @@
1
- /*global lifecycle: true*/
2
-
3
- QUnit.module('read', lifecycle);
4
-
5
- QUnit.test('simple value', function (assert) {
6
- assert.expect(1);
7
- document.cookie = 'c=v';
8
- assert.strictEqual(Cookies.get('c'), 'v', 'should return value');
9
- });
10
-
11
- QUnit.test('empty value', function (assert) {
12
- assert.expect(1);
13
- // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, which
14
- // resulted in a bug while reading such a cookie.
15
- Cookies.set('c', '');
16
- assert.strictEqual(Cookies.get('c'), '', 'should return value');
17
- });
18
-
19
- QUnit.test('not existing', function (assert) {
20
- assert.expect(1);
21
- assert.strictEqual(Cookies.get('whatever'), undefined, 'return undefined');
22
- });
23
-
24
- // github.com/carhartl/jquery-cookie/issues/50
25
- QUnit.test('equality sign in cookie value', function (assert) {
26
- assert.expect(1);
27
- Cookies.set('c', 'foo=bar');
28
- assert.strictEqual(Cookies.get('c'), 'foo=bar', 'should include the entire value');
29
- });
30
-
31
- // github.com/carhartl/jquery-cookie/issues/215
32
- QUnit.test('percent character in cookie value', function (assert) {
33
- assert.expect(1);
34
- document.cookie = 'bad=foo%';
35
- assert.strictEqual(Cookies.get('bad'), 'foo%', 'should read the percent character');
36
- });
37
-
38
- QUnit.test('percent character in cookie value mixed with encoded values', function (assert) {
39
- assert.expect(1);
40
- document.cookie = 'bad=foo%bar%22baz%bax%3D';
41
- assert.strictEqual(Cookies.get('bad'), 'foo%bar"baz%bax=', 'should read the percent character');
42
- });
43
-
44
- // github.com/carhartl/jquery-cookie/pull/88
45
- // github.com/carhartl/jquery-cookie/pull/117
46
- QUnit.test('malformed cookie value in IE', function (assert) {
47
- assert.expect(1);
48
- var done = assert.async();
49
- // Sandbox in an iframe so that we can poke around with document.cookie.
50
- var iframe = document.createElement('iframe');
51
- iframe.src = 'malformed_cookie.html';
52
- addEvent(iframe, 'load', function () {
53
- if (iframe.contentWindow.ok) {
54
- assert.strictEqual(iframe.contentWindow.testValue, 'two', 'reads all cookie values, skipping duplicate occurences of "; "');
55
- } else {
56
- // Skip the test where we can't stub document.cookie using
57
- // Object.defineProperty. Seems to work fine in
58
- // Chrome, Firefox and IE 8+.
59
- assert.ok(true, 'N/A');
60
- }
61
- done();
62
- });
63
- document.body.appendChild(iframe);
64
- });
65
-
66
- // github.com/js-cookie/js-cookie/pull/171
67
- QUnit.test('missing leading semicolon', function (assert) {
68
- assert.expect(1);
69
- var done = assert.async();
70
- // Sandbox in an iframe so that we can poke around with document.cookie.
71
- var iframe = document.createElement('iframe');
72
- var loadedSuccessfully = true;
73
- iframe.src = 'missing_semicolon.html';
74
-
75
- addEvent(iframe, 'load', function () {
76
- iframe.contentWindow.onerror = function () {
77
- loadedSuccessfully = false;
78
- };
79
- assert.strictEqual(loadedSuccessfully, true, 'can\'t throw Object is not a function error');
80
- done();
81
- });
82
- document.body.appendChild(iframe);
83
- });
84
-
85
- QUnit.test('Call to read all when there are cookies', function (assert) {
86
- Cookies.set('c', 'v');
87
- Cookies.set('foo', 'bar');
88
- assert.deepEqual(Cookies.get(), { c: 'v', foo: 'bar' }, 'returns object containing all cookies');
89
- });
90
-
91
- QUnit.test('Call to read all when there are no cookies at all', function (assert) {
92
- assert.deepEqual(Cookies.get(), {}, 'returns empty object');
93
- });
94
-
95
- QUnit.test('RFC 6265 - reading cookie-octet enclosed in DQUOTE', function (assert) {
96
- assert.expect(1);
97
- document.cookie = 'c="v"';
98
- assert.strictEqual(Cookies.get('c'), 'v', 'should simply ignore quoted strings');
99
- });
100
-
101
- // github.com/js-cookie/js-cookie/pull/62
102
- QUnit.test('Call to read cookie when there is another unrelated cookie with malformed encoding in the value', function (assert) {
103
- assert.expect(2);
104
- document.cookie = 'invalid=%A1';
105
- document.cookie = 'c=v';
106
- assert.strictEqual(Cookies.get('c'), 'v', 'should not throw a URI malformed exception when retrieving a single cookie');
107
- assert.deepEqual(Cookies.get(), { c: 'v' }, 'should not throw a URI malformed exception when retrieving all cookies');
108
- Cookies.withConverter(unescape).remove('invalid');
109
- });
110
-
111
- // github.com/js-cookie/js-cookie/issues/145
112
- QUnit.test('Call to read cookie when passing an Object Literal as the second argument', function (assert) {
113
- assert.expect(1);
114
- Cookies.get('name', { path: '' });
115
- assert.strictEqual(document.cookie, '', 'should not create a cookie');
116
- });
117
-
118
- QUnit.module('write', lifecycle);
119
-
120
- QUnit.test('String primitive', function (assert) {
121
- assert.expect(1);
122
- Cookies.set('c', 'v');
123
- assert.strictEqual(Cookies.get('c'), 'v', 'should write value');
124
- });
125
-
126
- QUnit.test('String object', function (assert) {
127
- assert.expect(1);
128
- Cookies.set('c', new String('v'));
129
- assert.strictEqual(Cookies.get('c'), 'v', 'should write value');
130
- });
131
-
132
- QUnit.test('value "[object Object]"', function (assert) {
133
- assert.expect(1);
134
- Cookies.set('c', '[object Object]');
135
- assert.strictEqual(Cookies.get('c'), '[object Object]', 'should write value');
136
- });
137
-
138
- QUnit.test('number', function (assert) {
139
- assert.expect(1);
140
- Cookies.set('c', 1234);
141
- assert.strictEqual(Cookies.get('c'), '1234', 'should write value');
142
- });
143
-
144
- QUnit.test('null', function (assert) {
145
- assert.expect(1);
146
- Cookies.set('c', null);
147
- assert.strictEqual(Cookies.get('c'), 'null', 'should write value');
148
- });
149
-
150
- QUnit.test('undefined', function (assert) {
151
- assert.expect(1);
152
- Cookies.set('c', undefined);
153
- assert.strictEqual(Cookies.get('c'), 'undefined', 'should write value');
154
- });
155
-
156
- QUnit.test('expires option as days from now', function (assert) {
157
- assert.expect(1);
158
- var sevenDaysFromNow = new Date();
159
- sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 21);
160
- var expected = 'c=v; expires=' + sevenDaysFromNow.toUTCString();
161
- var actual = Cookies.set('c', 'v', { expires: 21 }).substring(0, expected.length);
162
- assert.strictEqual(actual, expected, 'should write the cookie string with expires');
163
- });
164
-
165
- QUnit.test('expires option as fraction of a day', function (assert) {
166
- assert.expect(1);
167
-
168
- var now = new Date().getTime();
169
- var stringifiedDate = Cookies.set('c', 'v', { expires: 0.5 }).split('; ')[1].split('=')[1];
170
- var expires = Date.parse(stringifiedDate);
171
-
172
- // When we were using Date.setDate() fractions have been ignored
173
- // and expires resulted in the current date. Allow 1000 milliseconds
174
- // difference for execution time.
175
- assert.ok(expires > now + 1000, 'should write expires attribute with the correct date');
176
- });
177
-
178
- QUnit.test('expires option as Date instance', function (assert) {
179
- assert.expect(1);
180
- var sevenDaysFromNow = new Date();
181
- sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7);
182
- var expected = 'c=v; expires=' + sevenDaysFromNow.toUTCString();
183
- var actual = Cookies.set('c', 'v', { expires: sevenDaysFromNow }).substring(0, expected.length);
184
- assert.strictEqual(actual, expected, 'should write the cookie string with expires');
185
- });
186
-
187
- QUnit.test('return value', function (assert) {
188
- assert.expect(1);
189
- var expected = 'c=v';
190
- var actual = Cookies.set('c', 'v').substring(0, expected.length);
191
- assert.strictEqual(actual, expected, 'should return written cookie string');
192
- });
193
-
194
- QUnit.test('default path attribute', function (assert) {
195
- assert.expect(1);
196
- assert.ok(Cookies.set('c', 'v').match(/path=\//), 'should read the default path');
197
- });
198
-
199
- QUnit.test('API for changing defaults', function (assert) {
200
- assert.expect(3);
201
-
202
- Cookies.defaults.path = '/foo';
203
- assert.ok(Cookies.set('c', 'v').match(/path=\/foo/), 'should use attributes from defaults');
204
- Cookies.remove('c', { path: '/foo' });
205
-
206
- assert.ok(Cookies.set('c', 'v', { path: '/bar' }).match(/path=\/bar/), 'attributes argument has precedence');
207
- Cookies.remove('c', { path: '/bar' });
208
-
209
- delete Cookies.defaults.path;
210
- assert.ok(Cookies.set('c', 'v').match(/path=\//), 'should roll back to the default path');
211
- });
212
-
213
- // github.com/js-cookie/js-cookie/pull/54
214
- QUnit.test('false secure value', function (assert) {
215
- assert.expect(1);
216
- var expected = 'c=v; path=/';
217
- var actual = Cookies.set('c', 'v', {secure: false});
218
- assert.strictEqual(actual, expected, 'false should not modify path in cookie string');
219
- });
220
-
221
- QUnit.test('undefined attribute value', function (assert) {
222
- assert.expect(4);
223
- assert.strictEqual(Cookies.set('c', 'v', {
224
- expires: undefined
225
- }), 'c=v; path=/', 'should not write undefined expires attribute');
226
- assert.strictEqual(Cookies.set('c', 'v', {
227
- path: undefined
228
- }), 'c=v', 'should not write undefined path attribute');
229
- assert.strictEqual(Cookies.set('c', 'v', {
230
- domain: undefined
231
- }), 'c=v; path=/', 'should not write undefined domain attribute');
232
- assert.strictEqual(Cookies.set('c', 'v', {
233
- secure: undefined
234
- }), 'c=v; path=/', 'should not write undefined secure attribute');
235
- });
236
-
237
- QUnit.module('remove', lifecycle);
238
-
239
- QUnit.test('deletion', function (assert) {
240
- assert.expect(1);
241
- Cookies.set('c', 'v');
242
- Cookies.remove('c');
243
- assert.strictEqual(document.cookie, '', 'should delete the cookie');
244
- });
245
-
246
- QUnit.test('with attributes', function (assert) {
247
- assert.expect(1);
248
- var attributes = { path: '/' };
249
- Cookies.set('c', 'v', attributes);
250
- Cookies.remove('c', attributes);
251
- assert.strictEqual(document.cookie, '', 'should delete the cookie');
252
- });
253
-
254
- QUnit.test('passing attributes reference', function (assert) {
255
- assert.expect(1);
256
- var attributes = { path: '/' };
257
- Cookies.set('c', 'v', attributes);
258
- Cookies.remove('c', attributes);
259
- assert.deepEqual(attributes, { path: '/' }, 'won\'t alter attributes object');
260
- });
261
-
262
- QUnit.module('converters', lifecycle);
263
-
264
- // github.com/carhartl/jquery-cookie/pull/166
265
- QUnit.test('provide a way for decoding characters encoded by the escape function', function (assert) {
266
- assert.expect(1);
267
- document.cookie = 'c=%u5317%u4eac';
268
- assert.strictEqual(Cookies.withConverter(unescape).get('c'), '北京', 'should convert chinese characters correctly');
269
- });
270
-
271
- QUnit.test('should decode a malformed char that matches the decodeURIComponent regex', function (assert) {
272
- assert.expect(1);
273
- document.cookie = 'c=%E3';
274
- var cookies = Cookies.withConverter(unescape);
275
- assert.strictEqual(cookies.get('c'), 'ã', 'should convert the character correctly');
276
- cookies.remove('c', {
277
- path: ''
278
- });
279
- });
280
-
281
- QUnit.test('should be able to conditionally decode a single malformed cookie', function (assert) {
282
- assert.expect(4);
283
- var cookies = Cookies.withConverter(function (value, name) {
284
- if (name === 'escaped') {
285
- return unescape(value);
286
- }
287
- });
288
-
289
- document.cookie = 'escaped=%u5317';
290
- assert.strictEqual(cookies.get('escaped'), '北', 'should use a custom method for escaped cookie');
291
-
292
- document.cookie = 'encoded=%E4%BA%AC';
293
- assert.strictEqual(cookies.get('encoded'), '京', 'should use the default encoding for the rest');
294
-
295
- assert.deepEqual(cookies.get(), {
296
- escaped: '北',
297
- encoded: '京'
298
- }, 'should retrieve everything');
299
-
300
- Object.keys(cookies.get()).forEach(function (name) {
301
- cookies.remove(name, {
302
- path: ''
303
- });
304
- });
305
- assert.strictEqual(document.cookie, '', 'should remove everything');
306
- });
307
-
308
- // github.com/js-cookie/js-cookie/issues/70
309
- QUnit.test('should be able to create a write decoder', function (assert) {
310
- assert.expect(1);
311
- Cookies.withConverter({
312
- write: function (value) {
313
- return value.replace('+', '%2B');
314
- }
315
- }).set('c', '+');
316
- assert.strictEqual(document.cookie, 'c=%2B', 'should call the write converter');
317
- });
318
-
319
- QUnit.test('should be able to use read and write decoder', function (assert) {
320
- assert.expect(1);
321
- document.cookie = 'c=%2B';
322
- var cookies = Cookies.withConverter({
323
- read: function (value) {
324
- return value.replace('%2B', '+');
325
- }
326
- });
327
- assert.strictEqual(cookies.get('c'), '+', 'should call the read converter');
328
- });
329
-
330
- QUnit.module('JSON handling', lifecycle);
331
-
332
- QUnit.test('Number', function (assert) {
333
- assert.expect(2);
334
- Cookies.set('c', 1);
335
- assert.strictEqual(Cookies.getJSON('c'), 1, 'should handle a Number');
336
- assert.strictEqual(Cookies.get('c'), '1', 'should return a String');
337
- });
338
-
339
- QUnit.test('Boolean', function (assert) {
340
- assert.expect(2);
341
- Cookies.set('c', true);
342
- assert.strictEqual(Cookies.getJSON('c'), true, 'should handle a Boolean');
343
- assert.strictEqual(Cookies.get('c'), 'true', 'should return a Boolean');
344
- });
345
-
346
- QUnit.test('Array Literal', function (assert) {
347
- assert.expect(2);
348
- Cookies.set('c', ['v']);
349
- assert.deepEqual(Cookies.getJSON('c'), ['v'], 'should handle Array Literal');
350
- assert.strictEqual(Cookies.get('c'), '["v"]', 'should return a String');
351
- });
352
-
353
- QUnit.test('Array Constructor', function (assert) {
354
- /*jshint -W009 */
355
- assert.expect(2);
356
- var value = new Array();
357
- value[0] = 'v';
358
- Cookies.set('c', value);
359
- assert.deepEqual(Cookies.getJSON('c'), ['v'], 'should handle Array Constructor');
360
- assert.strictEqual(Cookies.get('c'), '["v"]', 'should return a String');
361
- });
362
-
363
- QUnit.test('Object Literal', function (assert) {
364
- assert.expect(2);
365
- Cookies.set('c', {k: 'v'});
366
- assert.deepEqual(Cookies.getJSON('c'), {k: 'v'}, 'should handle Object Literal');
367
- assert.strictEqual(Cookies.get('c'), '{"k":"v"}', 'should return a String');
368
- });
369
-
370
- QUnit.test('Object Constructor', function (assert) {
371
- /*jshint -W010 */
372
- assert.expect(2);
373
- var value = new Object();
374
- value.k = 'v';
375
- Cookies.set('c', value);
376
- assert.deepEqual(Cookies.getJSON('c'), {k: 'v'}, 'should handle Object Constructor');
377
- assert.strictEqual(Cookies.get('c'), '{"k":"v"}', 'should return a String');
378
- });
379
-
380
- QUnit.test('Use String(value) for unsupported objects that do not stringify into JSON', function (assert) {
381
- assert.expect(2);
382
- Cookies.set('date', new Date(2015, 04, 13, 0, 0, 0, 0));
383
- assert.strictEqual(Cookies.get('date').indexOf('"'), -1, 'should not quote the stringified Date object');
384
- assert.strictEqual(Cookies.getJSON('date').indexOf('"'), -1, 'should not quote the stringified Date object');
385
- });
386
-
387
- QUnit.test('Call to read all cookies with mixed json', function (assert) {
388
- Cookies.set('c', { foo: 'bar' });
389
- Cookies.set('c2', 'v');
390
- assert.deepEqual(Cookies.getJSON(), { c: { foo: 'bar' }, c2: 'v' }, 'returns JSON parsed cookies');
391
- assert.deepEqual(Cookies.get(), { c: '{"foo":"bar"}', c2: 'v' }, 'returns unparsed cookies');
392
- });
393
-
394
- QUnit.module('noConflict', lifecycle);
395
-
396
- QUnit.test('do not conflict with existent globals', function (assert) {
397
- assert.expect(2);
398
- var Cookies = window.Cookies.noConflict();
399
- Cookies.set('c', 'v');
400
- assert.strictEqual(Cookies.get('c'), 'v', 'should work correctly');
401
- assert.strictEqual(window.Cookies, 'existent global', 'should restore the original global');
402
- window.Cookies = Cookies;
403
- });
package/test/utils.js DELETED
@@ -1,122 +0,0 @@
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
- });
25
-
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
-
35
- window.lifecycle = {
36
- afterEach: function () {
37
- // Remove the cookies created using js-cookie default attributes
38
- Object.keys(Cookies.get()).forEach(Cookies.remove);
39
- // Remove the cookies created using browser default attributes
40
- Object.keys(Cookies.get()).forEach(function (cookie) {
41
- Cookies.remove(cookie, {
42
- path: ''
43
- });
44
- });
45
- }
46
- };
47
-
48
- window.addEvent = function (element, eventName, fn) {
49
- var method = 'addEventListener';
50
- if (element.attachEvent) {
51
- eventName = 'on' + eventName;
52
- method = 'attachEvent';
53
- }
54
- element[ method ](eventName, fn);
55
- };
56
-
57
- window.using = function (assert) {
58
- function getQuery(key) {
59
- var queries = location.href.split('?')[1];
60
- if (!queries) {
61
- return;
62
- }
63
- var pairs = queries.split(/&|=/);
64
- var indexBaseURL = pairs.indexOf(key);
65
- var result = pairs[indexBaseURL + 1];
66
- if (result) {
67
- return decodeURIComponent(result);
68
- }
69
- }
70
- function setCookie(name, value) {
71
- return {
72
- then: function (callback) {
73
- var iframe = document.getElementById('request_target');
74
- var serverURL = getQuery('integration_baseurl');
75
- Cookies.set(name, value);
76
- if (!serverURL) {
77
- callback(Cookies.get(name), document.cookie);
78
- } else {
79
- var requestURL = [
80
- serverURL,
81
- 'encoding?',
82
- 'name=' + encodeURIComponent(name),
83
- '&value=' + encodeURIComponent(value)
84
- ].join('');
85
- var done = assert.async();
86
- addEvent(iframe, 'load', function () {
87
- var iframeDocument = iframe.contentWindow.document;
88
- var root = iframeDocument.documentElement;
89
- var content = root.textContent;
90
- if (!content) {
91
- ok(false, [
92
- '"' + requestURL + '"',
93
- 'content should not be empty'
94
- ].join(' '));
95
- done();
96
- return;
97
- }
98
- try {
99
- var result = JSON.parse(content);
100
- callback(result.value, iframeDocument.cookie);
101
- } finally {
102
- done();
103
- }
104
- });
105
- iframe.src = requestURL;
106
- }
107
- }
108
- };
109
- }
110
- return {
111
- setCookie: setCookie
112
- };
113
- };
114
-
115
- window.loadFileSync = function (path) {
116
- var xhr = new XMLHttpRequest();
117
- xhr.open('GET', path, false);
118
- xhr.send(null);
119
- return xhr.status === 200 ? xhr.responseText : null;
120
- };
121
-
122
- }());
package/travis.sh DELETED
@@ -1,6 +0,0 @@
1
- #!/bin/bash
2
- if [ -z "$SAUCE_ACCESS_KEY" ]; then
3
- npm test
4
- else
5
- grunt ci --verbose
6
- fi