@newrelic/browser-agent 0.1.230 → 0.1.231
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/README.md +25 -1
- package/dist/cjs/common/browser-version/ios-version.js +4 -3
- package/dist/cjs/common/config/state/configurable.js +1 -1
- package/dist/cjs/common/config/state/info.js +1 -1
- package/dist/cjs/common/config/state/init.js +1 -1
- package/dist/cjs/common/config/state/loader-config.js +1 -1
- package/dist/cjs/common/config/state/runtime.js +5 -5
- package/dist/cjs/common/constants/env.cdn.js +29 -0
- package/dist/cjs/common/constants/env.js +32 -0
- package/dist/cjs/common/constants/env.npm.js +30 -0
- package/dist/cjs/common/event-emitter/contextual-ee.test.js +282 -0
- package/dist/cjs/common/event-emitter/handle.test.js +58 -0
- package/dist/cjs/common/event-emitter/register-handler.test.js +55 -0
- package/dist/cjs/common/harvest/harvest.js +2 -2
- package/dist/cjs/common/ids/id.js +14 -6
- package/dist/cjs/common/ids/id.test.js +85 -0
- package/dist/cjs/common/ids/unique-id.js +75 -51
- package/dist/cjs/common/ids/unique-id.test.js +49 -0
- package/dist/cjs/common/timing/nav-timing.js +51 -30
- package/dist/cjs/common/timing/nav-timing.test.js +192 -0
- package/dist/cjs/common/url/clean-url.test.js +9 -0
- package/dist/cjs/common/url/encode.test.js +74 -0
- package/dist/cjs/common/url/location.js +4 -0
- package/dist/cjs/common/url/location.test.js +13 -0
- package/dist/cjs/common/url/parse-url.test.js +111 -0
- package/dist/cjs/common/url/protocol.js +2 -12
- package/dist/cjs/common/url/protocol.test.js +16 -0
- package/dist/cjs/common/util/console.js +1 -1
- package/dist/cjs/common/util/map-own.test.js +3 -3
- package/dist/cjs/common/util/obfuscate.js +1 -1
- package/dist/cjs/common/window/page-visibility.js +2 -1
- package/dist/cjs/common/wrap/index.js +0 -7
- package/dist/cjs/common/wrap/wrap-events.js +6 -9
- package/dist/cjs/common/wrap/wrap-fetch.js +6 -6
- package/dist/cjs/common/wrap/wrap-history.js +7 -6
- package/dist/cjs/common/wrap/wrap-jsonp.js +7 -6
- package/dist/cjs/common/wrap/wrap-mutation.js +7 -6
- package/dist/cjs/common/wrap/wrap-promise.js +7 -6
- package/dist/cjs/common/wrap/wrap-promise.test.js +119 -0
- package/dist/cjs/common/wrap/wrap-raf.js +6 -6
- package/dist/cjs/common/wrap/wrap-timer.js +6 -6
- package/dist/cjs/common/wrap/wrap-xhr.js +5 -6
- package/dist/cjs/features/ajax/aggregate/index.js +1 -1
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
- package/dist/cjs/features/jserrors/aggregate/index.js +3 -3
- package/dist/cjs/features/jserrors/instrument/index.js +2 -2
- package/dist/cjs/features/metrics/aggregate/index.js +6 -7
- package/dist/cjs/features/metrics/instrument/index.js +0 -25
- package/dist/cjs/features/metrics/instrument/workers-helper.js +5 -5
- package/dist/cjs/features/page_action/aggregate/index.js +1 -1
- package/dist/cjs/features/page_view_event/aggregate/index.js +17 -6
- package/dist/cjs/features/page_view_timing/aggregate/index.js +36 -26
- package/dist/cjs/features/session_trace/aggregate/index.js +16 -13
- package/dist/cjs/features/utils/instrument-base.js +6 -2
- package/dist/cjs/features/utils/lazy-loader.js +1 -1
- package/dist/cjs/loaders/agent.js +1 -1
- package/dist/cjs/loaders/api/api.js +8 -5
- package/dist/cjs/loaders/features/enabled-features.js +1 -1
- package/dist/cjs/loaders/micro-agent.js +2 -1
- package/dist/esm/common/browser-version/ios-version.js +4 -3
- package/dist/esm/common/config/state/configurable.js +1 -1
- package/dist/esm/common/config/state/info.js +1 -1
- package/dist/esm/common/config/state/init.js +1 -1
- package/dist/esm/common/config/state/loader-config.js +1 -1
- package/dist/esm/common/config/state/runtime.js +2 -2
- package/dist/esm/common/constants/env.cdn.js +20 -0
- package/dist/esm/common/constants/env.js +23 -0
- package/dist/esm/common/constants/env.npm.js +21 -0
- package/dist/esm/common/event-emitter/contextual-ee.test.js +278 -0
- package/dist/esm/common/event-emitter/handle.test.js +54 -0
- package/dist/esm/common/event-emitter/register-handler.test.js +51 -0
- package/dist/esm/common/harvest/harvest.js +1 -1
- package/dist/esm/common/ids/id.js +16 -6
- package/dist/esm/common/ids/id.test.js +81 -0
- package/dist/esm/common/ids/unique-id.js +75 -51
- package/dist/esm/common/ids/unique-id.test.js +44 -0
- package/dist/esm/common/timing/nav-timing.js +51 -29
- package/dist/esm/common/timing/nav-timing.test.js +190 -0
- package/dist/esm/common/url/clean-url.test.js +7 -0
- package/dist/esm/common/url/encode.test.js +70 -0
- package/dist/esm/common/url/location.js +4 -0
- package/dist/esm/common/url/location.test.js +11 -0
- package/dist/esm/common/url/parse-url.test.js +107 -0
- package/dist/esm/common/url/protocol.js +3 -12
- package/dist/esm/common/url/protocol.test.js +14 -0
- package/dist/esm/common/util/console.js +1 -1
- package/dist/esm/common/util/map-own.test.js +3 -3
- package/dist/esm/common/util/obfuscate.js +2 -2
- package/dist/esm/common/window/page-visibility.js +2 -1
- package/dist/esm/common/wrap/index.js +1 -2
- package/dist/esm/common/wrap/wrap-events.js +6 -9
- package/dist/esm/common/wrap/wrap-fetch.js +6 -6
- package/dist/esm/common/wrap/wrap-history.js +7 -6
- package/dist/esm/common/wrap/wrap-jsonp.js +7 -6
- package/dist/esm/common/wrap/wrap-mutation.js +7 -6
- package/dist/esm/common/wrap/wrap-promise.js +7 -6
- package/dist/esm/common/wrap/wrap-promise.test.js +115 -0
- package/dist/esm/common/wrap/wrap-raf.js +6 -6
- package/dist/esm/common/wrap/wrap-timer.js +6 -6
- package/dist/esm/common/wrap/wrap-xhr.js +5 -6
- package/dist/esm/features/ajax/aggregate/index.js +1 -1
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
- package/dist/esm/features/jserrors/aggregate/index.js +3 -3
- package/dist/esm/features/jserrors/instrument/index.js +2 -2
- package/dist/esm/features/metrics/aggregate/index.js +7 -8
- package/dist/esm/features/metrics/instrument/index.js +0 -25
- package/dist/esm/features/metrics/instrument/workers-helper.js +5 -5
- package/dist/esm/features/page_action/aggregate/index.js +1 -1
- package/dist/esm/features/page_view_event/aggregate/index.js +17 -6
- package/dist/esm/features/page_view_timing/aggregate/index.js +36 -26
- package/dist/esm/features/session_trace/aggregate/index.js +16 -13
- package/dist/esm/features/utils/instrument-base.js +1 -1
- package/dist/esm/features/utils/lazy-loader.js +1 -1
- package/dist/esm/loaders/agent.js +1 -1
- package/dist/esm/loaders/api/api.js +4 -4
- package/dist/esm/loaders/features/enabled-features.js +1 -1
- package/dist/types/common/config/state/runtime.d.ts.map +1 -1
- package/dist/types/common/constants/env.cdn.d.ts +18 -0
- package/dist/types/common/constants/env.cdn.d.ts.map +1 -0
- package/dist/types/common/constants/env.d.ts +13 -0
- package/dist/types/common/constants/env.d.ts.map +1 -0
- package/dist/types/common/constants/env.npm.d.ts +19 -0
- package/dist/types/common/constants/env.npm.d.ts.map +1 -0
- package/dist/types/common/ids/id.d.ts +11 -1
- package/dist/types/common/ids/id.d.ts.map +1 -1
- package/dist/types/common/ids/unique-id.d.ts +24 -1
- package/dist/types/common/ids/unique-id.d.ts.map +1 -1
- package/dist/types/common/timing/nav-timing.d.ts +1 -2
- package/dist/types/common/timing/nav-timing.d.ts.map +1 -1
- package/dist/types/common/unload/eol.d.ts.map +1 -1
- package/dist/types/common/url/location.d.ts +4 -0
- package/dist/types/common/url/location.d.ts.map +1 -1
- package/dist/types/common/url/parse-url.d.ts.map +1 -1
- package/dist/types/common/url/protocol.d.ts +1 -6
- package/dist/types/common/url/protocol.d.ts.map +1 -1
- package/dist/types/common/util/global-scope.d.ts.map +1 -1
- package/dist/types/common/wrap/index.d.ts +1 -2
- package/dist/types/common/wrap/index.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-history.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/index.d.ts +0 -1
- package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_timing/aggregate/index.d.ts +1 -2
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
- package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
- package/package.json +9 -30
- package/src/common/browser-version/ios-version.js +4 -3
- package/src/common/config/state/runtime.js +26 -24
- package/src/common/constants/env.cdn.js +20 -0
- package/src/common/constants/env.js +23 -0
- package/src/common/constants/env.npm.js +21 -0
- package/src/common/event-emitter/contextual-ee.test.js +310 -0
- package/src/common/event-emitter/handle.test.js +56 -0
- package/src/common/event-emitter/register-handler.test.js +61 -0
- package/src/common/harvest/harvest.js +2 -2
- package/src/common/ids/id.js +15 -6
- package/src/common/ids/id.test.js +92 -0
- package/src/common/ids/unique-id.js +77 -54
- package/src/common/ids/unique-id.test.js +58 -0
- package/src/common/timing/nav-timing.js +50 -30
- package/src/common/timing/nav-timing.test.js +161 -0
- package/src/common/unload/eol.js +1 -2
- package/src/common/url/clean-url.test.js +25 -0
- package/src/common/url/encode.test.js +80 -0
- package/src/common/url/location.js +4 -0
- package/src/common/url/location.test.js +15 -0
- package/src/common/url/parse-url.js +1 -2
- package/src/common/url/parse-url.test.js +110 -0
- package/src/common/url/protocol.js +3 -13
- package/src/common/url/protocol.test.js +18 -0
- package/src/common/util/global-scope.js +1 -2
- package/src/common/util/obfuscate.js +2 -2
- package/src/common/window/page-visibility.js +1 -1
- package/src/common/wrap/index.js +1 -2
- package/src/common/wrap/wrap-events.js +5 -5
- package/src/common/wrap/wrap-fetch.js +4 -3
- package/src/common/wrap/wrap-history.js +6 -3
- package/src/common/wrap/wrap-jsonp.js +5 -3
- package/src/common/wrap/wrap-mutation.js +6 -3
- package/src/common/wrap/wrap-promise.js +7 -6
- package/src/common/wrap/wrap-promise.test.js +140 -0
- package/src/common/wrap/wrap-raf.js +5 -3
- package/src/common/wrap/wrap-timer.js +5 -3
- package/src/common/wrap/wrap-xhr.js +4 -3
- package/src/features/ajax/instrument/index.js +1 -1
- package/src/features/jserrors/instrument/index.js +4 -2
- package/src/features/metrics/aggregate/index.js +3 -4
- package/src/features/metrics/instrument/index.js +0 -30
- package/src/features/metrics/instrument/workers-helper.js +9 -6
- package/src/features/page_view_event/aggregate/index.js +15 -6
- package/src/features/page_view_timing/aggregate/index.js +36 -25
- package/src/features/page_view_timing/long-tasks.js +10 -10
- package/src/features/session_trace/aggregate/index.js +15 -12
- package/src/features/session_trace/instrument/index.js +3 -2
- package/src/features/spa/instrument/index.js +4 -2
- package/src/loaders/api/api.js +1 -1
- package/dist/cjs/common/constants/environment-variables.js +0 -20
- package/dist/cjs/common/wrap/wrap-console.js +0 -54
- package/dist/esm/common/constants/environment-variables.js +0 -11
- package/dist/esm/common/wrap/wrap-console.js +0 -46
- package/dist/types/common/constants/environment-variables.d.ts +0 -4
- package/dist/types/common/constants/environment-variables.d.ts.map +0 -1
- package/dist/types/common/wrap/wrap-console.d.ts +0 -16
- package/dist/types/common/wrap/wrap-console.d.ts.map +0 -1
- package/src/common/constants/environment-variables.js +0 -11
- package/src/common/wrap/wrap-console.js +0 -47
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
<a href="https://opensource.newrelic.com/oss-category/#community-plus"><picture><source media="(prefers-color-scheme: dark)" srcset="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/dark/Community_Plus.png"><source media="(prefers-color-scheme: light)" srcset="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Community_Plus.png"><img alt="New Relic Open Source community plus project banner." src="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Community_Plus.png"></picture></a>
|
|
2
2
|
|
|
3
3
|
# New Relic Browser Agent
|
|
4
4
|
|
|
@@ -170,6 +170,30 @@ import { Agent } from '@newrelic/browser-agent/loaders/agent'
|
|
|
170
170
|
import { Metrics } from '@newrelic/browser-agent/src/features/metrics'
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
+
## Support
|
|
174
|
+
|
|
175
|
+
New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there's a related Community topic in the New Relic Explorers Hub. You can find this project's topic/threads here:
|
|
176
|
+
|
|
177
|
+
https://discuss.newrelic.com/c/full-stack-observability/browser
|
|
178
|
+
|
|
179
|
+
## Contribute
|
|
180
|
+
|
|
181
|
+
We encourage your contributions to improve the Browser agent! Keep in mind that when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.
|
|
182
|
+
|
|
183
|
+
If you have any questions, or to execute our corporate CLA (which is required if your contribution is on behalf of a company), drop us an email at opensource@newrelic.com.
|
|
184
|
+
|
|
185
|
+
For more details on how best to contribute, see [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
186
|
+
|
|
187
|
+
**A note about vulnerabilities**
|
|
188
|
+
|
|
189
|
+
As noted in our [security policy](https://github.com/newrelic/newrelic-browser-agent/security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
|
|
190
|
+
|
|
191
|
+
If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through [HackerOne](https://hackerone.com/newrelic).
|
|
192
|
+
|
|
193
|
+
If you would like to contribute to this project, review [these guidelines](./CONTRIBUTING.md).
|
|
194
|
+
|
|
195
|
+
To all contributors, we thank you! Without your contribution, this project would not be what it is today. We also host [a community project page dedicated to the Browser agent](https://opensource.newrelic.com/projects/newrelic/newrelic-browser-agent).
|
|
196
|
+
|
|
173
197
|
## License
|
|
174
198
|
|
|
175
199
|
The Browser agent is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
|
|
@@ -11,8 +11,9 @@ const isiOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
|
|
|
11
11
|
// Shared Web Workers introduced in iOS 16.0+ and n/a in 15.6-
|
|
12
12
|
exports.isiOS = isiOS;
|
|
13
13
|
const iOS_below16 = isiOS && Boolean(typeof SharedWorker === 'undefined');
|
|
14
|
-
/*
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/*
|
|
15
|
+
^ It was discovered in Safari 14 (https://bugs.webkit.org/show_bug.cgi?id=225305) that the buffered flag in PerformanceObserver
|
|
16
|
+
did not work. This affects our onFCP metric in particular since web-vitals uses that flag to retrieve paint timing entries.
|
|
17
|
+
This was fixed in v16+.
|
|
17
18
|
*/
|
|
18
19
|
exports.iOS_below16 = iOS_below16;
|
|
@@ -18,7 +18,7 @@ class Configurable {
|
|
|
18
18
|
if (frozenAttrs.length && value && typeof value === 'object') {
|
|
19
19
|
frozenAttrs.forEach(attr => {
|
|
20
20
|
if (attr in value) {
|
|
21
|
-
(0, _console.warn)(
|
|
21
|
+
(0, _console.warn)("\"".concat(attr, "\" is a protected attribute and can not be changed in feature ").concat(key, ". It will have no effect."));
|
|
22
22
|
delete value[attr];
|
|
23
23
|
}
|
|
24
24
|
});
|
|
@@ -40,7 +40,7 @@ function isValid(id) {
|
|
|
40
40
|
}
|
|
41
41
|
function getInfo(id) {
|
|
42
42
|
if (!id) throw new Error('All info objects require an agent identifier!');
|
|
43
|
-
if (!_cache[id]) throw new Error(
|
|
43
|
+
if (!_cache[id]) throw new Error("Info for ".concat(id, " was never set"));
|
|
44
44
|
return _cache[id];
|
|
45
45
|
}
|
|
46
46
|
function setInfo(id, obj) {
|
|
@@ -60,7 +60,7 @@ const model = {
|
|
|
60
60
|
const _cache = {};
|
|
61
61
|
function getConfiguration(id) {
|
|
62
62
|
if (!id) throw new Error('All configuration objects require an agent identifier!');
|
|
63
|
-
if (!_cache[id]) throw new Error(
|
|
63
|
+
if (!_cache[id]) throw new Error("Configuration for ".concat(id, " was never set"));
|
|
64
64
|
return _cache[id];
|
|
65
65
|
}
|
|
66
66
|
function setConfiguration(id, obj) {
|
|
@@ -18,7 +18,7 @@ const model = {
|
|
|
18
18
|
const _cache = {};
|
|
19
19
|
function getLoaderConfig(id) {
|
|
20
20
|
if (!id) throw new Error('All loader-config objects require an agent identifier!');
|
|
21
|
-
if (!_cache[id]) throw new Error(
|
|
21
|
+
if (!_cache[id]) throw new Error("LoaderConfig for ".concat(id, " was never set"));
|
|
22
22
|
return _cache[id];
|
|
23
23
|
}
|
|
24
24
|
function setLoaderConfig(id, obj) {
|
|
@@ -11,16 +11,16 @@ var _nreum = require("../../window/nreum");
|
|
|
11
11
|
var _sessionStorage = require("../../window/session-storage");
|
|
12
12
|
var _config = require("../config");
|
|
13
13
|
var _globalScope = require("../../util/global-scope");
|
|
14
|
-
var
|
|
14
|
+
var _env = require("../../constants/env.npm");
|
|
15
15
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
16
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
17
|
const model = agentId => {
|
|
18
18
|
return {
|
|
19
|
-
buildEnv:
|
|
19
|
+
buildEnv: _env.BUILD_ENV,
|
|
20
20
|
bytesSent: {},
|
|
21
21
|
customTransaction: undefined,
|
|
22
22
|
disabled: false,
|
|
23
|
-
distMethod:
|
|
23
|
+
distMethod: _env.DIST_METHOD,
|
|
24
24
|
isolatedBacklog: false,
|
|
25
25
|
loaderType: undefined,
|
|
26
26
|
maxBytes: 30000,
|
|
@@ -35,13 +35,13 @@ const model = agentId => {
|
|
|
35
35
|
// if cookies (now session tracking) is turned off or can't get session ID, this is null
|
|
36
36
|
xhrWrappable: typeof _globalScope.globalScope.XMLHttpRequest?.prototype?.addEventListener === 'function',
|
|
37
37
|
userAgent,
|
|
38
|
-
version:
|
|
38
|
+
version: _env.VERSION
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
const _cache = {};
|
|
42
42
|
function getRuntime(id) {
|
|
43
43
|
if (!id) throw new Error('All runtime objects require an agent identifier!');
|
|
44
|
-
if (!_cache[id]) throw new Error(
|
|
44
|
+
if (!_cache[id]) throw new Error("Runtime for ".concat(id, " was never set"));
|
|
45
45
|
return _cache[id];
|
|
46
46
|
}
|
|
47
47
|
function setRuntime(id, obj) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @file This file exposes CDN build environment variables. These variables will
|
|
9
|
+
* be overridden with babel.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Exposes the version of the agent
|
|
14
|
+
*/
|
|
15
|
+
const VERSION = "1.231.0";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Exposes the build type of the agent
|
|
19
|
+
* Valid values are LOCAL, PROD, DEV
|
|
20
|
+
*/
|
|
21
|
+
exports.VERSION = VERSION;
|
|
22
|
+
const BUILD_ENV = undefined;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Exposes the distribution method of the agent
|
|
26
|
+
*/
|
|
27
|
+
exports.BUILD_ENV = BUILD_ENV;
|
|
28
|
+
const DIST_METHOD = 'CDN';
|
|
29
|
+
exports.DIST_METHOD = DIST_METHOD;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
|
|
7
|
+
var _package = _interopRequireDefault(require("../../../package.json"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
/**
|
|
10
|
+
* @file This file exposes build time environment variables that will be included in the
|
|
11
|
+
* build output of the agent. This file specifically contains the normal environment variables
|
|
12
|
+
* for the NPM agent build and will be overridden by webpack/babel during the build based on the
|
|
13
|
+
* type of build being performed.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Exposes the version of the agent
|
|
18
|
+
*/
|
|
19
|
+
const VERSION = _package.default.version;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Exposes the build type of the agent
|
|
23
|
+
*/
|
|
24
|
+
exports.VERSION = VERSION;
|
|
25
|
+
const BUILD_ENV = 'NPM';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Exposes the distribution method of the agent
|
|
29
|
+
*/
|
|
30
|
+
exports.BUILD_ENV = BUILD_ENV;
|
|
31
|
+
const DIST_METHOD = 'NPM';
|
|
32
|
+
exports.DIST_METHOD = DIST_METHOD;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @file This file exposes NPM build environment variables. These variables will
|
|
9
|
+
* be overridden with babel.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Exposes the version of the agent
|
|
14
|
+
*/
|
|
15
|
+
const VERSION = "1.231.0";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Exposes the build type of the agent
|
|
19
|
+
* Valid values are LOCAL, PROD, DEV
|
|
20
|
+
*/
|
|
21
|
+
exports.VERSION = VERSION;
|
|
22
|
+
const BUILD_ENV = 'NPM';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Exposes the distribution method of the agent
|
|
26
|
+
* Valid valuse are CDN, NPM
|
|
27
|
+
*/
|
|
28
|
+
exports.BUILD_ENV = BUILD_ENV;
|
|
29
|
+
const DIST_METHOD = 'NPM';
|
|
30
|
+
exports.DIST_METHOD = DIST_METHOD;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _faker = require("@faker-js/faker");
|
|
4
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
5
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
let mockNREUM;
|
|
7
|
+
let runtime;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockNREUM = {};
|
|
10
|
+
runtime = {};
|
|
11
|
+
jest.doMock('../window/nreum', () => ({
|
|
12
|
+
__esModule: true,
|
|
13
|
+
gosNREUM: jest.fn(() => mockNREUM)
|
|
14
|
+
}));
|
|
15
|
+
jest.doMock('../config/config', () => ({
|
|
16
|
+
__esModule: true,
|
|
17
|
+
getRuntime: jest.fn(() => runtime)
|
|
18
|
+
}));
|
|
19
|
+
});
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
jest.resetModules();
|
|
22
|
+
jest.resetAllMocks();
|
|
23
|
+
});
|
|
24
|
+
describe('global event-emitter', () => {
|
|
25
|
+
test('it returns the event-emitter defined on window.NREUM', async () => {
|
|
26
|
+
const mockEE = {};
|
|
27
|
+
mockNREUM.ee = mockEE;
|
|
28
|
+
const {
|
|
29
|
+
ee
|
|
30
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
31
|
+
expect(ee).toEqual(mockEE);
|
|
32
|
+
});
|
|
33
|
+
test('it sets the global event-emitter on window.NREUM', async () => {
|
|
34
|
+
const {
|
|
35
|
+
ee
|
|
36
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
37
|
+
expect(ee).toEqual(mockNREUM.ee);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe('scoping event-emitter', () => {
|
|
41
|
+
test('it creates a new child event-emitter', async () => {
|
|
42
|
+
const {
|
|
43
|
+
ee
|
|
44
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
45
|
+
const childName = _faker.faker.datatype.uuid();
|
|
46
|
+
const result = ee.get(childName);
|
|
47
|
+
expect(result).not.toEqual(mockNREUM.ee);
|
|
48
|
+
expect(result).toEqual(ee.get(childName)); // Should always return the same event-emitter
|
|
49
|
+
expect(result.debugId).toEqual(childName);
|
|
50
|
+
});
|
|
51
|
+
test('it creates a child event-emitter with an isolated backlog', async () => {
|
|
52
|
+
const childName = _faker.faker.random.alphaNumeric(16);
|
|
53
|
+
jest.doMock('../config/config', () => ({
|
|
54
|
+
__esModule: true,
|
|
55
|
+
getRuntime: jest.fn(id => {
|
|
56
|
+
if (id === childName) {
|
|
57
|
+
return {
|
|
58
|
+
isolatedBacklog: true
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return runtime;
|
|
62
|
+
})
|
|
63
|
+
}));
|
|
64
|
+
const {
|
|
65
|
+
ee
|
|
66
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
67
|
+
const result = ee.get(childName);
|
|
68
|
+
expect(ee.backlog).not.toBe(result.backlog);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('event-emitter context', () => {
|
|
72
|
+
test('it returns a new context', async () => {
|
|
73
|
+
const {
|
|
74
|
+
ee
|
|
75
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
76
|
+
const result = ee.context();
|
|
77
|
+
expect(result).toEqual({});
|
|
78
|
+
});
|
|
79
|
+
test('it returns the same context', async () => {
|
|
80
|
+
const {
|
|
81
|
+
ee
|
|
82
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
83
|
+
const result = ee.context();
|
|
84
|
+
expect(result).toEqual(ee.context(result));
|
|
85
|
+
});
|
|
86
|
+
test('it adds the context to the provided object', async () => {
|
|
87
|
+
const {
|
|
88
|
+
ee
|
|
89
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
90
|
+
const obj = {};
|
|
91
|
+
const result = ee.context(obj);
|
|
92
|
+
expect(result).toEqual(obj['nr@context']);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe('event-emitter buffer', () => {
|
|
96
|
+
it('it should create a new buffer for the given group', async () => {
|
|
97
|
+
const {
|
|
98
|
+
ee
|
|
99
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
100
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
101
|
+
const group = _faker.faker.datatype.uuid();
|
|
102
|
+
ee.buffer([eventType], group);
|
|
103
|
+
expect(ee.backlog).toEqual(expect.objectContaining({
|
|
104
|
+
[group]: []
|
|
105
|
+
}));
|
|
106
|
+
expect(ee.isBuffering(eventType)).toEqual(true);
|
|
107
|
+
});
|
|
108
|
+
it('it should default group to "feature"', async () => {
|
|
109
|
+
const {
|
|
110
|
+
ee
|
|
111
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
112
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
113
|
+
ee.buffer([eventType]);
|
|
114
|
+
expect(ee.backlog).toEqual(expect.objectContaining({
|
|
115
|
+
feature: []
|
|
116
|
+
}));
|
|
117
|
+
expect(ee.isBuffering(eventType)).toEqual(true);
|
|
118
|
+
});
|
|
119
|
+
it('it should not create buffer if event-emitter is aborted', async () => {
|
|
120
|
+
const {
|
|
121
|
+
ee
|
|
122
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
123
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
124
|
+
const group = _faker.faker.datatype.uuid();
|
|
125
|
+
ee.backlog = {
|
|
126
|
+
api: ['foo', 'bar', 'baz']
|
|
127
|
+
};
|
|
128
|
+
ee.abort();
|
|
129
|
+
ee.buffer([eventType], group);
|
|
130
|
+
expect(ee.backlog).toEqual({});
|
|
131
|
+
expect(ee.isBuffering(eventType)).toEqual(false);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
describe('event-emitter abort', () => {
|
|
135
|
+
test('it aborts if there is an API backlog', async () => {
|
|
136
|
+
const {
|
|
137
|
+
ee
|
|
138
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
139
|
+
ee.backlog = {
|
|
140
|
+
api: ['foo', 'bar', 'baz']
|
|
141
|
+
};
|
|
142
|
+
ee.abort();
|
|
143
|
+
expect(ee.aborted).toEqual(true);
|
|
144
|
+
expect(ee.backlog).toEqual({});
|
|
145
|
+
});
|
|
146
|
+
test('it aborts if there is a feature backlog', async () => {
|
|
147
|
+
const {
|
|
148
|
+
ee
|
|
149
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
150
|
+
ee.backlog = {
|
|
151
|
+
feature: ['foo', 'bar', 'baz']
|
|
152
|
+
};
|
|
153
|
+
ee.abort();
|
|
154
|
+
expect(ee.aborted).toEqual(true);
|
|
155
|
+
expect(ee.backlog).toEqual({});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('event-emitter emit', () => {
|
|
159
|
+
it('should execute the listener', async () => {
|
|
160
|
+
const {
|
|
161
|
+
ee
|
|
162
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
163
|
+
const mockListener = jest.fn();
|
|
164
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
165
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
166
|
+
ee.on(eventType, mockListener);
|
|
167
|
+
ee.emit(eventType, eventArgs);
|
|
168
|
+
expect(mockListener).toHaveBeenCalledWith(eventArgs[0], eventArgs[1], eventArgs[2]);
|
|
169
|
+
});
|
|
170
|
+
it('should not execute the listener after removal', async () => {
|
|
171
|
+
const {
|
|
172
|
+
ee
|
|
173
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
174
|
+
const mockListener = jest.fn();
|
|
175
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
176
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
177
|
+
ee.on(eventType, mockListener);
|
|
178
|
+
ee.emit(eventType, eventArgs);
|
|
179
|
+
ee.removeEventListener(eventType, mockListener);
|
|
180
|
+
ee.emit(eventType, eventArgs);
|
|
181
|
+
expect(mockListener).toHaveBeenCalledTimes(1);
|
|
182
|
+
});
|
|
183
|
+
it('should return early if global event-emitter is aborted', async () => {
|
|
184
|
+
const {
|
|
185
|
+
ee
|
|
186
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
187
|
+
const mockListener = jest.fn();
|
|
188
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
189
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
190
|
+
ee.backlog = {
|
|
191
|
+
api: ['foo', 'bar', 'baz']
|
|
192
|
+
};
|
|
193
|
+
ee.abort();
|
|
194
|
+
ee.on(eventType, mockListener);
|
|
195
|
+
ee.emit(eventType, eventArgs);
|
|
196
|
+
expect(mockListener).toHaveBeenCalledTimes(0);
|
|
197
|
+
});
|
|
198
|
+
it('should still emit if global event-emitter is aborted but force flag is true', async () => {
|
|
199
|
+
const {
|
|
200
|
+
ee
|
|
201
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
202
|
+
const scopeEE = ee.get(_faker.faker.datatype.uuid());
|
|
203
|
+
const mockScopeListener = jest.fn();
|
|
204
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
205
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
206
|
+
ee.backlog = {
|
|
207
|
+
api: ['foo', 'bar', 'baz']
|
|
208
|
+
};
|
|
209
|
+
ee.abort();
|
|
210
|
+
scopeEE.on(eventType, mockScopeListener);
|
|
211
|
+
scopeEE.emit(eventType, eventArgs, {}, true);
|
|
212
|
+
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
213
|
+
});
|
|
214
|
+
it('should bubble the event if bubble flag is true', async () => {
|
|
215
|
+
const {
|
|
216
|
+
ee
|
|
217
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
218
|
+
const scopeEE = ee.get(_faker.faker.datatype.uuid());
|
|
219
|
+
const mockListener = jest.fn();
|
|
220
|
+
const mockScopeListener = jest.fn();
|
|
221
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
222
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
223
|
+
ee.on(eventType, mockListener);
|
|
224
|
+
scopeEE.on(eventType, mockScopeListener);
|
|
225
|
+
scopeEE.emit(eventType, eventArgs, {}, false, true);
|
|
226
|
+
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
227
|
+
expect(mockListener).toHaveBeenCalledTimes(1);
|
|
228
|
+
});
|
|
229
|
+
it('should not bubble the event if bubble flag is false', async () => {
|
|
230
|
+
const {
|
|
231
|
+
ee
|
|
232
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
233
|
+
const scopeEE = ee.get(_faker.faker.datatype.uuid());
|
|
234
|
+
const mockListener = jest.fn();
|
|
235
|
+
const mockScopeListener = jest.fn();
|
|
236
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
237
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
238
|
+
ee.on(eventType, mockListener);
|
|
239
|
+
scopeEE.on(eventType, mockScopeListener);
|
|
240
|
+
scopeEE.emit(eventType, eventArgs, {}, false, false);
|
|
241
|
+
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
242
|
+
expect(mockListener).not.toHaveBeenCalled();
|
|
243
|
+
});
|
|
244
|
+
it('should buffer the event on the scoped event-emitter', async () => {
|
|
245
|
+
const {
|
|
246
|
+
ee
|
|
247
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
248
|
+
const scopeEE = ee.get(_faker.faker.datatype.uuid());
|
|
249
|
+
const mockListener = jest.fn();
|
|
250
|
+
const mockScopeListener = jest.fn();
|
|
251
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
252
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
253
|
+
ee.on(eventType, mockListener);
|
|
254
|
+
ee.buffer([eventType]);
|
|
255
|
+
scopeEE.on(eventType, mockScopeListener);
|
|
256
|
+
scopeEE.buffer([eventType]);
|
|
257
|
+
scopeEE.emit(eventType, eventArgs, {}, false, false);
|
|
258
|
+
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
259
|
+
expect(mockListener).not.toHaveBeenCalled();
|
|
260
|
+
expect(scopeEE.backlog['feature']).toEqual(expect.arrayContaining([expect.arrayContaining([scopeEE, eventType, eventArgs, {}])]));
|
|
261
|
+
expect(ee.backlog['feature']).toEqual(scopeEE.backlog['feature']);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
describe('getOrSetContext', () => {
|
|
265
|
+
test('it returns a new context', async () => {
|
|
266
|
+
const {
|
|
267
|
+
getOrSetContext
|
|
268
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
269
|
+
const obj = {};
|
|
270
|
+
const result = getOrSetContext(obj);
|
|
271
|
+
expect(result).toEqual({});
|
|
272
|
+
expect(result).toEqual(obj['nr@context']);
|
|
273
|
+
});
|
|
274
|
+
test('it returns the same context', async () => {
|
|
275
|
+
const {
|
|
276
|
+
getOrSetContext
|
|
277
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
278
|
+
const obj = {};
|
|
279
|
+
const result = getOrSetContext(obj);
|
|
280
|
+
expect(getOrSetContext(obj)).toEqual(result);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _faker = require("@faker-js/faker");
|
|
4
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
5
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
jest.mock('./contextual-ee', () => ({
|
|
7
|
+
__esModule: true,
|
|
8
|
+
ee: {
|
|
9
|
+
buffer: jest.fn(),
|
|
10
|
+
emit: jest.fn(),
|
|
11
|
+
get: jest.fn(() => ({
|
|
12
|
+
buffer: jest.fn(),
|
|
13
|
+
emit: jest.fn()
|
|
14
|
+
}))
|
|
15
|
+
}
|
|
16
|
+
}));
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
jest.resetModules();
|
|
19
|
+
jest.resetAllMocks();
|
|
20
|
+
});
|
|
21
|
+
test('it should create and use a default event-emitter', async () => {
|
|
22
|
+
const {
|
|
23
|
+
ee
|
|
24
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
25
|
+
const {
|
|
26
|
+
handle
|
|
27
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./handle')));
|
|
28
|
+
const handleEE = jest.mocked(ee.get).mock.results[0].value;
|
|
29
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
30
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
31
|
+
const eventContext = {};
|
|
32
|
+
const eventGroup = _faker.faker.datatype.uuid();
|
|
33
|
+
handle(eventType, eventArgs, eventContext, eventGroup);
|
|
34
|
+
expect(handleEE.buffer).toHaveBeenCalledWith([eventType], eventGroup);
|
|
35
|
+
expect(handleEE.emit).toHaveBeenCalledWith(eventType, eventArgs, eventContext);
|
|
36
|
+
});
|
|
37
|
+
test('it should use the provided scoped event-emitter', async () => {
|
|
38
|
+
const {
|
|
39
|
+
ee
|
|
40
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
41
|
+
const {
|
|
42
|
+
handle
|
|
43
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./handle')));
|
|
44
|
+
const scopedEE = {
|
|
45
|
+
buffer: jest.fn(),
|
|
46
|
+
emit: jest.fn()
|
|
47
|
+
};
|
|
48
|
+
const handleEE = jest.mocked(ee.get).mock.results[0].value;
|
|
49
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
50
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
51
|
+
const eventContext = {};
|
|
52
|
+
const eventGroup = _faker.faker.datatype.uuid();
|
|
53
|
+
handle(eventType, eventArgs, eventContext, eventGroup, scopedEE);
|
|
54
|
+
expect(handleEE.buffer).not.toHaveBeenCalled();
|
|
55
|
+
expect(handleEE.emit).not.toHaveBeenCalled();
|
|
56
|
+
expect(scopedEE.buffer).toHaveBeenCalledWith([eventType], eventGroup);
|
|
57
|
+
expect(scopedEE.emit).toHaveBeenCalledWith(eventType, eventArgs, eventContext);
|
|
58
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _faker = require("@faker-js/faker");
|
|
4
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
5
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
jest.mock('./handle', () => ({
|
|
7
|
+
__esModule: true,
|
|
8
|
+
handleEE: {}
|
|
9
|
+
}));
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
jest.resetModules();
|
|
12
|
+
jest.resetAllMocks();
|
|
13
|
+
});
|
|
14
|
+
test('should default group to "feature"', async () => {
|
|
15
|
+
const {
|
|
16
|
+
handleEE
|
|
17
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./handle')));
|
|
18
|
+
const {
|
|
19
|
+
registerHandler
|
|
20
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./register-handler')));
|
|
21
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
22
|
+
const eventHandler = jest.fn();
|
|
23
|
+
registerHandler(eventType, eventHandler);
|
|
24
|
+
expect(registerHandler.handlers['feature']).toEqual(expect.objectContaining({
|
|
25
|
+
[eventType]: [expect.arrayContaining([handleEE, eventHandler])]
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
test('should use the provided group', async () => {
|
|
29
|
+
const {
|
|
30
|
+
handleEE
|
|
31
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./handle')));
|
|
32
|
+
const {
|
|
33
|
+
registerHandler
|
|
34
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./register-handler')));
|
|
35
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
36
|
+
const eventGroup = _faker.faker.datatype.uuid();
|
|
37
|
+
const eventHandler = jest.fn();
|
|
38
|
+
registerHandler(eventType, eventHandler, eventGroup);
|
|
39
|
+
expect(registerHandler.handlers[eventGroup]).toEqual(expect.objectContaining({
|
|
40
|
+
[eventType]: [expect.arrayContaining([handleEE, eventHandler])]
|
|
41
|
+
}));
|
|
42
|
+
});
|
|
43
|
+
test('should use the provided event-emitter', async () => {
|
|
44
|
+
const {
|
|
45
|
+
registerHandler
|
|
46
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./register-handler')));
|
|
47
|
+
const scopedEE = {};
|
|
48
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
49
|
+
const eventGroup = _faker.faker.datatype.uuid();
|
|
50
|
+
const eventHandler = jest.fn();
|
|
51
|
+
registerHandler(eventType, eventHandler, eventGroup, scopedEE);
|
|
52
|
+
expect(registerHandler.handlers[eventGroup]).toEqual(expect.objectContaining({
|
|
53
|
+
[eventType]: [expect.arrayContaining([scopedEE, eventHandler])]
|
|
54
|
+
}));
|
|
55
|
+
});
|
|
@@ -17,7 +17,7 @@ var _eventListenerOpts = require("../event-listener/event-listener-opts");
|
|
|
17
17
|
var _obfuscate = require("../util/obfuscate");
|
|
18
18
|
var _traverse = require("../util/traverse");
|
|
19
19
|
var _sharedContext = require("../context/shared-context");
|
|
20
|
-
var
|
|
20
|
+
var _env = require("../constants/env.npm");
|
|
21
21
|
var _globalScope = require("../util/global-scope");
|
|
22
22
|
/*
|
|
23
23
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
@@ -165,7 +165,7 @@ class Harvest extends _sharedContext.SharedContext {
|
|
|
165
165
|
var info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
|
|
166
166
|
var location = (0, _cleanUrl.cleanURL)((0, _location.getLocation)());
|
|
167
167
|
var ref = this.obfuscator.shouldObfuscate() ? this.obfuscator.obfuscateString(location) : location;
|
|
168
|
-
return ['?a=' + info.applicationID, (0, _encode.param)('sa', info.sa ? '' + info.sa : ''), (0, _encode.param)('v',
|
|
168
|
+
return ['?a=' + info.applicationID, (0, _encode.param)('sa', info.sa ? '' + info.sa : ''), (0, _encode.param)('v', _env.VERSION), transactionNameParam(info), (0, _encode.param)('ct', runtime.customTransaction), '&rst=' + (0, _now.now)(), '&ck=0',
|
|
169
169
|
// ck param DEPRECATED - still expected by backend
|
|
170
170
|
'&s=' + (runtime.sessionId || '0'),
|
|
171
171
|
// the 0 id encaps all untrackable and default traffic
|