@vida-global/core 2.0.1 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,56 +0,0 @@
1
- const ORIGINAL_ENV = process.env;
2
-
3
-
4
- beforeEach(() => {
5
- jest.resetModules();
6
- process.env = { ...ORIGINAL_ENV, NODE_ENV: 'test' };
7
- delete process.env.NEW_RELIC_LICENSE_KEY;
8
- });
9
-
10
-
11
- afterEach(() => {
12
- process.env = ORIGINAL_ENV;
13
- });
14
-
15
-
16
- describe('apm/agent', () => {
17
- describe('stub client (NEW_RELIC_LICENSE_KEY unset)', () => {
18
- it ('reports enabled=false', () => {
19
- const { enabled } = require('../../lib/apm/agent');
20
-
21
- expect(enabled).toEqual(false);
22
- });
23
-
24
- it ('exposes no-op stubs that accept any arguments', () => {
25
- const { client } = require('../../lib/apm/agent');
26
-
27
- expect(() => client.addCustomAttribute('k', 'v')).not.toThrow();
28
- expect(() => client.noticeError(new Error('x'), {})).not.toThrow();
29
- expect(() => client.recordCustomEvent('Type', { a: 1 })).not.toThrow();
30
- expect(() => client.recordMetric('name', 1)).not.toThrow();
31
- expect(() => client.setControllerName('C', 'a')).not.toThrow();
32
- expect(() => client.setUserID(1)).not.toThrow();
33
- expect(() => client.instrumentLoadedModule('pkg', {})).not.toThrow();
34
- });
35
-
36
- it ('startBackgroundTransaction invokes the handler and returns its result', () => {
37
- const { client } = require('../../lib/apm/agent');
38
- const handler = jest.fn(() => 'bg-result');
39
-
40
- const result = client.startBackgroundTransaction('Job', 'queue', handler);
41
-
42
- expect(handler).toHaveBeenCalledTimes(1);
43
- expect(result).toEqual('bg-result');
44
- });
45
-
46
- it ('startSegment invokes the handler and returns its result', () => {
47
- const { client } = require('../../lib/apm/agent');
48
- const handler = jest.fn(() => 'seg-result');
49
-
50
- const result = client.startSegment('seg', true, handler);
51
-
52
- expect(handler).toHaveBeenCalledTimes(1);
53
- expect(result).toEqual('seg-result');
54
- });
55
- });
56
- });
@@ -1,121 +0,0 @@
1
- jest.mock('../../lib/apm/agent', () => ({
2
- enabled: false,
3
- client: {
4
- addCustomAttribute: jest.fn(),
5
- noticeError: jest.fn(),
6
- recordCustomEvent: jest.fn(),
7
- recordMetric: jest.fn(),
8
- setControllerName: jest.fn(),
9
- setUserID: jest.fn(),
10
- startBackgroundTransaction: jest.fn((name, group, handler) => handler()),
11
- startSegment: jest.fn((name, record, handler) => handler()),
12
- },
13
- }));
14
-
15
-
16
- let utils;
17
- let agent;
18
-
19
- beforeEach(() => {
20
- jest.resetModules();
21
- utils = require('../../lib/apm/utils');
22
- agent = require('../../lib/apm/agent');
23
- });
24
-
25
-
26
- afterEach(() => {
27
- jest.clearAllMocks();
28
- });
29
-
30
-
31
- describe('apm/utils', () => {
32
- describe('addCustomAttribute', () => {
33
- it ('forwards key and value to the client', () => {
34
- utils.addCustomAttribute('foo', 'bar');
35
-
36
- expect(agent.client.addCustomAttribute).toHaveBeenCalledWith('foo', 'bar');
37
- });
38
- });
39
-
40
-
41
- describe('reportError', () => {
42
- it ('forwards the error and details to noticeError', () => {
43
- const err = new Error('boom');
44
- const details = { a: 1 };
45
-
46
- utils.reportError(err, details);
47
-
48
- expect(agent.client.noticeError).toHaveBeenCalledWith(err, details);
49
- });
50
-
51
- it ('defaults details to an empty object', () => {
52
- const err = new Error('boom');
53
-
54
- utils.reportError(err);
55
-
56
- expect(agent.client.noticeError).toHaveBeenCalledWith(err, {});
57
- });
58
- });
59
-
60
-
61
- describe('recordCustomEvent', () => {
62
- it ('forwards eventType and attributes to the client', () => {
63
- const attrs = { jobName: 'X' };
64
-
65
- utils.recordCustomEvent('JobCompleted', attrs);
66
-
67
- expect(agent.client.recordCustomEvent).toHaveBeenCalledWith('JobCompleted', attrs);
68
- });
69
- });
70
-
71
-
72
- describe('recordMetric', () => {
73
- it ('forwards name and value to the client', () => {
74
- utils.recordMetric('Custom/Worker/foo', 42);
75
-
76
- expect(agent.client.recordMetric).toHaveBeenCalledWith('Custom/Worker/foo', 42);
77
- });
78
- });
79
-
80
-
81
- describe('setControllerName', () => {
82
- it ('forwards controller and action to the client', () => {
83
- utils.setControllerName('Users', 'getIndex');
84
-
85
- expect(agent.client.setControllerName).toHaveBeenCalledWith('Users', 'getIndex');
86
- });
87
- });
88
-
89
-
90
- describe('setUserId', () => {
91
- it ('forwards id to the client (note the casing difference)', () => {
92
- utils.setUserId(123);
93
-
94
- expect(agent.client.setUserID).toHaveBeenCalledWith(123);
95
- });
96
- });
97
-
98
-
99
- describe('startBackgroundTransaction', () => {
100
- it ('forwards name, group, and handler to the client and returns its result', () => {
101
- const handler = jest.fn(() => 'result');
102
-
103
- const result = utils.startBackgroundTransaction('Job', 'queue', handler);
104
-
105
- expect(agent.client.startBackgroundTransaction).toHaveBeenCalledWith('Job', 'queue', handler);
106
- expect(result).toEqual('result');
107
- });
108
- });
109
-
110
-
111
- describe('startSegment', () => {
112
- it ('forwards name, record flag, and handler to the client and returns its result', () => {
113
- const handler = jest.fn(() => 'segment-result');
114
-
115
- const result = utils.startSegment('seg', true, handler);
116
-
117
- expect(agent.client.startSegment).toHaveBeenCalledWith('seg', true, handler);
118
- expect(result).toEqual('segment-result');
119
- });
120
- });
121
- });