nativescript 9.1.0-alpha.4 → 9.1.0-alpha.7

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.
Files changed (227) hide show
  1. package/lib/common/mobile/android/android-emulator-services.js +11 -3
  2. package/lib/services/bundler/bundler-compiler-service.js +3 -3
  3. package/node_modules/debug/LICENSE +20 -0
  4. package/node_modules/debug/README.md +481 -0
  5. package/node_modules/debug/package.json +64 -0
  6. package/node_modules/debug/src/browser.js +272 -0
  7. package/node_modules/debug/src/common.js +292 -0
  8. package/node_modules/debug/src/index.js +10 -0
  9. package/node_modules/debug/src/node.js +263 -0
  10. package/node_modules/ms/index.js +162 -0
  11. package/node_modules/ms/license.md +21 -0
  12. package/node_modules/ms/package.json +38 -0
  13. package/node_modules/ms/readme.md +59 -0
  14. package/node_modules/universal-analytics/.travis.yml +11 -0
  15. package/node_modules/universal-analytics/AcceptableParams.md +757 -0
  16. package/node_modules/universal-analytics/HISTORY.md +170 -0
  17. package/node_modules/universal-analytics/Makefile +5 -0
  18. package/node_modules/universal-analytics/README.md +651 -0
  19. package/node_modules/universal-analytics/index.js +2 -0
  20. package/node_modules/universal-analytics/lib/config.js +171 -0
  21. package/node_modules/universal-analytics/lib/index.js +563 -0
  22. package/node_modules/universal-analytics/lib/request.js +73 -0
  23. package/node_modules/universal-analytics/lib/utils.js +29 -0
  24. package/node_modules/universal-analytics/package.json +33 -0
  25. package/node_modules/universal-analytics/test/_enqueue.js +144 -0
  26. package/node_modules/universal-analytics/test/event.js +346 -0
  27. package/node_modules/universal-analytics/test/exception.js +233 -0
  28. package/node_modules/universal-analytics/test/index.js +141 -0
  29. package/node_modules/universal-analytics/test/item.js +550 -0
  30. package/node_modules/universal-analytics/test/middleware.js +119 -0
  31. package/node_modules/universal-analytics/test/mocha.opts +3 -0
  32. package/node_modules/universal-analytics/test/pageview.js +286 -0
  33. package/node_modules/universal-analytics/test/send.js +232 -0
  34. package/node_modules/universal-analytics/test/set.js +68 -0
  35. package/node_modules/universal-analytics/test/timing.js +363 -0
  36. package/node_modules/universal-analytics/test/transaction.js +371 -0
  37. package/node_modules/uuid/LICENSE.md +9 -0
  38. package/node_modules/uuid/README.md +510 -0
  39. package/node_modules/uuid/dist/cjs/index.d.ts +15 -0
  40. package/node_modules/uuid/dist/cjs/index.js +31 -0
  41. package/node_modules/uuid/dist/cjs/max.d.ts +2 -0
  42. package/node_modules/uuid/dist/cjs/max.js +3 -0
  43. package/node_modules/uuid/dist/cjs/md5.d.ts +4 -0
  44. package/node_modules/uuid/dist/cjs/md5.js +13 -0
  45. package/node_modules/uuid/dist/cjs/native.d.ts +6 -0
  46. package/node_modules/uuid/dist/cjs/native.js +4 -0
  47. package/node_modules/uuid/dist/cjs/nil.d.ts +2 -0
  48. package/node_modules/uuid/dist/cjs/nil.js +3 -0
  49. package/node_modules/uuid/dist/cjs/package.json +1 -0
  50. package/node_modules/uuid/dist/cjs/parse.d.ts +2 -0
  51. package/node_modules/uuid/dist/cjs/parse.js +11 -0
  52. package/node_modules/uuid/dist/cjs/regex.d.ts +2 -0
  53. package/node_modules/uuid/dist/cjs/regex.js +3 -0
  54. package/node_modules/uuid/dist/cjs/rng.d.ts +1 -0
  55. package/node_modules/uuid/dist/cjs/rng.js +13 -0
  56. package/node_modules/uuid/dist/cjs/sha1.d.ts +4 -0
  57. package/node_modules/uuid/dist/cjs/sha1.js +13 -0
  58. package/node_modules/uuid/dist/cjs/stringify.d.ts +3 -0
  59. package/node_modules/uuid/dist/cjs/stringify.js +39 -0
  60. package/node_modules/uuid/dist/cjs/types.d.ts +21 -0
  61. package/node_modules/uuid/dist/cjs/types.js +2 -0
  62. package/node_modules/uuid/dist/cjs/uuid-bin.d.ts +1 -0
  63. package/node_modules/uuid/dist/cjs/uuid-bin.js +72 -0
  64. package/node_modules/uuid/dist/cjs/v1.d.ts +11 -0
  65. package/node_modules/uuid/dist/cjs/v1.js +87 -0
  66. package/node_modules/uuid/dist/cjs/v1ToV6.d.ts +2 -0
  67. package/node_modules/uuid/dist/cjs/v1ToV6.js +13 -0
  68. package/node_modules/uuid/dist/cjs/v3.d.ts +9 -0
  69. package/node_modules/uuid/dist/cjs/v3.js +14 -0
  70. package/node_modules/uuid/dist/cjs/v35.d.ts +7 -0
  71. package/node_modules/uuid/dist/cjs/v35.js +41 -0
  72. package/node_modules/uuid/dist/cjs/v4.d.ts +4 -0
  73. package/node_modules/uuid/dist/cjs/v4.js +29 -0
  74. package/node_modules/uuid/dist/cjs/v5.d.ts +9 -0
  75. package/node_modules/uuid/dist/cjs/v5.js +14 -0
  76. package/node_modules/uuid/dist/cjs/v6.d.ts +4 -0
  77. package/node_modules/uuid/dist/cjs/v6.js +19 -0
  78. package/node_modules/uuid/dist/cjs/v6ToV1.d.ts +2 -0
  79. package/node_modules/uuid/dist/cjs/v6ToV1.js +13 -0
  80. package/node_modules/uuid/dist/cjs/v7.d.ts +9 -0
  81. package/node_modules/uuid/dist/cjs/v7.js +69 -0
  82. package/node_modules/uuid/dist/cjs/validate.d.ts +2 -0
  83. package/node_modules/uuid/dist/cjs/validate.js +7 -0
  84. package/node_modules/uuid/dist/cjs/version.d.ts +2 -0
  85. package/node_modules/uuid/dist/cjs/version.js +10 -0
  86. package/node_modules/uuid/dist/cjs-browser/index.d.ts +15 -0
  87. package/node_modules/uuid/dist/cjs-browser/index.js +31 -0
  88. package/node_modules/uuid/dist/cjs-browser/max.d.ts +2 -0
  89. package/node_modules/uuid/dist/cjs-browser/max.js +3 -0
  90. package/node_modules/uuid/dist/cjs-browser/md5.d.ts +2 -0
  91. package/node_modules/uuid/dist/cjs-browser/md5.js +137 -0
  92. package/node_modules/uuid/dist/cjs-browser/native.d.ts +4 -0
  93. package/node_modules/uuid/dist/cjs-browser/native.js +4 -0
  94. package/node_modules/uuid/dist/cjs-browser/nil.d.ts +2 -0
  95. package/node_modules/uuid/dist/cjs-browser/nil.js +3 -0
  96. package/node_modules/uuid/dist/cjs-browser/package.json +1 -0
  97. package/node_modules/uuid/dist/cjs-browser/parse.d.ts +2 -0
  98. package/node_modules/uuid/dist/cjs-browser/parse.js +11 -0
  99. package/node_modules/uuid/dist/cjs-browser/regex.d.ts +2 -0
  100. package/node_modules/uuid/dist/cjs-browser/regex.js +3 -0
  101. package/node_modules/uuid/dist/cjs-browser/rng.d.ts +1 -0
  102. package/node_modules/uuid/dist/cjs-browser/rng.js +14 -0
  103. package/node_modules/uuid/dist/cjs-browser/sha1.d.ts +2 -0
  104. package/node_modules/uuid/dist/cjs-browser/sha1.js +72 -0
  105. package/node_modules/uuid/dist/cjs-browser/stringify.d.ts +3 -0
  106. package/node_modules/uuid/dist/cjs-browser/stringify.js +39 -0
  107. package/node_modules/uuid/dist/cjs-browser/types.d.ts +21 -0
  108. package/node_modules/uuid/dist/cjs-browser/types.js +2 -0
  109. package/node_modules/uuid/dist/cjs-browser/uuid-bin.d.ts +1 -0
  110. package/node_modules/uuid/dist/cjs-browser/uuid-bin.js +72 -0
  111. package/node_modules/uuid/dist/cjs-browser/v1.d.ts +11 -0
  112. package/node_modules/uuid/dist/cjs-browser/v1.js +87 -0
  113. package/node_modules/uuid/dist/cjs-browser/v1ToV6.d.ts +2 -0
  114. package/node_modules/uuid/dist/cjs-browser/v1ToV6.js +13 -0
  115. package/node_modules/uuid/dist/cjs-browser/v3.d.ts +9 -0
  116. package/node_modules/uuid/dist/cjs-browser/v3.js +14 -0
  117. package/node_modules/uuid/dist/cjs-browser/v35.d.ts +7 -0
  118. package/node_modules/uuid/dist/cjs-browser/v35.js +41 -0
  119. package/node_modules/uuid/dist/cjs-browser/v4.d.ts +4 -0
  120. package/node_modules/uuid/dist/cjs-browser/v4.js +29 -0
  121. package/node_modules/uuid/dist/cjs-browser/v5.d.ts +9 -0
  122. package/node_modules/uuid/dist/cjs-browser/v5.js +14 -0
  123. package/node_modules/uuid/dist/cjs-browser/v6.d.ts +4 -0
  124. package/node_modules/uuid/dist/cjs-browser/v6.js +19 -0
  125. package/node_modules/uuid/dist/cjs-browser/v6ToV1.d.ts +2 -0
  126. package/node_modules/uuid/dist/cjs-browser/v6ToV1.js +13 -0
  127. package/node_modules/uuid/dist/cjs-browser/v7.d.ts +9 -0
  128. package/node_modules/uuid/dist/cjs-browser/v7.js +69 -0
  129. package/node_modules/uuid/dist/cjs-browser/validate.d.ts +2 -0
  130. package/node_modules/uuid/dist/cjs-browser/validate.js +7 -0
  131. package/node_modules/uuid/dist/cjs-browser/version.d.ts +2 -0
  132. package/node_modules/uuid/dist/cjs-browser/version.js +10 -0
  133. package/node_modules/uuid/dist/esm/bin/uuid +2 -0
  134. package/node_modules/uuid/dist/esm/index.d.ts +15 -0
  135. package/node_modules/uuid/dist/esm/index.js +14 -0
  136. package/node_modules/uuid/dist/esm/max.d.ts +2 -0
  137. package/node_modules/uuid/dist/esm/max.js +1 -0
  138. package/node_modules/uuid/dist/esm/md5.d.ts +4 -0
  139. package/node_modules/uuid/dist/esm/md5.js +11 -0
  140. package/node_modules/uuid/dist/esm/native.d.ts +6 -0
  141. package/node_modules/uuid/dist/esm/native.js +2 -0
  142. package/node_modules/uuid/dist/esm/nil.d.ts +2 -0
  143. package/node_modules/uuid/dist/esm/nil.js +1 -0
  144. package/node_modules/uuid/dist/esm/parse.d.ts +2 -0
  145. package/node_modules/uuid/dist/esm/parse.js +9 -0
  146. package/node_modules/uuid/dist/esm/regex.d.ts +2 -0
  147. package/node_modules/uuid/dist/esm/regex.js +1 -0
  148. package/node_modules/uuid/dist/esm/rng.d.ts +1 -0
  149. package/node_modules/uuid/dist/esm/rng.js +10 -0
  150. package/node_modules/uuid/dist/esm/sha1.d.ts +4 -0
  151. package/node_modules/uuid/dist/esm/sha1.js +11 -0
  152. package/node_modules/uuid/dist/esm/stringify.d.ts +3 -0
  153. package/node_modules/uuid/dist/esm/stringify.js +35 -0
  154. package/node_modules/uuid/dist/esm/types.d.ts +21 -0
  155. package/node_modules/uuid/dist/esm/types.js +1 -0
  156. package/node_modules/uuid/dist/esm/uuid-bin.d.ts +1 -0
  157. package/node_modules/uuid/dist/esm/uuid-bin.js +70 -0
  158. package/node_modules/uuid/dist/esm/v1.d.ts +11 -0
  159. package/node_modules/uuid/dist/esm/v1.js +83 -0
  160. package/node_modules/uuid/dist/esm/v1ToV6.d.ts +2 -0
  161. package/node_modules/uuid/dist/esm/v1ToV6.js +10 -0
  162. package/node_modules/uuid/dist/esm/v3.d.ts +9 -0
  163. package/node_modules/uuid/dist/esm/v3.js +9 -0
  164. package/node_modules/uuid/dist/esm/v35.d.ts +7 -0
  165. package/node_modules/uuid/dist/esm/v35.js +36 -0
  166. package/node_modules/uuid/dist/esm/v4.d.ts +4 -0
  167. package/node_modules/uuid/dist/esm/v4.js +27 -0
  168. package/node_modules/uuid/dist/esm/v5.d.ts +9 -0
  169. package/node_modules/uuid/dist/esm/v5.js +9 -0
  170. package/node_modules/uuid/dist/esm/v6.d.ts +4 -0
  171. package/node_modules/uuid/dist/esm/v6.js +17 -0
  172. package/node_modules/uuid/dist/esm/v6ToV1.d.ts +2 -0
  173. package/node_modules/uuid/dist/esm/v6ToV1.js +10 -0
  174. package/node_modules/uuid/dist/esm/v7.d.ts +9 -0
  175. package/node_modules/uuid/dist/esm/v7.js +65 -0
  176. package/node_modules/uuid/dist/esm/validate.d.ts +2 -0
  177. package/node_modules/uuid/dist/esm/validate.js +5 -0
  178. package/node_modules/uuid/dist/esm/version.d.ts +2 -0
  179. package/node_modules/uuid/dist/esm/version.js +8 -0
  180. package/node_modules/uuid/dist/esm-browser/index.d.ts +15 -0
  181. package/node_modules/uuid/dist/esm-browser/index.js +14 -0
  182. package/node_modules/uuid/dist/esm-browser/max.d.ts +2 -0
  183. package/node_modules/uuid/dist/esm-browser/max.js +1 -0
  184. package/node_modules/uuid/dist/esm-browser/md5.d.ts +2 -0
  185. package/node_modules/uuid/dist/esm-browser/md5.js +135 -0
  186. package/node_modules/uuid/dist/esm-browser/native.d.ts +4 -0
  187. package/node_modules/uuid/dist/esm-browser/native.js +2 -0
  188. package/node_modules/uuid/dist/esm-browser/nil.d.ts +2 -0
  189. package/node_modules/uuid/dist/esm-browser/nil.js +1 -0
  190. package/node_modules/uuid/dist/esm-browser/parse.d.ts +2 -0
  191. package/node_modules/uuid/dist/esm-browser/parse.js +9 -0
  192. package/node_modules/uuid/dist/esm-browser/regex.d.ts +2 -0
  193. package/node_modules/uuid/dist/esm-browser/regex.js +1 -0
  194. package/node_modules/uuid/dist/esm-browser/rng.d.ts +1 -0
  195. package/node_modules/uuid/dist/esm-browser/rng.js +11 -0
  196. package/node_modules/uuid/dist/esm-browser/sha1.d.ts +2 -0
  197. package/node_modules/uuid/dist/esm-browser/sha1.js +70 -0
  198. package/node_modules/uuid/dist/esm-browser/stringify.d.ts +3 -0
  199. package/node_modules/uuid/dist/esm-browser/stringify.js +35 -0
  200. package/node_modules/uuid/dist/esm-browser/types.d.ts +21 -0
  201. package/node_modules/uuid/dist/esm-browser/types.js +1 -0
  202. package/node_modules/uuid/dist/esm-browser/uuid-bin.d.ts +1 -0
  203. package/node_modules/uuid/dist/esm-browser/uuid-bin.js +70 -0
  204. package/node_modules/uuid/dist/esm-browser/v1.d.ts +11 -0
  205. package/node_modules/uuid/dist/esm-browser/v1.js +83 -0
  206. package/node_modules/uuid/dist/esm-browser/v1ToV6.d.ts +2 -0
  207. package/node_modules/uuid/dist/esm-browser/v1ToV6.js +10 -0
  208. package/node_modules/uuid/dist/esm-browser/v3.d.ts +9 -0
  209. package/node_modules/uuid/dist/esm-browser/v3.js +9 -0
  210. package/node_modules/uuid/dist/esm-browser/v35.d.ts +7 -0
  211. package/node_modules/uuid/dist/esm-browser/v35.js +36 -0
  212. package/node_modules/uuid/dist/esm-browser/v4.d.ts +4 -0
  213. package/node_modules/uuid/dist/esm-browser/v4.js +27 -0
  214. package/node_modules/uuid/dist/esm-browser/v5.d.ts +9 -0
  215. package/node_modules/uuid/dist/esm-browser/v5.js +9 -0
  216. package/node_modules/uuid/dist/esm-browser/v6.d.ts +4 -0
  217. package/node_modules/uuid/dist/esm-browser/v6.js +17 -0
  218. package/node_modules/uuid/dist/esm-browser/v6ToV1.d.ts +2 -0
  219. package/node_modules/uuid/dist/esm-browser/v6ToV1.js +10 -0
  220. package/node_modules/uuid/dist/esm-browser/v7.d.ts +9 -0
  221. package/node_modules/uuid/dist/esm-browser/v7.js +65 -0
  222. package/node_modules/uuid/dist/esm-browser/validate.d.ts +2 -0
  223. package/node_modules/uuid/dist/esm-browser/validate.js +5 -0
  224. package/node_modules/uuid/dist/esm-browser/version.d.ts +2 -0
  225. package/node_modules/uuid/dist/esm-browser/version.js +8 -0
  226. package/node_modules/uuid/package.json +132 -0
  227. package/package.json +8 -4
