js-cookie 2.1.4 → 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.
@@ -1,17 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title></title>
5
- <script src="../build/js.cookie.min.js"></script>
6
- <script>
7
- try {
8
- Object.defineProperty(document, "cookie", { get: function() { return "first=one; ; second=two"; } });
9
- window.testValue = Cookies.get("second");
10
- window.ok = true;
11
- } catch (er) {
12
- }
13
- </script>
14
- </head>
15
- <body>
16
- </body>
17
- </html>
@@ -1,24 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title></title>
6
- <link href="../node_modules/qunitjs/qunit/qunit.css" rel="stylesheet">
7
- <script src="../node_modules/qunitjs/qunit/qunit.js"></script>
8
- <script src="utils.js"></script>
9
- <script>
10
- (function() {
11
- var contents = window.loadFileSync('../build/js.cookie.min.js');
12
-
13
- if (contents !== null) {
14
- var script = document.createElement('script');
15
- script.innerHTML = '(function (){ return {}; })() ' + contents;
16
- document.getElementsByTagName('head')[0].appendChild(script);
17
- }
18
- })();
19
- </script>
20
- </head>
21
- <body>
22
-
23
- </body>
24
- </html>
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,463 +0,0 @@
1
- 'use strict';
2
-
3
- /*global lifecycle: true*/
4
-
5
- QUnit.module('read', lifecycle);
6
-
7
- QUnit.test('simple value', function (assert) {
8
- assert.expect(1);
9
- document.cookie = 'c=v';
10
- assert.strictEqual(Cookies.get('c'), 'v', 'should return value');
11
- });
12
-
13
- QUnit.test('empty value', function (assert) {
14
- assert.expect(1);
15
- // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, which
16
- // resulted in a bug while reading such a cookie.
17
- Cookies.set('c', '');
18
- assert.strictEqual(Cookies.get('c'), '', 'should return value');
19
- });
20
-
21
- QUnit.test('not existing', function (assert) {
22
- assert.expect(1);
23
- assert.strictEqual(Cookies.get('whatever'), undefined, 'return undefined');
24
- });
25
-
26
- // github.com/carhartl/jquery-cookie/issues/50
27
- QUnit.test('equality sign in cookie value', function (assert) {
28
- assert.expect(1);
29
- Cookies.set('c', 'foo=bar');
30
- assert.strictEqual(Cookies.get('c'), 'foo=bar', 'should include the entire value');
31
- });
32
-
33
- // github.com/carhartl/jquery-cookie/issues/215
34
- QUnit.test('percent character in cookie value', function (assert) {
35
- assert.expect(1);
36
- document.cookie = 'bad=foo%';
37
- assert.strictEqual(Cookies.get('bad'), 'foo%', 'should read the percent character');
38
- });
39
-
40
- QUnit.test('percent character in cookie value mixed with encoded values', function (assert) {
41
- assert.expect(1);
42
- document.cookie = 'bad=foo%bar%22baz%bax%3D';
43
- assert.strictEqual(Cookies.get('bad'), 'foo%bar"baz%bax=', 'should read the percent character');
44
- });
45
-
46
- // github.com/carhartl/jquery-cookie/pull/88
47
- // github.com/carhartl/jquery-cookie/pull/117
48
- QUnit.test('malformed cookie value in IE', function (assert) {
49
- assert.expect(1);
50
- var done = assert.async();
51
- // Sandbox in an iframe so that we can poke around with document.cookie.
52
- var iframe = document.createElement('iframe');
53
- iframe.src = 'malformed_cookie.html';
54
- addEvent(iframe, 'load', function () {
55
- if (iframe.contentWindow.ok) {
56
- assert.strictEqual(iframe.contentWindow.testValue, 'two', 'reads all cookie values, skipping duplicate occurences of "; "');
57
- } else {
58
- // Skip the test where we can't stub document.cookie using
59
- // Object.defineProperty. Seems to work fine in
60
- // Chrome, Firefox and IE 8+.
61
- assert.ok(true, 'N/A');
62
- }
63
- done();
64
- });
65
- document.body.appendChild(iframe);
66
- });
67
-
68
- // github.com/js-cookie/js-cookie/pull/171
69
- QUnit.test('missing leading semicolon', function (assert) {
70
- assert.expect(1);
71
- var done = assert.async();
72
- // Sandbox in an iframe so that we can poke around with document.cookie.
73
- var iframe = document.createElement('iframe');
74
- var loadedSuccessfully = true;
75
- iframe.src = 'missing_semicolon.html';
76
-
77
- addEvent(iframe, 'load', function () {
78
- iframe.contentWindow.onerror = function () {
79
- loadedSuccessfully = false;
80
- };
81
- assert.strictEqual(loadedSuccessfully, true, 'can\'t throw Object is not a function error');
82
- done();
83
- });
84
- document.body.appendChild(iframe);
85
- });
86
-
87
- QUnit.test('Call to read all when there are cookies', function (assert) {
88
- Cookies.set('c', 'v');
89
- Cookies.set('foo', 'bar');
90
- assert.deepEqual(Cookies.get(), { c: 'v', foo: 'bar' }, 'returns object containing all cookies');
91
- });
92
-
93
- QUnit.test('Call to read all when there are no cookies at all', function (assert) {
94
- assert.deepEqual(Cookies.get(), {}, 'returns empty object');
95
- });
96
-
97
- QUnit.test('RFC 6265 - reading cookie-octet enclosed in DQUOTE', function (assert) {
98
- assert.expect(1);
99
- document.cookie = 'c="v"';
100
- assert.strictEqual(Cookies.get('c'), 'v', 'should simply ignore quoted strings');
101
- });
102
-
103
- // github.com/js-cookie/js-cookie/issues/196
104
- QUnit.test('Call to read cookie when there is another unrelated cookie with malformed encoding in the name', function (assert) {
105
- assert.expect(2);
106
- document.cookie = 'BS%BS=1';
107
- document.cookie = 'c=v';
108
- assert.strictEqual(Cookies.get('c'), 'v', 'should not throw a URI malformed exception when retrieving a single cookie');
109
- assert.deepEqual(Cookies.get(), { c: 'v' }, 'should not throw a URI malformed exception when retrieving all cookies');
110
- document.cookie = 'BS%BS=1; expires=Thu, 01 Jan 1970 00:00:00 GMT';
111
- });
112
-
113
- // github.com/js-cookie/js-cookie/pull/62
114
- QUnit.test('Call to read cookie when there is another unrelated cookie with malformed encoding in the value', function (assert) {
115
- assert.expect(2);
116
- document.cookie = 'invalid=%A1';
117
- document.cookie = 'c=v';
118
- assert.strictEqual(Cookies.get('c'), 'v', 'should not throw a URI malformed exception when retrieving a single cookie');
119
- assert.deepEqual(Cookies.get(), { c: 'v' }, 'should not throw a URI malformed exception when retrieving all cookies');
120
- Cookies.withConverter(unescape).remove('invalid');
121
- });
122
-
123
- // github.com/js-cookie/js-cookie/issues/145
124
- QUnit.test('Call to read cookie when passing an Object Literal as the second argument', function (assert) {
125
- assert.expect(1);
126
- Cookies.get('name', { path: '' });
127
- assert.strictEqual(document.cookie, '', 'should not create a cookie');
128
- });
129
-
130
- // github.com/js-cookie/js-cookie/issues/238
131
- QUnit.test('Call to read cookie when there is a window.json variable globally', function (assert) {
132
- assert.expect(1);
133
- window.json = true;
134
- Cookies.set('boolean', true);
135
- assert.strictEqual(typeof Cookies.get('boolean'), 'string', 'should not change the returned type');
136
- // IE 6-8 throw an exception if trying to delete a window property
137
- // See stackoverflow.com/questions/1073414/deleting-a-window-property-in-ie/1824228
138
- try {
139
- delete window.json;
140
- } catch (e) {}
141
- });
142
-
143
- QUnit.module('write', lifecycle);
144
-
145
- QUnit.test('String primitive', function (assert) {
146
- assert.expect(1);
147
- Cookies.set('c', 'v');
148
- assert.strictEqual(Cookies.get('c'), 'v', 'should write value');
149
- });
150
-
151
- QUnit.test('String object', function (assert) {
152
- assert.expect(1);
153
- Cookies.set('c', new String('v'));
154
- assert.strictEqual(Cookies.get('c'), 'v', 'should write value');
155
- });
156
-
157
- QUnit.test('value "[object Object]"', function (assert) {
158
- assert.expect(1);
159
- Cookies.set('c', '[object Object]');
160
- assert.strictEqual(Cookies.get('c'), '[object Object]', 'should write value');
161
- });
162
-
163
- QUnit.test('number', function (assert) {
164
- assert.expect(1);
165
- Cookies.set('c', 1234);
166
- assert.strictEqual(Cookies.get('c'), '1234', 'should write value');
167
- });
168
-
169
- QUnit.test('null', function (assert) {
170
- assert.expect(1);
171
- Cookies.set('c', null);
172
- assert.strictEqual(Cookies.get('c'), 'null', 'should write value');
173
- });
174
-
175
- QUnit.test('undefined', function (assert) {
176
- assert.expect(1);
177
- Cookies.set('c', undefined);
178
- assert.strictEqual(Cookies.get('c'), 'undefined', 'should write value');
179
- });
180
-
181
- QUnit.test('expires option as days from now', function (assert) {
182
- assert.expect(1);
183
- var sevenDaysFromNow = new Date();
184
- sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 21);
185
- var expected = 'expires=' + sevenDaysFromNow.toUTCString();
186
- var actual = Cookies.set('c', 'v', { expires: 21 });
187
- assert.ok(actual.indexOf(expected) !== -1, quoted(actual) + ' includes ' + quoted(expected));
188
- });
189
-
190
- // github.com/carhartl/jquery-cookie/issues/246
191
- QUnit.test('expires option as fraction of a day', function (assert) {
192
- assert.expect(1);
193
-
194
- var findValueForAttributeName = function (createdCookie, attributeName) {
195
- var pairs = createdCookie.split('; ');
196
- var foundAttributeValue;
197
- pairs.forEach(function (pair) {
198
- if (pair.split('=')[0] === attributeName) {
199
- foundAttributeValue = pair.split('=')[1];
200
- }
201
- });
202
- return foundAttributeValue;
203
- };
204
- var now = new Date();
205
- var stringifiedDate = findValueForAttributeName(Cookies.set('c', 'v', { expires: 0.5 }), 'expires');
206
- var expires = new Date(stringifiedDate);
207
-
208
- // When we were using Date.setDate() fractions have been ignored
209
- // and expires resulted in the current date. Allow 1000 milliseconds
210
- // difference for execution time because new Date() can be different,
211
- // even when it's run synchronously.
212
- // See https://github.com/js-cookie/js-cookie/commit/ecb597b65e4c477baa2b30a2a5a67fdaee9870ea#commitcomment-20146048.
213
- var assertion = expires.getTime() > now.getTime() + 1000;
214
- var message = quoted(expires.getTime()) + ' should be greater than ' + quoted(now.getTime());
215
- assert.ok(assertion, message);
216
- });
217
-
218
- QUnit.test('expires option as Date instance', function (assert) {
219
- assert.expect(1);
220
- var sevenDaysFromNow = new Date();
221
- sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7);
222
- var expected = 'expires=' + sevenDaysFromNow.toUTCString();
223
- var actual = Cookies.set('c', 'v', { expires: sevenDaysFromNow });
224
- assert.ok(actual.indexOf(expected) !== -1, quoted(actual) + ' includes ' + quoted(expected));
225
- });
226
-
227
- QUnit.test('return value', function (assert) {
228
- assert.expect(1);
229
- var expected = 'c=v';
230
- var actual = Cookies.set('c', 'v').substring(0, expected.length);
231
- assert.strictEqual(actual, expected, 'should return written cookie string');
232
- });
233
-
234
- QUnit.test('default path attribute', function (assert) {
235
- assert.expect(1);
236
- assert.ok(Cookies.set('c', 'v').match(/path=\//), 'should read the default path');
237
- });
238
-
239
- QUnit.test('API for changing defaults', function (assert) {
240
- assert.expect(3);
241
-
242
- Cookies.defaults.path = '/foo';
243
- assert.ok(Cookies.set('c', 'v').match(/path=\/foo/), 'should use attributes from defaults');
244
- Cookies.remove('c', { path: '/foo' });
245
-
246
- assert.ok(Cookies.set('c', 'v', { path: '/bar' }).match(/path=\/bar/), 'attributes argument has precedence');
247
- Cookies.remove('c', { path: '/bar' });
248
-
249
- delete Cookies.defaults.path;
250
- assert.ok(Cookies.set('c', 'v').match(/path=\//), 'should roll back to the default path');
251
- });
252
-
253
- QUnit.test('true secure value', function (assert) {
254
- assert.expect(1);
255
- var expected = 'c=v; path=/; secure';
256
- var actual = Cookies.set('c', 'v', {secure: true});
257
- assert.strictEqual(actual, expected, 'should add secure attribute');
258
- });
259
-
260
- // github.com/js-cookie/js-cookie/pull/54
261
- QUnit.test('false secure value', function (assert) {
262
- assert.expect(1);
263
- var expected = 'c=v; path=/';
264
- var actual = Cookies.set('c', 'v', {secure: false});
265
- assert.strictEqual(actual, expected, 'false should not modify path in cookie string');
266
- });
267
-
268
- // github.com/js-cookie/js-cookie/issues/276
269
- QUnit.test('unofficial attribute', function (assert) {
270
- assert.expect(1);
271
- var expected = 'c=v; path=/; unofficial=anything';
272
- var actual = Cookies.set('c', 'v', {
273
- unofficial: 'anything'
274
- });
275
- assert.strictEqual(expected, actual, 'should write the cookie string with unofficial attribute');
276
- });
277
-
278
- QUnit.test('undefined attribute value', function (assert) {
279
- assert.expect(5);
280
- assert.strictEqual(Cookies.set('c', 'v', {
281
- expires: undefined
282
- }), 'c=v; path=/', 'should not write undefined expires attribute');
283
- assert.strictEqual(Cookies.set('c', 'v', {
284
- path: undefined
285
- }), 'c=v', 'should not write undefined path attribute');
286
- assert.strictEqual(Cookies.set('c', 'v', {
287
- domain: undefined
288
- }), 'c=v; path=/', 'should not write undefined domain attribute');
289
- assert.strictEqual(Cookies.set('c', 'v', {
290
- secure: undefined
291
- }), 'c=v; path=/', 'should not write undefined secure attribute');
292
- assert.strictEqual(Cookies.set('c', 'v', {
293
- unofficial: undefined
294
- }), 'c=v; path=/', 'should not write undefined unofficial attribute');
295
- });
296
-
297
- QUnit.module('remove', lifecycle);
298
-
299
- QUnit.test('deletion', function (assert) {
300
- assert.expect(1);
301
- Cookies.set('c', 'v');
302
- Cookies.remove('c');
303
- assert.strictEqual(document.cookie, '', 'should delete the cookie');
304
- });
305
-
306
- QUnit.test('with attributes', function (assert) {
307
- assert.expect(1);
308
- var attributes = { path: '/' };
309
- Cookies.set('c', 'v', attributes);
310
- Cookies.remove('c', attributes);
311
- assert.strictEqual(document.cookie, '', 'should delete the cookie');
312
- });
313
-
314
- QUnit.test('passing attributes reference', function (assert) {
315
- assert.expect(1);
316
- var attributes = { path: '/' };
317
- Cookies.set('c', 'v', attributes);
318
- Cookies.remove('c', attributes);
319
- assert.deepEqual(attributes, { path: '/' }, 'won\'t alter attributes object');
320
- });
321
-
322
- QUnit.module('converters', lifecycle);
323
-
324
- // github.com/carhartl/jquery-cookie/pull/166
325
- QUnit.test('provide a way for decoding characters encoded by the escape function', function (assert) {
326
- assert.expect(1);
327
- document.cookie = 'c=%u5317%u4eac';
328
- assert.strictEqual(Cookies.withConverter(unescape).get('c'), '北京', 'should convert chinese characters correctly');
329
- });
330
-
331
- QUnit.test('should decode a malformed char that matches the decodeURIComponent regex', function (assert) {
332
- assert.expect(1);
333
- document.cookie = 'c=%E3';
334
- var cookies = Cookies.withConverter(unescape);
335
- assert.strictEqual(cookies.get('c'), 'ã', 'should convert the character correctly');
336
- cookies.remove('c', {
337
- path: ''
338
- });
339
- });
340
-
341
- QUnit.test('should be able to conditionally decode a single malformed cookie', function (assert) {
342
- assert.expect(4);
343
- var cookies = Cookies.withConverter(function (value, name) {
344
- if (name === 'escaped') {
345
- return unescape(value);
346
- }
347
- });
348
-
349
- document.cookie = 'escaped=%u5317';
350
- assert.strictEqual(cookies.get('escaped'), '北', 'should use a custom method for escaped cookie');
351
-
352
- document.cookie = 'encoded=%E4%BA%AC';
353
- assert.strictEqual(cookies.get('encoded'), '京', 'should use the default encoding for the rest');
354
-
355
- assert.deepEqual(cookies.get(), {
356
- escaped: '北',
357
- encoded: '京'
358
- }, 'should retrieve everything');
359
-
360
- Object.keys(cookies.get()).forEach(function (name) {
361
- cookies.remove(name, {
362
- path: ''
363
- });
364
- });
365
- assert.strictEqual(document.cookie, '', 'should remove everything');
366
- });
367
-
368
- // github.com/js-cookie/js-cookie/issues/70
369
- QUnit.test('should be able to create a write decoder', function (assert) {
370
- assert.expect(1);
371
- Cookies.withConverter({
372
- write: function (value) {
373
- return value.replace('+', '%2B');
374
- }
375
- }).set('c', '+');
376
- assert.strictEqual(document.cookie, 'c=%2B', 'should call the write converter');
377
- });
378
-
379
- QUnit.test('should be able to use read and write decoder', function (assert) {
380
- assert.expect(1);
381
- document.cookie = 'c=%2B';
382
- var cookies = Cookies.withConverter({
383
- read: function (value) {
384
- return value.replace('%2B', '+');
385
- }
386
- });
387
- assert.strictEqual(cookies.get('c'), '+', 'should call the read converter');
388
- });
389
-
390
- QUnit.module('JSON handling', lifecycle);
391
-
392
- QUnit.test('Number', function (assert) {
393
- assert.expect(2);
394
- Cookies.set('c', 1);
395
- assert.strictEqual(Cookies.getJSON('c'), 1, 'should handle a Number');
396
- assert.strictEqual(Cookies.get('c'), '1', 'should return a String');
397
- });
398
-
399
- QUnit.test('Boolean', function (assert) {
400
- assert.expect(2);
401
- Cookies.set('c', true);
402
- assert.strictEqual(Cookies.getJSON('c'), true, 'should handle a Boolean');
403
- assert.strictEqual(Cookies.get('c'), 'true', 'should return a Boolean');
404
- });
405
-
406
- QUnit.test('Array Literal', function (assert) {
407
- assert.expect(2);
408
- Cookies.set('c', ['v']);
409
- assert.deepEqual(Cookies.getJSON('c'), ['v'], 'should handle Array Literal');
410
- assert.strictEqual(Cookies.get('c'), '["v"]', 'should return a String');
411
- });
412
-
413
- QUnit.test('Array Constructor', function (assert) {
414
- /*jshint -W009 */
415
- assert.expect(2);
416
- var value = new Array();
417
- value[0] = 'v';
418
- Cookies.set('c', value);
419
- assert.deepEqual(Cookies.getJSON('c'), ['v'], 'should handle Array Constructor');
420
- assert.strictEqual(Cookies.get('c'), '["v"]', 'should return a String');
421
- });
422
-
423
- QUnit.test('Object Literal', function (assert) {
424
- assert.expect(2);
425
- Cookies.set('c', {k: 'v'});
426
- assert.deepEqual(Cookies.getJSON('c'), {k: 'v'}, 'should handle Object Literal');
427
- assert.strictEqual(Cookies.get('c'), '{"k":"v"}', 'should return a String');
428
- });
429
-
430
- QUnit.test('Object Constructor', function (assert) {
431
- /*jshint -W010 */
432
- assert.expect(2);
433
- var value = new Object();
434
- value.k = 'v';
435
- Cookies.set('c', value);
436
- assert.deepEqual(Cookies.getJSON('c'), {k: 'v'}, 'should handle Object Constructor');
437
- assert.strictEqual(Cookies.get('c'), '{"k":"v"}', 'should return a String');
438
- });
439
-
440
- QUnit.test('Use String(value) for unsupported objects that do not stringify into JSON', function (assert) {
441
- assert.expect(2);
442
- Cookies.set('date', new Date(2015, 4, 13, 0, 0, 0, 0));
443
- assert.strictEqual(Cookies.get('date').indexOf('"'), -1, 'should not quote the stringified Date object');
444
- assert.strictEqual(Cookies.getJSON('date').indexOf('"'), -1, 'should not quote the stringified Date object');
445
- });
446
-
447
- QUnit.test('Call to read all cookies with mixed json', function (assert) {
448
- Cookies.set('c', { foo: 'bar' });
449
- Cookies.set('c2', 'v');
450
- assert.deepEqual(Cookies.getJSON(), { c: { foo: 'bar' }, c2: 'v' }, 'returns JSON parsed cookies');
451
- assert.deepEqual(Cookies.get(), { c: '{"foo":"bar"}', c2: 'v' }, 'returns unparsed cookies');
452
- });
453
-
454
- QUnit.module('noConflict', lifecycle);
455
-
456
- QUnit.test('do not conflict with existent globals', function (assert) {
457
- assert.expect(2);
458
- var Cookies = window.Cookies.noConflict();
459
- Cookies.set('c', 'v');
460
- assert.strictEqual(Cookies.get('c'), 'v', 'should work correctly');
461
- assert.strictEqual(window.Cookies, 'existent global', 'should restore the original global');
462
- window.Cookies = Cookies;
463
- });
package/test/utils.js DELETED
@@ -1,126 +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
- window.quoted = function (input) {
123
- return '"' + input + '"';
124
- };
125
-
126
- }());
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