@fullstory/browser 1.7.0 → 2.0.0-beta.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/dist/index.d.ts +34 -46
- package/dist/index.esm.js +140 -250
- package/dist/index.js +140 -261
- package/package.json +18 -10
- package/src/index.test.ts +172 -0
- package/src/index.ts +189 -0
- package/CHANGELOG.md +0 -102
- package/src/index.d.ts +0 -65
- package/src/index.js +0 -102
- package/src/snippet.js +0 -40
package/dist/index.js
CHANGED
|
@@ -1,279 +1,158 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function _defineProperty(obj, key, value) {
|
|
32
|
-
if (key in obj) {
|
|
33
|
-
Object.defineProperty(obj, key, {
|
|
34
|
-
value: value,
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true,
|
|
37
|
-
writable: true
|
|
38
|
-
});
|
|
39
|
-
} else {
|
|
40
|
-
obj[key] = value;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return obj;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var snippet = function snippet(_ref) {
|
|
47
|
-
var orgId = _ref.orgId,
|
|
48
|
-
_ref$namespace = _ref.namespace,
|
|
49
|
-
namespace = _ref$namespace === void 0 ? 'FS' : _ref$namespace,
|
|
50
|
-
_ref$debug = _ref.debug,
|
|
51
|
-
_ref$host = _ref.host,
|
|
52
|
-
host = _ref$host === void 0 ? 'fullstory.com' : _ref$host,
|
|
53
|
-
_ref$script = _ref.script,
|
|
54
|
-
script = _ref$script === void 0 ? 'edge.fullstory.com/s/fs.js' : _ref$script;
|
|
55
|
-
|
|
56
|
-
if (!orgId) {
|
|
57
|
-
throw new Error('FullStory orgId is a required parameter');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
window['_fs_host'] = host;
|
|
61
|
-
window['_fs_script'] = script;
|
|
62
|
-
window['_fs_org'] = orgId;
|
|
63
|
-
window['_fs_namespace'] = namespace;
|
|
64
|
-
|
|
65
|
-
(function (m, n, e, t, l, o, g, y) {
|
|
66
|
-
if (e in m) {
|
|
67
|
-
if (m.console && m.console.log) {
|
|
68
|
-
m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
g = m[e] = function (a, b, s) {
|
|
75
|
-
g.q ? g.q.push([a, b, s]) : g._api(a, b, s);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
g.q = [];
|
|
79
|
-
o = n.createElement(t);
|
|
80
|
-
o.async = 1;
|
|
81
|
-
o.crossOrigin = 'anonymous';
|
|
82
|
-
o.src = 'https://' + _fs_script;
|
|
83
|
-
y = n.getElementsByTagName(t)[0];
|
|
84
|
-
y.parentNode.insertBefore(o, y);
|
|
85
|
-
|
|
86
|
-
g.identify = function (i, v, s) {
|
|
87
|
-
g(l, {
|
|
88
|
-
uid: i
|
|
89
|
-
}, s);
|
|
90
|
-
if (v) g(l, v, s);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
g.setUserVars = function (v, s) {
|
|
94
|
-
g(l, v, s);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
g.event = function (i, v, s) {
|
|
98
|
-
g('event', {
|
|
99
|
-
n: i,
|
|
100
|
-
p: v
|
|
101
|
-
}, s);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
g.anonymize = function () {
|
|
105
|
-
g.identify(!!0);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
g.shutdown = function () {
|
|
109
|
-
g("rec", !1);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
g.restart = function () {
|
|
113
|
-
g("rec", !0);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
g.log = function (a, b) {
|
|
117
|
-
g("log", [a, b]);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
g.consent = function (a) {
|
|
121
|
-
g("consent", !arguments.length || a);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
g.identifyAccount = function (i, v) {
|
|
125
|
-
o = 'account';
|
|
126
|
-
v = v || {};
|
|
127
|
-
v.acctId = i;
|
|
128
|
-
g(o, v);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
g.clearUserCookie = function () {};
|
|
132
|
-
|
|
133
|
-
g.setVars = function (n, p) {
|
|
134
|
-
g('setVars', [n, p]);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
g._w = {};
|
|
138
|
-
y = 'XMLHttpRequest';
|
|
139
|
-
g._w[y] = m[y];
|
|
140
|
-
y = 'fetch';
|
|
141
|
-
g._w[y] = m[y];
|
|
142
|
-
if (m[y]) m[y] = function () {
|
|
143
|
-
return g._w[y].apply(this, arguments);
|
|
144
|
-
};
|
|
145
|
-
g._v = "1.3.0";
|
|
146
|
-
})(window, document, window['_fs_namespace'], 'script', 'user');
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
var fs = function fs() {
|
|
150
|
-
return window[window._fs_namespace];
|
|
3
|
+
var snippet = require('@fullstory/snippet');
|
|
4
|
+
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
|
|
20
|
+
var __assign = function() {
|
|
21
|
+
__assign = Object.assign || function __assign(t) {
|
|
22
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
+
s = arguments[i];
|
|
24
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
};
|
|
28
|
+
return __assign.apply(this, arguments);
|
|
151
29
|
};
|
|
152
30
|
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
31
|
+
var getFullStory = function () {
|
|
32
|
+
if (window._fs_namespace) {
|
|
33
|
+
return window[window._fs_namespace];
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
159
36
|
};
|
|
160
|
-
|
|
161
|
-
var
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return testNames.every(function (current) {
|
|
169
|
-
return fs()[current];
|
|
170
|
-
});
|
|
37
|
+
var ensureSnippetLoaded = function () {
|
|
38
|
+
var fs = getFullStory();
|
|
39
|
+
if (!fs) {
|
|
40
|
+
throw Error('FullStory is not loaded, please ensure the init function is invoked before calling FullStory API functions');
|
|
41
|
+
}
|
|
42
|
+
return fs;
|
|
171
43
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return message;
|
|
44
|
+
var _init = function (inputOptions, readyCallback) {
|
|
45
|
+
// Make a copy so we can modify `options` if desired.
|
|
46
|
+
var options = __assign({}, inputOptions);
|
|
47
|
+
if (getFullStory()) {
|
|
48
|
+
console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
|
|
49
|
+
return;
|
|
179
50
|
}
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return (_fs = fs())[name].apply(_fs, arguments);
|
|
51
|
+
// see README for details on the recordCrossDomainIFrames option
|
|
52
|
+
if (options.recordCrossDomainIFrames) {
|
|
53
|
+
window._fs_run_in_iframe = true;
|
|
185
54
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
var
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (options.debug === true) {
|
|
224
|
-
if (!options.script) {
|
|
225
|
-
options.script = 'edge.fullstory.com/s/fs-debug.js';
|
|
226
|
-
} else {
|
|
227
|
-
console.warn('Ignoring `debug = true` because `script` is set');
|
|
55
|
+
// record the contents of this iFrame when embedded in a parent site
|
|
56
|
+
if (options.recordOnlyThisIFrame) {
|
|
57
|
+
window._fs_is_outer_script = true;
|
|
58
|
+
}
|
|
59
|
+
// Set cookie domain if it was specified.
|
|
60
|
+
if (options.cookieDomain) {
|
|
61
|
+
window._fs_cookie_domain = options.cookieDomain;
|
|
62
|
+
}
|
|
63
|
+
if (options.debug === true) {
|
|
64
|
+
if (!options.script) {
|
|
65
|
+
options.script = 'edge.fullstory.com/s/fs-debug.js';
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.warn('Ignoring `debug = true` because `script` is set');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
snippet.initFS(options);
|
|
72
|
+
var fs = getFullStory();
|
|
73
|
+
if (!fs) {
|
|
74
|
+
console.warn('Failed to initialize FS snippet');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (readyCallback) {
|
|
78
|
+
fs('observe', { type: 'start', callback: readyCallback });
|
|
79
|
+
}
|
|
80
|
+
if (options.devMode === true) {
|
|
81
|
+
var message = 'FullStory was initialized in devMode and will stop recording';
|
|
82
|
+
fs('trackEvent', {
|
|
83
|
+
name: 'FullStory Dev Mode',
|
|
84
|
+
properties: {
|
|
85
|
+
message_str: message,
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
fs('shutdown');
|
|
89
|
+
window._fs_dev_mode = true;
|
|
90
|
+
console.warn(message);
|
|
228
91
|
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
snippet(options);
|
|
232
|
-
|
|
233
|
-
if (readyCallback) {
|
|
234
|
-
fs()('observe', {
|
|
235
|
-
type: 'start',
|
|
236
|
-
callback: readyCallback
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (options.devMode === true) {
|
|
241
|
-
var message = 'FullStory was initialized in devMode and will stop recording';
|
|
242
|
-
event('FullStory Dev Mode', {
|
|
243
|
-
message_str: message
|
|
244
|
-
});
|
|
245
|
-
shutdown();
|
|
246
|
-
window._fs_dev_mode = true;
|
|
247
|
-
console.warn(message);
|
|
248
|
-
}
|
|
249
92
|
};
|
|
250
|
-
|
|
251
|
-
var initOnce = function initOnce(fn, message) {
|
|
252
|
-
return function () {
|
|
93
|
+
var initOnce = function (message) { return function (inputOptions, readyCallback) {
|
|
253
94
|
if (window._fs_initialized) {
|
|
254
|
-
|
|
255
|
-
|
|
95
|
+
if (message)
|
|
96
|
+
console.warn(message);
|
|
97
|
+
return;
|
|
256
98
|
}
|
|
257
|
-
|
|
258
|
-
fn.apply(void 0, arguments);
|
|
99
|
+
_init(inputOptions, readyCallback);
|
|
259
100
|
window._fs_initialized = true;
|
|
260
|
-
|
|
101
|
+
}; };
|
|
102
|
+
var init = initOnce('FullStory init has already been called once, additional invocations are ignored');
|
|
103
|
+
// normalize undefined into boolean
|
|
104
|
+
var isInitialized = function () { return !!window._fs_initialized; };
|
|
105
|
+
var hasFullStoryWithFunction = function () {
|
|
106
|
+
var testNames = [];
|
|
107
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
108
|
+
testNames[_i] = arguments[_i];
|
|
109
|
+
}
|
|
110
|
+
var fs = ensureSnippetLoaded();
|
|
111
|
+
return testNames.every(function (current) { return fs[current]; });
|
|
261
112
|
};
|
|
262
|
-
|
|
263
|
-
var
|
|
264
|
-
var
|
|
265
|
-
|
|
113
|
+
var guard = function (name) { return function () {
|
|
114
|
+
var args = [];
|
|
115
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
116
|
+
args[_i] = arguments[_i];
|
|
117
|
+
}
|
|
118
|
+
if (window._fs_dev_mode) {
|
|
119
|
+
var message = "FullStory is in dev mode and is not recording: ".concat(name, " method not executed");
|
|
120
|
+
console.warn(message);
|
|
121
|
+
return message;
|
|
122
|
+
}
|
|
123
|
+
var fs = getFullStory();
|
|
124
|
+
if (hasFullStoryWithFunction(name) && fs) {
|
|
125
|
+
return fs[name].apply(fs, args);
|
|
126
|
+
}
|
|
127
|
+
console.warn("FS.".concat(name, " not ready"));
|
|
128
|
+
return null;
|
|
129
|
+
}; };
|
|
130
|
+
var buildFullStoryShim = function () {
|
|
131
|
+
var FS = function (operation, options, source) {
|
|
132
|
+
var fs = ensureSnippetLoaded();
|
|
133
|
+
if (window._fs_dev_mode) {
|
|
134
|
+
var message = 'FullStory is in dev mode and is not recording: method not executed';
|
|
135
|
+
console.warn(message);
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
return fs(operation, options, source);
|
|
139
|
+
};
|
|
140
|
+
FS.anonymize = guard('anonymize');
|
|
141
|
+
FS.consent = guard('consent');
|
|
142
|
+
FS.disableConsole = guard('disableConsole');
|
|
143
|
+
FS.enableConsole = guard('enableConsole');
|
|
144
|
+
FS.event = guard('event');
|
|
145
|
+
FS.getCurrentSessionURL = guard('getCurrentSessionURL');
|
|
146
|
+
FS.identify = guard('identify');
|
|
147
|
+
FS.log = guard('log');
|
|
148
|
+
FS.restart = guard('restart');
|
|
149
|
+
FS.setUserVars = guard('setUserVars');
|
|
150
|
+
FS.setVars = guard('setVars');
|
|
151
|
+
FS.shutdown = guard('shutdown');
|
|
152
|
+
return FS;
|
|
266
153
|
};
|
|
154
|
+
var FullStory = buildFullStoryShim();
|
|
267
155
|
|
|
268
|
-
exports.
|
|
269
|
-
exports.consent = consent;
|
|
270
|
-
exports.event = event;
|
|
271
|
-
exports.getCurrentSessionURL = getCurrentSessionURL;
|
|
272
|
-
exports.identify = identify;
|
|
156
|
+
exports.FullStory = FullStory;
|
|
273
157
|
exports.init = init;
|
|
274
158
|
exports.isInitialized = isInitialized;
|
|
275
|
-
exports.log = log;
|
|
276
|
-
exports.restart = restart;
|
|
277
|
-
exports.setUserVars = setUserVars;
|
|
278
|
-
exports.setVars = setVars;
|
|
279
|
-
exports.shutdown = shutdown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fullstory/browser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"description": "The official FullStory browser SDK",
|
|
5
5
|
"repository": "git://github.com/fullstorydev/fullstory-browser-sdk.git",
|
|
6
6
|
"homepage": "https://github.com/fullstorydev/fullstory-browser-sdk",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"clean": "rimraf dist",
|
|
14
|
-
"
|
|
15
|
-
"test
|
|
16
|
-
"lint": "eslint src
|
|
17
|
-
"build": "
|
|
14
|
+
"pretest": "tsc --project tsconfig.test.json",
|
|
15
|
+
"test": "npm run lint && karma start --single-run --browsers ChromeHeadless karma.conf.js",
|
|
16
|
+
"lint": "eslint src",
|
|
17
|
+
"build": "rollup -c"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
@@ -25,12 +25,20 @@
|
|
|
25
25
|
"browser",
|
|
26
26
|
"sdk"
|
|
27
27
|
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@fullstory/snippet": "2.0.0-beta.2"
|
|
30
|
+
},
|
|
28
31
|
"devDependencies": {
|
|
29
32
|
"@babel/core": "^7.8.7",
|
|
30
33
|
"@babel/eslint-parser": "^7.16.5",
|
|
31
34
|
"@babel/preset-env": "^7.10.4",
|
|
32
35
|
"@babel/register": "^7.8.6",
|
|
33
|
-
"@rollup/plugin-
|
|
36
|
+
"@rollup/plugin-typescript": "^11.1.0",
|
|
37
|
+
"@types/chai": "^4.3.4",
|
|
38
|
+
"@types/mocha": "^10.0.1",
|
|
39
|
+
"@types/node": "^18.15.11",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.58.0",
|
|
41
|
+
"@typescript-eslint/parser": "^5.58.0",
|
|
34
42
|
"chai": "^4.1.2",
|
|
35
43
|
"eslint": "^8.6.0",
|
|
36
44
|
"eslint-config-airbnb": "^19.0.4",
|
|
@@ -45,9 +53,9 @@
|
|
|
45
53
|
"karma-webpack": "^5.0.0",
|
|
46
54
|
"mocha": "^9.2.0",
|
|
47
55
|
"rimraf": "^2.7.1",
|
|
48
|
-
"rollup": "^
|
|
49
|
-
"
|
|
50
|
-
"typescript": "^
|
|
51
|
-
"webpack": "^5.
|
|
56
|
+
"rollup": "^3.21.0",
|
|
57
|
+
"tslib": "^2.5.0",
|
|
58
|
+
"typescript": "^4.2.4",
|
|
59
|
+
"webpack": "^5.76.1"
|
|
52
60
|
}
|
|
53
61
|
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { assert, expect } from 'chai';
|
|
2
|
+
import {
|
|
3
|
+
FullStory as FS,
|
|
4
|
+
init,
|
|
5
|
+
isInitialized,
|
|
6
|
+
SnippetOptions,
|
|
7
|
+
} from '.';
|
|
8
|
+
|
|
9
|
+
const testOrg = '123';
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
if (window[window._fs_namespace ?? '']) {
|
|
13
|
+
delete window._fs_initialized;
|
|
14
|
+
delete window._fs_dev_mode;
|
|
15
|
+
delete window[window._fs_namespace ?? ''];
|
|
16
|
+
delete window._fs_namespace;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('init', () => {
|
|
21
|
+
it('should throw error if not initialized with an orgId', () => {
|
|
22
|
+
expect(() => { init({} as SnippetOptions); }).to.throw();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should throw error if API called before init', () => {
|
|
26
|
+
try {
|
|
27
|
+
FS('log', { msg: 'my log' });
|
|
28
|
+
expect(false).to.be('this should have thrown');
|
|
29
|
+
} catch (error) {
|
|
30
|
+
expect((error as Error).message).to.match(/FullStory is not loaded/);
|
|
31
|
+
}
|
|
32
|
+
init({ orgId: testOrg });
|
|
33
|
+
expect(() => { FS('log', { msg: 'my log' }); }).to.not.throw();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should add _fs_org value to window object', () => {
|
|
37
|
+
init({ orgId: testOrg });
|
|
38
|
+
expect(window._fs_org).to.equal(testOrg);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should add _fs_run_in_iframe value to window object', () => {
|
|
42
|
+
init({
|
|
43
|
+
orgId: testOrg,
|
|
44
|
+
recordCrossDomainIFrames: true,
|
|
45
|
+
});
|
|
46
|
+
expect(window._fs_run_in_iframe).to.equal(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should add _fs_is_outer_script value to window object', () => {
|
|
50
|
+
init({
|
|
51
|
+
orgId: testOrg,
|
|
52
|
+
recordOnlyThisIFrame: true,
|
|
53
|
+
});
|
|
54
|
+
expect(window._fs_is_outer_script).to.equal(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should add _fs_dev_mode value to window when initialzed with devMode', () => {
|
|
58
|
+
init({
|
|
59
|
+
orgId: testOrg,
|
|
60
|
+
devMode: true,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(window._fs_dev_mode).to.equal(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should return whether initialized', () => {
|
|
67
|
+
let isInit = isInitialized();
|
|
68
|
+
expect(isInit).to.equal(false);
|
|
69
|
+
|
|
70
|
+
init({
|
|
71
|
+
orgId: testOrg,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
isInit = isInitialized();
|
|
75
|
+
expect(isInit).to.equal(true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should load fs-debug.js when debug is set', () => {
|
|
79
|
+
init({
|
|
80
|
+
orgId: testOrg,
|
|
81
|
+
debug: true,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(window._fs_script).to.match(/fs-debug.js$/);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('devMode', () => {
|
|
89
|
+
let consoleWarnedMessage;
|
|
90
|
+
const oldConsoleWarn = console.warn;
|
|
91
|
+
beforeEach(() => {
|
|
92
|
+
console.warn = (msg) => { consoleWarnedMessage = msg; };
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
afterEach(() => {
|
|
96
|
+
console.warn = oldConsoleWarn;
|
|
97
|
+
consoleWarnedMessage = undefined;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should return a message for functions invoked when in devMode', () => {
|
|
101
|
+
expect(consoleWarnedMessage).to.equal(undefined);
|
|
102
|
+
init({
|
|
103
|
+
orgId: testOrg,
|
|
104
|
+
devMode: true,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(consoleWarnedMessage).to.match(/FullStory was initialized in devMode/);
|
|
108
|
+
|
|
109
|
+
FS('log', { msg: 'hello world' });
|
|
110
|
+
|
|
111
|
+
expect(consoleWarnedMessage).to.match(/FullStory is in dev mode/);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('getCurrentSessionURL', () => {
|
|
116
|
+
it('should return null before fs.js is fully bootstrapped', () => {
|
|
117
|
+
init({ orgId: testOrg });
|
|
118
|
+
// in theory, this is a race condition - assuming that fs.js
|
|
119
|
+
// can't load by the time the following statement is executed
|
|
120
|
+
const url = FS('getSession');
|
|
121
|
+
assert.equal(
|
|
122
|
+
url,
|
|
123
|
+
null,
|
|
124
|
+
'FullStory.getCurrentSessionURL() should return null if executed before fs.js is fully bootstrapped'
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('typescript safety', () => {
|
|
130
|
+
it('provides type assistance matching the api', () => {
|
|
131
|
+
// Just a quick non-exhaustive check that types are working as expected.
|
|
132
|
+
// The "@ts-expect-error" declaration will fail if the types do NOT throw
|
|
133
|
+
// an error.
|
|
134
|
+
init({ orgId: testOrg });
|
|
135
|
+
|
|
136
|
+
// Passes TypeScript check
|
|
137
|
+
FS('getSession', { format: 'url.now' });
|
|
138
|
+
|
|
139
|
+
// Does not pass (improper format)
|
|
140
|
+
// @ts-expect-error (for testing purposes)
|
|
141
|
+
FS('getSession', { format: '😏' });
|
|
142
|
+
|
|
143
|
+
// Does not pass (invalid action)
|
|
144
|
+
// @ts-expect-error (for testing purposes)
|
|
145
|
+
FS('🦄');
|
|
146
|
+
|
|
147
|
+
// Passes TypeScript check
|
|
148
|
+
FS('observe', { type: 'start', callback: () => console.log('STARTED') });
|
|
149
|
+
|
|
150
|
+
// Does not pass (improper type)
|
|
151
|
+
// @ts-expect-error (for testing purposes)
|
|
152
|
+
FS('observe', { type: '🦂', callback: () => console.log('STARTED') });
|
|
153
|
+
|
|
154
|
+
// LEGACY:
|
|
155
|
+
// Passes TypeScript check
|
|
156
|
+
FS.setVars('user', { email: 'e@mail.com' });
|
|
157
|
+
|
|
158
|
+
// Does not pass (improper VarScope)
|
|
159
|
+
// @ts-expect-error (for testing purposes)
|
|
160
|
+
FS.setVars('🤯', { email: 'e@mail.com' });
|
|
161
|
+
|
|
162
|
+
// Passes TypeScript check
|
|
163
|
+
FS.event('Order Complete', { product_id: 'asdf' });
|
|
164
|
+
|
|
165
|
+
// Does not pass (eventName must be string)
|
|
166
|
+
// @ts-expect-error (for testing purposes)
|
|
167
|
+
FS.event(42, { product_id: 'asdf' });
|
|
168
|
+
|
|
169
|
+
// Assertion for posterity's sake...
|
|
170
|
+
expect(true).to.equal(true);
|
|
171
|
+
});
|
|
172
|
+
});
|