@@ -0,0 +1,286 @@
1
+
2
+ var qs = require("querystring");
3
+ var uuid = require("uuid");
4
+ var should = require("should");
5
+ var sinon = require("sinon");
6
+ var url = require("url");
7
+
8
+ var ua = require("../lib/index.js");
9
+ var utils = require("../lib/utils.js");
10
+ var config = require("../lib/config.js");
11
+ var request = require("../lib/request");
12
+
13
+
14
+ describe("ua", function () {
15
+
16
+
17
+
18
+ describe("#pageview", function () {
19
+ var _enqueue;
20
+
21
+ beforeEach(function () {
22
+ _enqueue = sinon.stub(ua.Visitor.prototype, "_enqueue", function () {
23
+ if (arguments.length === 3 && typeof arguments[2] === 'function') {
24
+ arguments[2]();
25
+ }
26
+ return this;
27
+ });
28
+ });
29
+
30
+ afterEach(function () {
31
+ _enqueue.restore()
32
+ });
33
+
34
+
35
+ it("should be available via the #pv shortcut", function () {
36
+ var visitor = ua()
37
+ visitor.pv.should.equal(visitor.pageview)
38
+ });
39
+
40
+
41
+ it("should accept arguments (path)", function () {
42
+ var path = "/" + Math.random()
43
+
44
+ var visitor = ua("UA-XXXXX-XX")
45
+
46
+ var result = visitor.pageview(path)
47
+
48
+ visitor._context = result._context;
49
+ result.should.eql(visitor, "should return a visitor that is identical except for the context");
50
+
51
+ result.should.be.instanceof(ua.Visitor);
52
+ result._context.should.eql(_enqueue.args[0][1], "the pageview params should be persisted as the context of the visitor clone")
53
+
54
+ _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");
55
+ _enqueue.args[0][0].should.equal("pageview");
56
+ _enqueue.args[0][1].should.have.keys("dp")
57
+ _enqueue.args[0][1].dp.should.equal(path);
58
+ });
59
+
60
+
61
+ it("should accept arguments (path, fn)", function () {
62
+ var path = "/" + Math.random();
63
+ var fn = sinon.spy();
64
+
65
+ var visitor = ua("UA-XXXXX-XX")
66
+
67
+ var result = visitor.pageview(path, fn)
68
+
69
+ visitor._context = result._context;
70
+ result.should.eql(visitor, "should return a visitor that is identical except for the context");
71
+
72
+ result.should.be.instanceof(ua.Visitor);
73
+ result._context.should.eql(_enqueue.args[0][1], "the pageview params should be persisted as the context of the visitor clone")
74
+
75
+ _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");
76
+ _enqueue.args[0][0].should.equal("pageview");
77
+ _enqueue.args[0][1].should.have.keys("dp")
78
+ _enqueue.args[0][1].dp.should.equal(path);
79
+
80
+ fn.calledOnce.should.equal(true, "callback should have been called once");
81
+ });
82
+
83
+
84
+ it("should accept arguments (params)", function () {
85
+ var params = {
86
+ dp: "/" + Math.random()
87
+ };
88
+
89
+ var visitor = ua("UA-XXXXX-XX")
90
+
91
+ var result = visitor.pageview(params)
92
+
93
+ visitor._context = result._context;
94
+ result.should.eql(visitor, "should return a visitor that is identical except for the context");
95
+
96
+ result.should.be.instanceof(ua.Visitor);
97
+ result._context.should.eql(_enqueue.args[0][1], "the pageview params should be persisted as the context of the visitor clone")
98
+
99
+ _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");
100
+ _enqueue.args[0][0].should.equal("pageview");
101
+ _enqueue.args[0][1].should.have.keys("dp")
102
+ _enqueue.args[0][1].dp.should.equal(params.dp);
103
+ });
104
+
105
+
106
+ it("should accept arguments (params, fn)", function () {
107
+ var params = {
108
+ dp: "/" + Math.random(),
109
+ empty: null // Should be removed
110
+ };
111
+ var json = JSON.stringify(params)
112
+ var fn = sinon.spy()
113
+
114
+ ua("UA-XXXXX-XX").pageview(params, fn)
115
+
116
+ _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");
117
+ _enqueue.args[0][0].should.equal("pageview");
118
+ _enqueue.args[0][1].should.have.keys("dp")
119
+ _enqueue.args[0][1].dp.should.equal(params.dp);
120
+
121
+ fn.calledOnce.should.equal(true, "callback should have been called once");
122
+
123
+ JSON.stringify(params).should.equal(json, "params should not have been modified")
124
+ });
125
+
126
+
127
+ it("should accept arguments (path, hostname)", function () {
128
+ var path = Math.random().toString();
129
+ var hostname = Math.random().toString();
130
+
131
+ ua("UA-XXXXX-XX").pageview(path, hostname);
132
+
133
+ _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");
134
+ _enqueue.args[0][0].should.equal("pageview");
135
+ _enqueue.args[0][1].should.have.keys("dp", "dh")
136
+ _enqueue.args[0][1].dp.should.equal(path);
137
+ _enqueue.args[0][1].dh.should.equal(hostname);
138
+ });
139
+
140
+
141
+ it("should accept arguments (path, hostname, fn)", function () {
142
+ var path = Math.random().toString();
143
+ var hostname = Math.random().toString();
144
+ var fn = sinon.spy()
145
+
146
+ ua("UA-XXXXX-XX").pageview(path, hostname, fn);
147
+
148
+ _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");
149
+ _enqueue.args[0][0].should.equal("pageview");
150
+ _enqueue.args[0][1].should.have.keys("dp", "dh")
151
+ _enqueue.args[0][1].dp.should.equal(path);
152
+ _enqueue.args[0][1].dh.should.equal(hostname);
153
+
154
+ fn.calledOnce.should.equal(true, "callback should have been called once");
155
+ });
156
+
157
+
158
+ it("should accept arguments (path, hostname, title)", function () {
159
+ var path = Math.random().toString();
160
+ var hostname = Math.random().toString();
161
+ var title = Math.random().toString();
162
+
163
+ ua("UA-XXXXX-XX").pageview(path, hostname, title);
164
+
165
+ _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");
166
+ _enqueue.args[0][0].should.equal("pageview");
167
+ _enqueue.args[0][1].should.have.keys("dp", "dh", "dt")
168
+ _enqueue.args[0][1].dp.should.equal(path);
169
+ _enqueue.args[0][1].dh.should.equal(hostname);
170
+ _enqueue.args[0][1].dt.should.equal(title);
171
+ });
172
+
173
+
174
+ it("should accept arguments (path, hostname, title, fn)", function () {
175
+ var path = Math.random().toString();
176
+ var hostname = Math.random().toString();
177
+ var title = Math.random().toString();
178
+ var fn = sinon.spy()
179
+
180
+ ua("UA-XXXXX-XX").pageview(path, hostname, title, fn);
181
+
182
+ _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");
183
+ _enqueue.args[0][0].should.equal("pageview");
184
+ _enqueue.args[0][1].should.have.keys("dp", "dh", "dt")
185
+ _enqueue.args[0][1].dp.should.equal(path);
186
+ _enqueue.args[0][1].dh.should.equal(hostname);
187
+ _enqueue.args[0][1].dt.should.equal(title);
188
+
189
+ fn.calledOnce.should.equal(true, "callback should have been called once");
190
+ });
191
+
192
+
193
+ it("should allow daisy-chaining and re-using parameters", function () {
194
+ var path = "/" + Math.random()
195
+ var title = Math.random().toString();
196
+
197
+ ua("UA-XXXXX-XX").pageview(path, null, title).pageview()
198
+
199
+ _enqueue.calledTwice.should.equal(true, "#_enqueue should have been called twice, once for each pageview");
200
+
201
+ _enqueue.args[0][0].should.equal(_enqueue.args[1][0]);
202
+ _enqueue.args[0][1].should.eql(_enqueue.args[1][1]);
203
+ })
204
+
205
+
206
+ it("should extend and overwrite params when daisy-chaining", function () {
207
+ var path = "/" + Math.random()
208
+ var path2 = "/" + Math.random()
209
+ var title = Math.random().toString();
210
+ var title2 = Math.random().toString();
211
+ var foo = Math.random()
212
+
213
+ ua("UA-XXXXX-XX")
214
+ .pageview(path, null, title)
215
+ .pageview({
216
+ dt: title2,
217
+ dp: path2,
218
+ foo: foo
219
+ }).pageview(path)
220
+
221
+ _enqueue.calledThrice.should.equal(true, "#_enqueue should have been called three times, once for each pageview");
222
+
223
+ _enqueue.args[0][1].should.have.keys("dp", "dt")
224
+ _enqueue.args[0][1].dp.should.equal(path);
225
+ _enqueue.args[0][1].dt.should.equal(title);
226
+
227
+ _enqueue.args[1][1].should.have.keys("dp", "dt", "foo")
228
+ _enqueue.args[1][1].dp.should.equal(path2);
229
+ _enqueue.args[1][1].dt.should.equal(title2);
230
+ _enqueue.args[1][1].foo.should.equal(foo);
231
+
232
+ _enqueue.args[2][1].should.have.keys("dp", "dt")
233
+ _enqueue.args[2][1].dp.should.equal(path);
234
+ _enqueue.args[2][1].dt.should.equal(title2);
235
+ })
236
+
237
+ it("should accept document location instead of page path", function () {
238
+ var params = {
239
+ dl: "http://www.google.com/" + Math.random()
240
+ };
241
+ var json = JSON.stringify(params)
242
+ var fn = sinon.spy()
243
+
244
+ ua("UA-XXXXX-XX").pageview(params, fn)
245
+
246
+ _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");
247
+ _enqueue.args[0][0].should.equal("pageview");
248
+ _enqueue.args[0][1].should.have.keys("dl")
249
+ _enqueue.args[0][1].dl.should.equal(params.dl);
250
+
251
+ fn.calledOnce.should.equal(true, "callback should have been called once");
252
+
253
+ JSON.stringify(params).should.equal(json, "params should not have been modified")
254
+ });
255
+
256
+ it("should fail without page path or document location", function () {
257
+ var fn = sinon.spy()
258
+ var visitor = ua()
259
+
260
+ var result = visitor.pageview(null, fn);
261
+
262
+ visitor._context = result._context;
263
+ result.should.eql(visitor, "should return a visitor that is identical except for the context");
264
+
265
+ result.should.be.instanceof(ua.Visitor);
266
+ result._context.should.eql({}, "the transaction params should not be persisted")
267
+
268
+ _enqueue.called.should.equal(false, "#_enqueue should have not been called once");
269
+ fn.calledOnce.should.equal(true, "callback should have been called once");
270
+ fn.args[0][0].should.be.instanceof(Error);
271
+ fn.thisValues[0].should.equal(visitor);
272
+ });
273
+
274
+ });
275
+
276
+ });
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
@@ -0,0 +1,232 @@
1
+
2
+ var qs = require("querystring");
3
+ var uuid = require("uuid");
4
+ var should = require("should");
5
+ var sinon = require("sinon");
6
+ var url = require("url");
7
+
8
+ var ua = require("../lib/index.js");
9
+ var utils = require("../lib/utils.js")
10
+ var config = require("../lib/config.js")
11
+ var request = require("../lib/request.js");
12
+
13
+
14
+ describe("ua", function () {
15
+
16
+ describe("#send", function () {
17
+ var post;
18
+
19
+ beforeEach(function () {
20
+ post = sinon.stub(request, "post").callsArg(3);
21
+ });
22
+
23
+ afterEach(function () {
24
+ post.restore()
25
+ });
26
+
27
+ it("should immidiately return with an empty queue", function () {
28
+ var visitor = ua();
29
+ var fn = sinon.spy();
30
+
31
+ visitor.send(fn);
32
+
33
+ post.called.should.equal(false, "no request should have been sent")
34
+ fn.calledOnce.should.equal(true, "callback should have been called once")
35
+ fn.thisValues[0].should.equal(visitor, "callback should be called in the context of the visitor instance");
36
+ fn.args[0].should.eql([null, 0], "no error, no requests");
37
+ });
38
+
39
+ it("should include data in POST body", function (done) {
40
+ var paramSets = [
41
+ {first: "123"}
42
+ ]
43
+
44
+ var fn = sinon.spy(function () {
45
+ fn.calledOnce.should.equal(true, "callback should have been called once")
46
+ fn.thisValues[0].should.equal(visitor, "callback should be called in the context of the visitor instance");
47
+ fn.args[0].should.eql([null, 1], "no error, 1 requests");
48
+
49
+ post.callCount.should.equal(paramSets.length, "each param set should have been POSTed");
50
+
51
+ for (var i = 0; i < paramSets.length; i++) {
52
+ var params = paramSets[i];
53
+ var args = post.args[i];
54
+
55
+ var parsedUrl = url.parse(args[0]);
56
+
57
+ Math.random(); // I have absolutely no idea why it fails unless there was some processing to be done after url.parse…
58
+
59
+ (parsedUrl.protocol + "//" + parsedUrl.host).should.equal(config.hostname);
60
+ args[1].should.equal(qs.stringify(params));
61
+ }
62
+
63
+ done();
64
+ });
65
+
66
+ var visitor = ua();
67
+ visitor._queue.push.apply(visitor._queue, paramSets);
68
+ visitor.send(fn);
69
+ });
70
+
71
+ it("should send individual requests when batchting is false", function(done) {
72
+ var paramSets = [
73
+ {first: Math.random()},
74
+ {second: Math.random()},
75
+ {third: Math.random()}
76
+ ]
77
+
78
+ var fn = sinon.spy(function () {
79
+ fn.calledOnce.should.equal(true, "callback should have been called once")
80
+ fn.thisValues[0].should.equal(visitor, "callback should be called in the context of the visitor instance");
81
+
82
+ fn.args[0].should.eql([null, 3], "no error, 3 requests");
83
+
84
+ done();
85
+ });
86
+
87
+ var visitor = ua({enableBatching:false});
88
+ visitor._queue.push.apply(visitor._queue, paramSets)
89
+ visitor.send(fn);
90
+ });
91
+
92
+ describe("#batching is true", function() {
93
+ it("should send request to collect path when only one payload", function(done) {
94
+ var paramSets = [
95
+ {first: Math.random()}
96
+ ]
97
+
98
+ var fn = sinon.spy(function () {
99
+ fn.args[0].should.eql([null, 1], "no error, 1 requests");
100
+ var args = post.args[0];
101
+
102
+ var parsedUrl = url.parse(args[0]);
103
+
104
+ parsedUrl.pathname.should.eql(config.path);
105
+ done();
106
+ });
107
+
108
+ var visitor = ua({enableBatching:true});
109
+ visitor._queue.push.apply(visitor._queue, paramSets)
110
+ visitor.send(fn);
111
+ });
112
+
113
+ it("should send request to batch path when more than one payload sent", function(done) {
114
+ var paramSets = [
115
+ {first: Math.random()},
116
+ {second: Math.random()},
117
+ {third: Math.random()}
118
+ ]
119
+
120
+ var fn = sinon.spy(function () {
121
+ fn.args[0].should.eql([null, 1], "no error, 1 requests");
122
+ var args = post.args[0];
123
+
124
+ var parsedUrl = url.parse(args[0]);
125
+
126
+ parsedUrl.pathname.should.eql(config.batchPath);
127
+ done();
128
+ });
129
+
130
+ var visitor = ua({enableBatching:true});
131
+ visitor._queue.push.apply(visitor._queue, paramSets)
132
+ visitor.send(fn);
133
+ });
134
+
135
+ it("should batch data in Post form", function(done) {
136
+ var paramSets = [
137
+ {first: Math.random()},
138
+ {second: Math.random()},
139
+ {third: Math.random()}
140
+ ]
141
+
142
+ var fn = sinon.spy(function () {
143
+ fn.calledOnce.should.equal(true, "callback should have been called once")
144
+ fn.thisValues[0].should.equal(visitor, "callback should be called in the context of the visitor instance");
145
+
146
+ fn.args[0].should.eql([null, 1], "no error, 1 requests");
147
+ var args = post.args[0];
148
+
149
+ var params = paramSets;
150
+ var formParams = args[1].split("\n");
151
+ formParams.should.have.lengthOf(3);
152
+ formParams[0].should.equal(qs.stringify(params[0]));
153
+
154
+ done();
155
+ });
156
+
157
+ var visitor = ua({enableBatching:true});
158
+ visitor._queue.push.apply(visitor._queue, paramSets)
159
+ visitor.send(fn);
160
+ })
161
+
162
+ it("should batch data based on batchSize", function(done) {
163
+ var paramSets = [
164
+ {first: Math.random()},
165
+ {second: Math.random()},
166
+ {third: Math.random()}
167
+ ]
168
+
169
+ var fn = sinon.spy(function () {
170
+ fn.calledOnce.should.equal(true, "callback should have been called once")
171
+ fn.thisValues[0].should.equal(visitor, "callback should be called in the context of the visitor instance");
172
+
173
+ fn.args[0].should.eql([null, 2], "no error, 2 requests");
174
+
175
+ var body = post.args[0][1];
176
+
177
+ body.split("\n").should.have.lengthOf(2);
178
+
179
+ done();
180
+ });
181
+
182
+ var visitor = ua({enableBatching:true, batchSize: 2});
183
+ visitor._queue.push.apply(visitor._queue, paramSets)
184
+ visitor.send(fn);
185
+ });
186
+ });
187
+
188
+
189
+
190
+
191
+
192
+
193
+ it("should add custom headers to request header", function (done) {
194
+ var fn = sinon.spy(function () {
195
+ fn.calledOnce.should.equal(true, "callback should have been called once");
196
+ fn.thisValues[0].should.equal(visitor, "callback should be called in the context of the visitor instance");
197
+
198
+ post.calledOnce.should.equal(true, "request should have been POSTed");
199
+
200
+ var parsedUrl = url.parse(post.args[0][0]);
201
+ var headers = post.args[0][2];
202
+
203
+ (parsedUrl.protocol + "//" + parsedUrl.host).should.equal(config.hostname);
204
+
205
+ headers.should.have.key("User-Agent");
206
+ headers["User-Agent"].should.equal("Test User Agent");
207
+
208
+ done();
209
+ });
210
+
211
+ var visitor = ua({
212
+ headers: {'User-Agent': 'Test User Agent'}
213
+ });
214
+ visitor._queue.push({});
215
+ visitor.send(fn);
216
+ });
217
+
218
+
219
+
220
+ })
221
+
222
+ });
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
@@ -0,0 +1,68 @@
1
+
2
+ var qs = require("querystring");
3
+ var uuid = require("uuid");
4
+ var should = require("should");
5
+ var sinon = require("sinon");
6
+ var url = require("url");
7
+
8
+ var ua = require("../lib/index.js");
9
+ var utils = require("../lib/utils.js");
10
+ var config = require("../lib/config.js");
11
+ var request = require("../lib/request");
12
+
13
+
14
+ describe("ua", function () {
15
+
16
+
17
+
18
+ describe("#set", function () {
19
+ var _enqueue;
20
+
21
+ beforeEach(function () {
22
+ _enqueue = sinon.stub(ua.Visitor.prototype, "_enqueue", function () {
23
+ if (arguments.length === 3 && typeof arguments[2] === 'function') {
24
+ arguments[2]();
25
+ }
26
+ return this;
27
+ });
28
+ });
29
+
30
+ afterEach(function () {
31
+ _enqueue.restore()
32
+ });
33
+
34
+
35
+ it("should set persistent parameter", function () {
36
+
37
+ var visitor = ua("UA-XXXXX-XX")
38
+ visitor.set("cd1", "bar")
39
+ visitor.pageview("/foo")
40
+
41
+
42
+ _enqueue.calledOnce.should.equal(true, "#_enqueue should have been called once");
43
+ _enqueue.args[0][0].should.equal("pageview");
44
+ _enqueue.args[0][1].should.have.keys("dp", "cd1")
45
+
46
+
47
+ visitor.pageview("/foo/foo").event("Test Event", "Action")
48
+
49
+ _enqueue.args[1][0].should.equal("pageview");
50
+ _enqueue.args[1][1].should.have.keys("dp", "cd1")
51
+
52
+ _enqueue.args[2][0].should.equal("event");
53
+ _enqueue.args[2][1].should.have.keys("ec", "ea", "p", "cd1")
54
+ });
55
+
56
+ });
57
+
58
+ });
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+