@servicetitan/log-service 28.1.1 → 28.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/__mocks__/broadcast-channel.d.ts +13 -0
- package/dist/__tests__/__mocks__/broadcast-channel.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/broadcast-channel.js +79 -0
- package/dist/__tests__/__mocks__/broadcast-channel.js.map +1 -0
- package/dist/__tests__/__mocks__/index.d.ts +2 -0
- package/dist/__tests__/__mocks__/index.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/index.js +2 -0
- package/dist/__tests__/__mocks__/index.js.map +1 -0
- package/dist/__tests__/connection-service.test.d.ts +2 -0
- package/dist/__tests__/connection-service.test.d.ts.map +1 -0
- package/dist/__tests__/connection-service.test.js +43 -0
- package/dist/__tests__/connection-service.test.js.map +1 -0
- package/dist/__tests__/global-error-handler.test.d.ts +2 -0
- package/dist/__tests__/global-error-handler.test.d.ts.map +1 -0
- package/dist/__tests__/global-error-handler.test.js +174 -0
- package/dist/__tests__/global-error-handler.test.js.map +1 -0
- package/dist/__tests__/log-config-provider.test.d.ts +2 -0
- package/dist/__tests__/log-config-provider.test.d.ts.map +1 -0
- package/dist/__tests__/log-config-provider.test.js +20 -0
- package/dist/__tests__/log-config-provider.test.js.map +1 -0
- package/dist/__tests__/log-sender.test.d.ts +2 -0
- package/dist/__tests__/log-sender.test.d.ts.map +1 -0
- package/dist/__tests__/log-sender.test.js +117 -0
- package/dist/__tests__/log-sender.test.js.map +1 -0
- package/dist/__tests__/log-service.test.d.ts +2 -0
- package/dist/__tests__/log-service.test.d.ts.map +1 -0
- package/dist/__tests__/log-service.test.js +49 -0
- package/dist/__tests__/log-service.test.js.map +1 -0
- package/dist/__tests__/log-storage.test.d.ts +2 -0
- package/dist/__tests__/log-storage.test.d.ts.map +1 -0
- package/dist/__tests__/log-storage.test.js +139 -0
- package/dist/__tests__/log-storage.test.js.map +1 -0
- package/dist/__tests__/log.test.d.ts +2 -0
- package/dist/__tests__/log.test.d.ts.map +1 -0
- package/dist/__tests__/log.test.js +137 -0
- package/dist/__tests__/log.test.js.map +1 -0
- package/dist/__tests__/serialize-with-metadata.test.d.ts +2 -0
- package/dist/__tests__/serialize-with-metadata.test.d.ts.map +1 -0
- package/dist/__tests__/serialize-with-metadata.test.js +27 -0
- package/dist/__tests__/serialize-with-metadata.test.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class MockBroadcastChannel implements BroadcastChannel {
|
|
2
|
+
name: string;
|
|
3
|
+
onmessage: jest.Mock<any, any, any>;
|
|
4
|
+
onmessageerror: jest.Mock<any, any, any>;
|
|
5
|
+
removeEventListener: jest.Mock<any, any, any>;
|
|
6
|
+
dispatchEvent: jest.Mock<any, any, any>;
|
|
7
|
+
postMessage: jest.Mock<any, any, any>;
|
|
8
|
+
addEventListener: jest.Mock<any, any, any>;
|
|
9
|
+
close: jest.Mock<any, any, any>;
|
|
10
|
+
private emitter;
|
|
11
|
+
constructor(name: string);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=broadcast-channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broadcast-channel.d.ts","sourceRoot":"","sources":["../../../src/__tests__/__mocks__/broadcast-channel.ts"],"names":[],"mappings":"AAIA,qBAAa,oBAAqB,YAAW,gBAAgB;IA0BtC,IAAI,EAAE,MAAM;IAzB/B,SAAS,2BAAa;IACtB,cAAc,2BAAa;IAC3B,mBAAmB,2BAAa;IAChC,aAAa,2BAAa;IAE1B,WAAW,2BAGR;IAEH,gBAAgB,2BAMb;IAEH,KAAK,2BAGF;IAEH,OAAO,CAAC,OAAO,CAAe;gBAEX,IAAI,EAAE,MAAM;CAQlC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
const channels = new Map();
|
|
3
|
+
export class MockBroadcastChannel {
|
|
4
|
+
constructor(name) {
|
|
5
|
+
Object.defineProperty(this, "name", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: name
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(this, "onmessage", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: jest.fn()
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "onmessageerror", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: jest.fn()
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "removeEventListener", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: jest.fn()
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "dispatchEvent", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: jest.fn()
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "postMessage", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: jest.fn().mockImplementation(message => {
|
|
40
|
+
const event = { data: message, from: this };
|
|
41
|
+
this.emitter.emit('message', event);
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(this, "addEventListener", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true,
|
|
48
|
+
value: jest.fn().mockImplementation((_, listener) => {
|
|
49
|
+
this.emitter.on('message', ({ from, ...event }) => {
|
|
50
|
+
if (from !== this) {
|
|
51
|
+
listener(event);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(this, "close", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: jest.fn().mockImplementation(() => {
|
|
61
|
+
this.emitter.removeAllListeners();
|
|
62
|
+
channels.delete(this.name);
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "emitter", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
71
|
+
this.emitter = channels.get(name);
|
|
72
|
+
if (!this.emitter) {
|
|
73
|
+
const emitter = new EventEmitter();
|
|
74
|
+
channels.set(name, emitter);
|
|
75
|
+
this.emitter = emitter;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=broadcast-channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broadcast-channel.js","sourceRoot":"","sources":["../../../src/__tests__/__mocks__/broadcast-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,QAAQ,GAA8B,IAAI,GAAG,EAAE,CAAC;AAEtD,MAAM,OAAO,oBAAoB;IA0B7B,YAAmB,IAAY;QAAnB;;;;mBAAO,IAAI;WAAQ;QAzB/B;;;;mBAAY,IAAI,CAAC,EAAE,EAAE;WAAC;QACtB;;;;mBAAiB,IAAI,CAAC,EAAE,EAAE;WAAC;QAC3B;;;;mBAAsB,IAAI,CAAC,EAAE,EAAE;WAAC;QAChC;;;;mBAAgB,IAAI,CAAC,EAAE,EAAE;WAAC;QAE1B;;;;mBAAc,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE;gBACjD,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;gBAC5C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YACxC,CAAC,CAAC;WAAC;QAEH;;;;mBAAmB,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAS,EAAE,QAAa,EAAE,EAAE;gBACzE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;oBAC9C,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;wBAChB,QAAQ,CAAC,KAAK,CAAC,CAAC;oBACpB,CAAC;gBACL,CAAC,CAAC,CAAC;YACP,CAAC,CAAC;WAAC;QAEH;;;;mBAAQ,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE;gBACtC,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC;gBAClC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC,CAAC;WAAC;QAEK;;;;;WAAsB;QAG1B,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;YACnC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/__tests__/__mocks__/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/__tests__/__mocks__/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-service.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/connection-service.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ConnectionService } from '../connection-service';
|
|
2
|
+
describe(`[log-service] ${ConnectionService.name}`, () => {
|
|
3
|
+
const navigator = window.navigator;
|
|
4
|
+
beforeAll(() => {
|
|
5
|
+
Object.defineProperty(window.navigator, 'onLine', { value: undefined, writable: true });
|
|
6
|
+
});
|
|
7
|
+
const subject = () => new ConnectionService();
|
|
8
|
+
describe('when browser is offline', () => {
|
|
9
|
+
beforeEach(() => (navigator.onLine = false));
|
|
10
|
+
test('reports offline', () => {
|
|
11
|
+
expect(subject().online).toBe(false);
|
|
12
|
+
});
|
|
13
|
+
describe('when browser goes online', () => {
|
|
14
|
+
const setup = () => {
|
|
15
|
+
const service = subject();
|
|
16
|
+
window.dispatchEvent(new Event('online'));
|
|
17
|
+
return service;
|
|
18
|
+
};
|
|
19
|
+
test('reports online', () => {
|
|
20
|
+
const service = setup();
|
|
21
|
+
expect(service.online).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('when browser is online', () => {
|
|
26
|
+
beforeEach(() => (navigator.onLine = true));
|
|
27
|
+
test('reports online', () => {
|
|
28
|
+
expect(subject().online).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
describe('when browser goes offline', () => {
|
|
31
|
+
const setup = () => {
|
|
32
|
+
const service = subject();
|
|
33
|
+
window.dispatchEvent(new Event('offline'));
|
|
34
|
+
return service;
|
|
35
|
+
};
|
|
36
|
+
test('reports offline', () => {
|
|
37
|
+
const service = setup();
|
|
38
|
+
expect(service.online).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=connection-service.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-service.test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C,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACpC,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;QAE5C,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE;YACxB,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;YACvC,MAAM,KAAK,GAAG,GAAG,EAAE;gBACf,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC;gBAC1B,MAAM,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;gBAC3C,OAAO,OAAO,CAAC;YACnB,CAAC,CAAC;YAEF,IAAI,CAAC,iBAAiB,EAAE,GAAG,EAAE;gBACzB,MAAM,OAAO,GAAG,KAAK,EAAE,CAAC;gBAExB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-error-handler.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/global-error-handler.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { serializeWithMetadata } from '../serialize-with-metadata';
|
|
2
|
+
import { GlobalErrorHandler } from '../global-error-handler';
|
|
3
|
+
describe(`[log-service] ${GlobalErrorHandler.name}`, () => {
|
|
4
|
+
const log = { error: jest.fn() };
|
|
5
|
+
let handler;
|
|
6
|
+
beforeAll(() => (handler = new GlobalErrorHandler(log)));
|
|
7
|
+
beforeEach(() => jest.clearAllMocks());
|
|
8
|
+
describe('onError', () => {
|
|
9
|
+
const line = 12;
|
|
10
|
+
const column = 34;
|
|
11
|
+
const url = 'http://example.com';
|
|
12
|
+
let message;
|
|
13
|
+
let error;
|
|
14
|
+
let isUnhandled;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
message = 'Oops!';
|
|
17
|
+
error = new Error('Something went wrong');
|
|
18
|
+
isUnhandled = undefined;
|
|
19
|
+
});
|
|
20
|
+
const subject = () => handler.onError(message, url, line, column, error, isUnhandled);
|
|
21
|
+
test('reports error', () => {
|
|
22
|
+
subject();
|
|
23
|
+
expect(log.error).toHaveBeenCalledWith({
|
|
24
|
+
error,
|
|
25
|
+
message: error.message,
|
|
26
|
+
category: 'UnhandledError',
|
|
27
|
+
code: 'UnhandledError',
|
|
28
|
+
data: undefined,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('when error was handled', () => {
|
|
32
|
+
beforeEach(() => (isUnhandled = false));
|
|
33
|
+
test('omits category and code', () => {
|
|
34
|
+
subject();
|
|
35
|
+
expect(log.error).toHaveBeenCalledWith({
|
|
36
|
+
error,
|
|
37
|
+
message: error.message,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('with no error', () => {
|
|
42
|
+
beforeEach(() => (error = undefined));
|
|
43
|
+
test('reports synthetic error', () => {
|
|
44
|
+
subject();
|
|
45
|
+
expect(log.error).toHaveBeenCalledWith({
|
|
46
|
+
error: expect.objectContaining({
|
|
47
|
+
message: `Message - ${message}`,
|
|
48
|
+
stack: expect.stringContaining(`${url}:${line}:${column}`),
|
|
49
|
+
}),
|
|
50
|
+
message: `Message - ${message}`,
|
|
51
|
+
category: 'UnhandledError',
|
|
52
|
+
code: 'NonUniform',
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe('when message is not a string', () => {
|
|
56
|
+
beforeEach(() => (message = { foo: 'bar' }));
|
|
57
|
+
test('serializes message', () => {
|
|
58
|
+
subject();
|
|
59
|
+
expect(log.error).toHaveBeenCalledWith(expect.objectContaining({
|
|
60
|
+
message: `Message - ${serializeWithMetadata(message)}`,
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe('with a non-standard error', () => {
|
|
66
|
+
beforeEach(() => (error = { data: 'foo' }));
|
|
67
|
+
test('serializes error into message', () => {
|
|
68
|
+
subject();
|
|
69
|
+
expect(log.error).toHaveBeenCalledWith(expect.objectContaining({
|
|
70
|
+
message: `Message - ${message};Error - ${serializeWithMetadata(error)}`,
|
|
71
|
+
}));
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe.each([
|
|
75
|
+
'gCrWeb',
|
|
76
|
+
'Geolocation',
|
|
77
|
+
'kCLErrorDomain',
|
|
78
|
+
'The last location provider was disabled',
|
|
79
|
+
'Location services are disabled',
|
|
80
|
+
])('when message contains "%s"', subString => {
|
|
81
|
+
beforeEach(() => (message = `foo${subString}bar`));
|
|
82
|
+
test('ignores error', () => {
|
|
83
|
+
subject();
|
|
84
|
+
expect(log.error).not.toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('when report fails', () => {
|
|
88
|
+
const reportError = new Error('Something went wrong');
|
|
89
|
+
beforeEach(() => {
|
|
90
|
+
jest.mocked(log.error).mockImplementation(() => {
|
|
91
|
+
throw reportError;
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
test('logs failure', () => {
|
|
95
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(jest.fn());
|
|
96
|
+
subject();
|
|
97
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('@log-service/onError/failsafe', message);
|
|
98
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('@log-service/onError/failsafe', reportError);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe('onReject', () => {
|
|
103
|
+
let reason;
|
|
104
|
+
const subject = () => handler.onReject({ reason });
|
|
105
|
+
describe('when reason is an Error', () => {
|
|
106
|
+
const error = new Error('Oops!');
|
|
107
|
+
beforeEach(() => (reason = error));
|
|
108
|
+
test('reports error', () => {
|
|
109
|
+
subject();
|
|
110
|
+
expect(log.error).toHaveBeenCalledWith({
|
|
111
|
+
error,
|
|
112
|
+
message: error.message,
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe('when reason is not an error', () => {
|
|
117
|
+
beforeEach(() => (reason = { foo: 'bar' }));
|
|
118
|
+
test('reports synthetic error', () => {
|
|
119
|
+
subject();
|
|
120
|
+
const message = `Unhandled rejection - ${serializeWithMetadata(reason)}`;
|
|
121
|
+
expect(log.error).toHaveBeenCalledWith({
|
|
122
|
+
error: expect.objectContaining({ message }),
|
|
123
|
+
message,
|
|
124
|
+
code: 'NonUniform',
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('when report fails', () => {
|
|
129
|
+
const reportError = new Error('Something went wrong');
|
|
130
|
+
beforeEach(() => {
|
|
131
|
+
jest.mocked(log.error).mockImplementation(() => {
|
|
132
|
+
throw reportError;
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
test('logs failure', () => {
|
|
136
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(jest.fn());
|
|
137
|
+
subject();
|
|
138
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('@log-service/onReject/failsafe', reportError);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
describe('instrument', () => {
|
|
143
|
+
let window;
|
|
144
|
+
beforeEach(() => (window = {}));
|
|
145
|
+
const subject = () => handler.instrument(window);
|
|
146
|
+
test('installs "onError" handler', () => {
|
|
147
|
+
subject();
|
|
148
|
+
expect(window.onerror).toBe(handler.onError);
|
|
149
|
+
});
|
|
150
|
+
test('installs "onReject" handler', () => {
|
|
151
|
+
subject();
|
|
152
|
+
expect(window.onunhandledrejection).toBe(handler.onReject);
|
|
153
|
+
});
|
|
154
|
+
describe('with existing handler', () => {
|
|
155
|
+
const existingHandler = jest.fn();
|
|
156
|
+
beforeEach(() => (window.onerror = existingHandler));
|
|
157
|
+
test('chains the error handlers', () => {
|
|
158
|
+
const onErrorSpy = jest.spyOn(handler, 'onError');
|
|
159
|
+
const error = new Error('Oops!');
|
|
160
|
+
subject();
|
|
161
|
+
window.onerror(error);
|
|
162
|
+
expect(existingHandler).toHaveBeenCalledWith(error);
|
|
163
|
+
expect(onErrorSpy).toHaveBeenCalledWith(error);
|
|
164
|
+
});
|
|
165
|
+
describe('when existing error handler is not a function', () => {
|
|
166
|
+
beforeEach(() => (window.onerror = 'Nope!'));
|
|
167
|
+
test('throws error', () => {
|
|
168
|
+
expect(subject).toThrow(/attempt to instrument non-function value/i);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
//# sourceMappingURL=global-error-handler.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-error-handler.test.js","sourceRoot":"","sources":["../../src/__tests__/global-error-handler.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,QAAQ,CAAC,iBAAiB,kBAAkB,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE;IACtD,MAAM,GAAG,GAAuB,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC;IACrD,IAAI,OAA2B,CAAC;IAEhC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,GAAG,IAAI,kBAAkB,CAAC,GAAU,CAAC,CAAC,CAAC,CAAC;IAEhE,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;IAEvC,QAAQ,CAAC,SAAS,EAA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|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useDependencies } from '@servicetitan/react-ioc';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import { LOG_CONFIG_TOKEN } from '../log-config';
|
|
5
|
+
import { LogConfigProvider } from '../log-config-provider';
|
|
6
|
+
describe(`[log-service] ${LogConfigProvider.name}`, () => {
|
|
7
|
+
const logConfig = { endpoint: '/Log/Foo', storageKey: 'LogStorage_Foo' };
|
|
8
|
+
let providedLogConfig;
|
|
9
|
+
const Wrapper = () => {
|
|
10
|
+
const [logConfig] = useDependencies(LOG_CONFIG_TOKEN);
|
|
11
|
+
providedLogConfig = logConfig;
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
const subject = () => render(_jsx(LogConfigProvider, { value: logConfig, children: _jsx(Wrapper, {}) }));
|
|
15
|
+
test('provides LOG_CONFIG_TOKEN', () => {
|
|
16
|
+
subject();
|
|
17
|
+
expect(providedLogConfig).toBe(logConfig);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=log-config-provider.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-config-provider.test.js","sourceRoot":"","sources":["../../src/__tests__/log-config-provider.test.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAa,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,QAAQ,CAAC,iBAAiB,iBAAiB,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE;IACrD,MAAM,SAAS,GAAc,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;IACpF,IAAI,iBAA4B,CAAC;IAEjC,MAAM,OAAO,GAAO,GAAG,EAAE;QACrB,MAAM,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC;QACtD,iBAAiB,GAAG,SAAS,CAAC;QAC9B,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,GAAG,EAAE,CACjB,MAAM,CACF,KAAC,iBAAiB,IAAC,KAAK,EAAE,SAAS,YAC/B,KAAC,OAAO,KAAG,GACK,CACvB,CAAC;IAEN,IAAI,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,OAAO,EAAE,CAAC;QAEV,MAAM,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-sender.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/log-sender.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { ConnectionService } from '../connection-service';
|
|
3
|
+
import { LogEntryType } from '../log';
|
|
4
|
+
import { lastId, LogStorage } from '../log-storage';
|
|
5
|
+
import { LogSender } from '../log-sender';
|
|
6
|
+
jest.mock('axios', () => ({ post: jest.fn() }));
|
|
7
|
+
class MockLog {
|
|
8
|
+
constructor(logStorage) {
|
|
9
|
+
Object.defineProperty(this, "logStorage", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: logStorage
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
info(entry) {
|
|
17
|
+
this.logStorage.store({
|
|
18
|
+
type: LogEntryType.Info,
|
|
19
|
+
...entry,
|
|
20
|
+
category: null,
|
|
21
|
+
code: null,
|
|
22
|
+
data: {},
|
|
23
|
+
error: null,
|
|
24
|
+
message: null,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
warning(_entry) { }
|
|
28
|
+
}
|
|
29
|
+
const SECOND = 1000;
|
|
30
|
+
const MINUTE = 60 * SECOND;
|
|
31
|
+
describe(`[log-service] ${LogSender.name}`, () => {
|
|
32
|
+
const connectionService = new ConnectionService();
|
|
33
|
+
const logConfig = { endpoint: '/Log/Foo', storageKey: 'LogStorage_Foo' };
|
|
34
|
+
let logStorage;
|
|
35
|
+
let log;
|
|
36
|
+
beforeAll(() => {
|
|
37
|
+
var _a;
|
|
38
|
+
var _b;
|
|
39
|
+
(_a = (_b = process.env).NODE_ENV) !== null && _a !== void 0 ? _a : (_b.NODE_ENV = 'test'); // workaround issue with Jest not setting NODE_ENV=test
|
|
40
|
+
jest.spyOn(window, 'setInterval').mockImplementation(jest.fn());
|
|
41
|
+
jest.spyOn(axios, 'post').mockImplementation(jest.fn());
|
|
42
|
+
});
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
jest.clearAllMocks();
|
|
45
|
+
logStorage = new LogStorage(logConfig);
|
|
46
|
+
log = new MockLog(logStorage);
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
+
const logSender = new LogSender(connectionService, logStorage, logConfig, log);
|
|
49
|
+
});
|
|
50
|
+
afterEach(() => logStorage.deleteToId(lastId(logStorage.items)));
|
|
51
|
+
const subject = async () => {
|
|
52
|
+
getHandler().fn();
|
|
53
|
+
await Promise.resolve(); // resolve pending promises
|
|
54
|
+
};
|
|
55
|
+
function getHandler() {
|
|
56
|
+
const [fn, interval] = jest.mocked(window.setInterval).mock.calls[0];
|
|
57
|
+
return { fn, interval };
|
|
58
|
+
}
|
|
59
|
+
function initLog(count) {
|
|
60
|
+
Array.from({ length: count }).map((_, index) => log.info({ message: `Message ${index}` }));
|
|
61
|
+
return logStorage.items;
|
|
62
|
+
}
|
|
63
|
+
test('schedules handler to run once per minute', async () => {
|
|
64
|
+
await subject();
|
|
65
|
+
expect(getHandler().interval).toBe(MINUTE);
|
|
66
|
+
});
|
|
67
|
+
describe('when there are items waiting to be sent', () => {
|
|
68
|
+
beforeEach(() => initLog(3));
|
|
69
|
+
test('handler posts then purges log', async () => {
|
|
70
|
+
const { items } = logStorage;
|
|
71
|
+
await subject();
|
|
72
|
+
expect(axios.post).toHaveBeenCalledWith(logConfig.endpoint, items);
|
|
73
|
+
expect(logStorage.items).toEqual([]);
|
|
74
|
+
});
|
|
75
|
+
describe('when post fails', () => {
|
|
76
|
+
beforeEach(() => jest.mocked(axios.post).mockRejectedValue(new Error('Oops!')));
|
|
77
|
+
test('reschedules handler to run in exponentially increasing intervals until it succeeds', async () => {
|
|
78
|
+
for (let n = 0; n <= 10; n++) {
|
|
79
|
+
// eslint-disable-next-line no-await-in-loop
|
|
80
|
+
await subject();
|
|
81
|
+
}
|
|
82
|
+
for (let n = 0; n < 10; n++) {
|
|
83
|
+
expect(window.setInterval).toHaveBeenCalledWith(expect.any(Function), 2 ** n * SECOND);
|
|
84
|
+
}
|
|
85
|
+
jest.mocked(axios.post).mockReset();
|
|
86
|
+
await subject();
|
|
87
|
+
expect(logStorage.items).toEqual([]);
|
|
88
|
+
expect(window.setInterval).toHaveBeenCalledWith(expect.any(Function), MINUTE);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe('when handler runs while posting', () => {
|
|
92
|
+
beforeEach(() => jest.spyOn(axios, 'post').mockImplementation(() => {
|
|
93
|
+
getHandler().fn();
|
|
94
|
+
return Promise.resolve({});
|
|
95
|
+
}));
|
|
96
|
+
test('skips redundant post', async () => {
|
|
97
|
+
await subject();
|
|
98
|
+
expect(axios.post).toHaveBeenCalledTimes(1);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
describe('when offline', () => {
|
|
102
|
+
beforeEach(() => connectionService.setOnline(false));
|
|
103
|
+
afterEach(() => connectionService.setOnline(true));
|
|
104
|
+
test('does not post', async () => {
|
|
105
|
+
await subject();
|
|
106
|
+
expect(axios.post).not.toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
test('automatically posts when log >= 128 items', async () => {
|
|
111
|
+
await subject();
|
|
112
|
+
expect(axios.post).not.toHaveBeenCalled();
|
|
113
|
+
const items = initLog(128);
|
|
114
|
+
expect(axios.post).toHaveBeenCalledWith(logConfig.endpoint, items);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=log-sender.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-sender.test.js","sourceRoot":"","sources":["../../src/__tests__/log-sender.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAkB,YAAY,EAAuB,MAAM,QAAQ,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAEhD,MAAM,OAAO;IACT,YAA6B,UAAsB;QAAvC;;;;mBAAiB,UAAU;WAAY;IAAG,CAAC;IAEvD,IAAI,CAAC,KAAc;QACf,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;YAClB,IAAI,EAAE,YAAY,CAAC,IAAI;YACvB,GAAG,KAAK;YACR,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,EAAE;YACR,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,IAAI;SAChB,CAAC,CAAC;IACP,CAAC;IAED,OAAO,CAAC,MAAkB,IAAG,CAAC;CACjC;AAED,MAAM,MAAM,GAAG,IAAI,CAAC;AACpB,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC;AAE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CAAC;YAEF,IAAI,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;gBACpC,MAAM,OAAO,EAAE,CAAC;gBAEhB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YAChD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;YAC1B,UAAU,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YACrD,SAAS,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YAEnD,IAAI,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;gBAC7B,MAAM,OAAO,EAAE,CAAC;gBAEhB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;YAC9C,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,OAAO,EAAE,CAAC;QAChB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAE1C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAE3B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,oBAAoB,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-service.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/log-service.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Provider, useDependencies, useOptionalDependencies, } from '@servicetitan/react-ioc';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import { LOG_CONFIG_TOKEN, LOG_PARENT_TOKEN, Log } from '../log';
|
|
5
|
+
import { defaultLogConfig } from '../log-config';
|
|
6
|
+
import { LogStorage } from '../log-storage';
|
|
7
|
+
import { LogService } from '../log-service';
|
|
8
|
+
describe(`[log-service] ${LogService.name}`, () => {
|
|
9
|
+
let props;
|
|
10
|
+
let providedLog;
|
|
11
|
+
let providedLogConfig;
|
|
12
|
+
let providedParent;
|
|
13
|
+
let singletons;
|
|
14
|
+
const Component = () => {
|
|
15
|
+
[providedLog, providedLogConfig] = useDependencies(Log, LOG_CONFIG_TOKEN);
|
|
16
|
+
[providedParent] = useOptionalDependencies(LOG_PARENT_TOKEN);
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
19
|
+
const subject = () => {
|
|
20
|
+
return render(_jsx(Provider, { singletons: singletons, children: _jsx(LogService, { ...props, children: _jsx(Component, {}) }) }));
|
|
21
|
+
};
|
|
22
|
+
test('provides Log instance', () => {
|
|
23
|
+
subject();
|
|
24
|
+
expect(providedLog).toBeInstanceOf(Log);
|
|
25
|
+
});
|
|
26
|
+
test('defaults to endpoint "/Log/Send" and storageKey "LogStorage"', () => {
|
|
27
|
+
subject();
|
|
28
|
+
expect(providedLogConfig).toEqual({ endpoint: '/Log/Send', storageKey: 'LogStorage' });
|
|
29
|
+
});
|
|
30
|
+
describe.each(['endpoint', 'storageKey'])('when "%s" is specified', prop => {
|
|
31
|
+
beforeEach(() => (props = { [prop]: 'Foo' }));
|
|
32
|
+
test(`uses the specified ${prop}`, () => {
|
|
33
|
+
subject();
|
|
34
|
+
expect(providedLogConfig[prop]).toEqual(props[prop]);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('with a parent log', () => {
|
|
38
|
+
const parent = new Log(new LogStorage(defaultLogConfig));
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
singletons = [{ provide: Log, useValue: parent }];
|
|
41
|
+
props = { endpoint: '/Log/Foo', storageKey: 'LogStorage_Foo' };
|
|
42
|
+
});
|
|
43
|
+
test('provides parent Log', () => {
|
|
44
|
+
subject();
|
|
45
|
+
expect(providedParent).toBe(parent);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=log-service.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-service.test.js","sourceRoot":"","sources":["../../src/__tests__/log-service.test.tsx"],"names":[],"mappings":";AACA,OAAO,EACH,QAAQ,EAER,eAAe,EACf,uBAAuB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,EAAa,MAAM,QAAQ,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAmB,MAAM,gBAAgB,CAAC;AAE7D,QAAQ,CAAC,iBAAiB,UAAU,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE;IAC9C,IAAI,KAAsB,CAAC;IAC3B,IAAI,WAAgB,CAAC;IACrB,IAAI,iBAA4B,CAAC;IACjC,IAAI,cAA+B,CAAC;IACpC,IAAI,UAAuC,CAAC;IAE5C,MAAM,SAAS,GAAO,GAAG,EAAE;QACvB,CAAC,WAAW,EAAE,iBAAiB,CAAC,GAAG,eAAe,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;QAC1E,CAAC,cAAc,CAAC,GAAG,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;QAC7D,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,GAAG,EAAE;QACjB,OAAO,MAAM,CACT,KAAC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AE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;QACnE,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE;YAC7B,OAAO,EAAE,CAAC;YAEV,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-storage.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/log-storage.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { LogEntryType } from '../log';
|
|
2
|
+
import { lastId, LogStorage } from '../log-storage';
|
|
3
|
+
import { MockBroadcastChannel } from './__mocks__';
|
|
4
|
+
describe(`${LogStorage.name}`, () => {
|
|
5
|
+
const LOCAL_STORAGE_VERSION = '1';
|
|
6
|
+
const logConfig = { endpoint: '/Log/Foo', storageKey: 'LogStorage_Foo' };
|
|
7
|
+
let logStorage;
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
jest.spyOn(globalThis, 'BroadcastChannel').mockImplementation((name) => new MockBroadcastChannel(name));
|
|
10
|
+
});
|
|
11
|
+
beforeEach(() => window.localStorage.clear());
|
|
12
|
+
afterEach(() => logStorage.dispose());
|
|
13
|
+
const subject = (entryOrEntries = []) => {
|
|
14
|
+
logStorage = new LogStorage(logConfig);
|
|
15
|
+
[entryOrEntries].flat().forEach(entry => logStorage.store(entry));
|
|
16
|
+
return logStorage;
|
|
17
|
+
};
|
|
18
|
+
function itLoadsNoItems() {
|
|
19
|
+
test('loads no items', () => {
|
|
20
|
+
expect(subject().items).toEqual([]);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
itLoadsNoItems();
|
|
24
|
+
describe('with previously saved items', () => {
|
|
25
|
+
const entries = createEntries(3);
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
const logStorage = new LogStorage(logConfig);
|
|
28
|
+
entries.map(entry => logStorage.store(entry));
|
|
29
|
+
logStorage.dispose();
|
|
30
|
+
});
|
|
31
|
+
function itLoadsSavedItems() {
|
|
32
|
+
test('loads saved items', () => {
|
|
33
|
+
expect(subject().items).toEqual(buildItems(entries).map(expect.objectContaining));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
itLoadsSavedItems();
|
|
37
|
+
describe('when saved data has incompatible version', () => {
|
|
38
|
+
const storageVersionKey = `${logConfig.storageKey}Version`;
|
|
39
|
+
beforeEach(() => window.localStorage.setItem(storageVersionKey, '-1'));
|
|
40
|
+
itLoadsNoItems();
|
|
41
|
+
test('updates version', () => {
|
|
42
|
+
subject();
|
|
43
|
+
expect(localStorage.getItem(storageVersionKey)).toBe(LOCAL_STORAGE_VERSION);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('when saved data is not valid', () => {
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
window.localStorage.setItem(logConfig.storageKey, '}{');
|
|
49
|
+
});
|
|
50
|
+
itLoadsNoItems();
|
|
51
|
+
});
|
|
52
|
+
describe('when saved data contains old "error" field', () => {
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
const itemsWithErrorField = JSON.parse(localStorage.getItem(logConfig.storageKey)).map(({ exception, ...rest }) => ({ ...rest, error: exception }));
|
|
55
|
+
localStorage.setItem(logConfig.storageKey, JSON.stringify(itemsWithErrorField));
|
|
56
|
+
});
|
|
57
|
+
itLoadsSavedItems();
|
|
58
|
+
});
|
|
59
|
+
describe('when multiple instances are running simultaneously', () => {
|
|
60
|
+
let otherLogStorage;
|
|
61
|
+
beforeEach(() => (otherLogStorage = new LogStorage(logConfig)));
|
|
62
|
+
afterEach(() => otherLogStorage.dispose());
|
|
63
|
+
test('deleteToId removes items from both instances', () => {
|
|
64
|
+
const logStorage = subject();
|
|
65
|
+
expect(logStorage.items.length).toEqual(entries.length);
|
|
66
|
+
expect(otherLogStorage.items.length).toEqual(entries.length);
|
|
67
|
+
logStorage.deleteToId(lastId(logStorage.items));
|
|
68
|
+
expect(logStorage.items).toEqual([]);
|
|
69
|
+
expect(otherLogStorage.items).toEqual([]);
|
|
70
|
+
});
|
|
71
|
+
test('deleteToId does not remove private items', () => {
|
|
72
|
+
const logStorage = subject();
|
|
73
|
+
const entry = createEntry({ message: 'foo' });
|
|
74
|
+
otherLogStorage.store(entry);
|
|
75
|
+
logStorage.deleteToId(lastId(logStorage.items));
|
|
76
|
+
expect(logStorage.items).toEqual([]);
|
|
77
|
+
expect(otherLogStorage.items).toEqual(buildItems([entry]).map(expect.objectContaining));
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
test('stores items with unique ids', () => {
|
|
82
|
+
const entries = createEntries(3);
|
|
83
|
+
const logStorage = subject(entries);
|
|
84
|
+
expect(logStorage.items).toEqual(buildItems(entries).map(expect.objectContaining));
|
|
85
|
+
expect(new Set(logStorage.items.map(({ id }) => id)).size).toBe(entries.length);
|
|
86
|
+
});
|
|
87
|
+
test('limits storage to 1000 items', () => {
|
|
88
|
+
const logStorage = subject(createEntries(1001));
|
|
89
|
+
expect(logStorage.items).toHaveLength(1000);
|
|
90
|
+
});
|
|
91
|
+
test('stringifies entry data', () => {
|
|
92
|
+
const entry = createEntry({ message: 'foo', data: { foo: 'bar' } });
|
|
93
|
+
const { data } = subject(entry).items[0];
|
|
94
|
+
expect(data).toBe(JSON.stringify(entry.data));
|
|
95
|
+
});
|
|
96
|
+
test('converts entry error to exception', () => {
|
|
97
|
+
const error = new Error('Oops!');
|
|
98
|
+
const { exception } = subject(createEntry({ error })).items[0];
|
|
99
|
+
expect(exception).toEqual(JSON.stringify({ message: error.message, stack: error.stack }));
|
|
100
|
+
});
|
|
101
|
+
test('deleteToId removes entries with same or lower id', () => {
|
|
102
|
+
const entries = createEntries(10);
|
|
103
|
+
const logStorage = subject(entries);
|
|
104
|
+
const index = 2;
|
|
105
|
+
const { id } = logStorage.items[index];
|
|
106
|
+
logStorage.deleteToId(id);
|
|
107
|
+
expect(logStorage.items.length).toBe(entries.length - index - 1);
|
|
108
|
+
expect(logStorage.items.every(entry => entry.id > id)).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
test('loadBatch returns first N items', () => {
|
|
111
|
+
const entries = createEntries(10);
|
|
112
|
+
const logStorage = subject(entries);
|
|
113
|
+
const count = 5;
|
|
114
|
+
const batch = logStorage.loadBatch(count);
|
|
115
|
+
expect(batch).toEqual(buildItems(entries.slice(0, count)).map(expect.objectContaining));
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
function buildItems(entries) {
|
|
119
|
+
return entries.map(({ data, error, ...rest }) => ({
|
|
120
|
+
...rest,
|
|
121
|
+
data: JSON.stringify(data),
|
|
122
|
+
exception: JSON.stringify(error && { message: error.message, stack: error.stack }),
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
function createEntries(length) {
|
|
126
|
+
return Array.from({ length }).map((_, index) => createEntry({ message: `Entry ${index}` }));
|
|
127
|
+
}
|
|
128
|
+
function createEntry(entry) {
|
|
129
|
+
return {
|
|
130
|
+
type: LogEntryType.Info,
|
|
131
|
+
message: null,
|
|
132
|
+
code: null,
|
|
133
|
+
category: null,
|
|
134
|
+
error: null,
|
|
135
|
+
data: {},
|
|
136
|
+
...entry,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=log-storage.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-storage.test.js","sourceRoot":"","sources":["../../src/__tests__/log-storage.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,YAAY,EAAE,MAAM,QAAQ,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,QAAQ,CAAC,GAAG,UA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Ac;IACjC,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,SAAS,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;AAChG,CAAC;AAED,SAAS,WAAW,CAAC,KAA6B;IAC9C,OAAO;QACH,IAAI,EAAE,YAAY,CAAC,IAAI;QACvB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,EAAE;QACR,GAAG,KAAK;KACX,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/log.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Log, LogEntryType } from '../log';
|
|
2
|
+
import { defaultLogConfig } from '../log-config';
|
|
3
|
+
import { LogStorage } from '../log-storage';
|
|
4
|
+
import { serializeWithMetadata } from '../serialize-with-metadata';
|
|
5
|
+
const SECOND = 1000;
|
|
6
|
+
const THROTTLE_INTERVAL = 30 * SECOND;
|
|
7
|
+
describe(`[log-service] ${Log.name}`, () => {
|
|
8
|
+
const logConfig = { endpoint: '/Log/Foo', storageKey: 'LogStorage_Foo' };
|
|
9
|
+
const entry = { category: 'category', code: 'code', message: 'foo' };
|
|
10
|
+
let parentLog;
|
|
11
|
+
beforeAll(() => jest.useFakeTimers());
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
jest.clearAllTimers();
|
|
14
|
+
jest.spyOn(console, 'error').mockImplementation(jest.fn());
|
|
15
|
+
window.localStorage.clear();
|
|
16
|
+
});
|
|
17
|
+
const subject = () => {
|
|
18
|
+
const logStorage = new LogStorage(logConfig);
|
|
19
|
+
const log = new Log(logStorage, parentLog);
|
|
20
|
+
jest.spyOn(logStorage, 'store');
|
|
21
|
+
return { log, logStorage };
|
|
22
|
+
};
|
|
23
|
+
test('logs info', () => {
|
|
24
|
+
const { log, logStorage } = subject();
|
|
25
|
+
log.info(entry);
|
|
26
|
+
expect(logStorage.store).toHaveBeenCalledWith(expect.objectContaining({ ...entry, type: LogEntryType.Info }));
|
|
27
|
+
});
|
|
28
|
+
test('logs warnings', () => {
|
|
29
|
+
const { log, logStorage } = subject();
|
|
30
|
+
log.warning(entry);
|
|
31
|
+
expect(logStorage.store).toHaveBeenCalledWith(expect.objectContaining({ ...entry, type: LogEntryType.Warning }));
|
|
32
|
+
});
|
|
33
|
+
test('log errors, after delay', () => {
|
|
34
|
+
const errorEntry = { ...entry, error: new Error('Oops!'), message: undefined };
|
|
35
|
+
const { log, logStorage } = subject();
|
|
36
|
+
log.error(errorEntry);
|
|
37
|
+
jest.runOnlyPendingTimers();
|
|
38
|
+
expect(logStorage.store).toHaveBeenCalledWith(expect.objectContaining({
|
|
39
|
+
...errorEntry,
|
|
40
|
+
type: LogEntryType.Error,
|
|
41
|
+
message: errorEntry.error.message,
|
|
42
|
+
}));
|
|
43
|
+
// eslint-disable-next-line no-console
|
|
44
|
+
expect(console.error).toHaveBeenCalledWith('@log-service/error', errorEntry);
|
|
45
|
+
});
|
|
46
|
+
test(`skips redundant error logged within ${THROTTLE_INTERVAL / SECOND}s`, () => {
|
|
47
|
+
const errorEntry = { ...entry, error: new Error('Oops!') };
|
|
48
|
+
const { log, logStorage } = subject();
|
|
49
|
+
Array.from({ length: 5 }).forEach(() => log.error(errorEntry));
|
|
50
|
+
jest.advanceTimersByTime(THROTTLE_INTERVAL);
|
|
51
|
+
expect(logStorage.store).toHaveBeenCalledTimes(1);
|
|
52
|
+
});
|
|
53
|
+
test(`keeps redundant error logged after ${THROTTLE_INTERVAL / SECOND}s`, () => {
|
|
54
|
+
const errorEntry = { ...entry, error: new Error('Oops!') };
|
|
55
|
+
const { log, logStorage } = subject();
|
|
56
|
+
Array.from({ length: 5 }).forEach(() => log.error(errorEntry));
|
|
57
|
+
jest.advanceTimersByTime(THROTTLE_INTERVAL);
|
|
58
|
+
Array.from({ length: 5 }).forEach(() => log.error(errorEntry));
|
|
59
|
+
jest.runOnlyPendingTimers();
|
|
60
|
+
expect(logStorage.store).toHaveBeenCalledTimes(2);
|
|
61
|
+
});
|
|
62
|
+
test('serializes non-standard errors', () => {
|
|
63
|
+
const errorEntry = { ...entry, error: { foo: 'bar' } };
|
|
64
|
+
const { log, logStorage } = subject();
|
|
65
|
+
log.error(errorEntry);
|
|
66
|
+
jest.runOnlyPendingTimers();
|
|
67
|
+
expect(logStorage.store).toHaveBeenCalledWith(expect.objectContaining({
|
|
68
|
+
message: errorEntry.message,
|
|
69
|
+
error: expect.objectContaining({
|
|
70
|
+
message: serializeWithMetadata(errorEntry.error),
|
|
71
|
+
}),
|
|
72
|
+
}));
|
|
73
|
+
});
|
|
74
|
+
test('extends log data', () => {
|
|
75
|
+
const data = { foo: 'bar' };
|
|
76
|
+
const { log, logStorage } = subject();
|
|
77
|
+
log.info({ ...entry, data });
|
|
78
|
+
expect(logStorage.store).toHaveBeenCalledWith(expect.objectContaining({
|
|
79
|
+
data: {
|
|
80
|
+
...data,
|
|
81
|
+
CreatedOn: new Date(),
|
|
82
|
+
Online: window.navigator.onLine,
|
|
83
|
+
Url: window.location.toString(),
|
|
84
|
+
UserAgent: window.navigator.userAgent,
|
|
85
|
+
Source: 'Frontend',
|
|
86
|
+
Plugins: '',
|
|
87
|
+
TzOffset: expect.any(Number),
|
|
88
|
+
IsDst: expect.any(Boolean),
|
|
89
|
+
IsDstSubject: expect.any(Boolean),
|
|
90
|
+
},
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
describe('when browser has plugins', () => {
|
|
94
|
+
const plugins = [
|
|
95
|
+
{ name: 'foo', filename: 'filename', description: 'description' },
|
|
96
|
+
{ name: 'bar', filename: 'filename', description: 'description' },
|
|
97
|
+
];
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
Object.defineProperty(window.navigator, 'plugins', { value: plugins, writable: true });
|
|
100
|
+
});
|
|
101
|
+
test('adds plugins to log data', () => {
|
|
102
|
+
const { log, logStorage } = subject();
|
|
103
|
+
log.info(entry);
|
|
104
|
+
expect(logStorage.store).toHaveBeenCalledWith(expect.objectContaining({
|
|
105
|
+
data: expect.objectContaining({
|
|
106
|
+
Plugins: plugins.map(p => [p.name, p.filename, p.description]).join('/'),
|
|
107
|
+
}),
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
110
|
+
describe('when error occurs reading plugins', () => {
|
|
111
|
+
beforeEach(() => Object.assign(window.navigator, { plugins: [undefined] }));
|
|
112
|
+
test('reports "unknown"', () => {
|
|
113
|
+
const { log, logStorage } = subject();
|
|
114
|
+
log.info(entry);
|
|
115
|
+
expect(logStorage.store).toHaveBeenCalledWith(expect.objectContaining({
|
|
116
|
+
data: expect.objectContaining({ Plugins: 'unknown' }),
|
|
117
|
+
}));
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe('when log has parent', () => {
|
|
122
|
+
beforeEach(() => (parentLog = new Log(new LogStorage(defaultLogConfig))));
|
|
123
|
+
test.each(['info', 'warning', 'error'])('forwards %s to parent log', method => {
|
|
124
|
+
jest.spyOn(parentLog, method);
|
|
125
|
+
const logEntry = { ...entry, error: new Error('Oops!') };
|
|
126
|
+
subject().log[method](logEntry);
|
|
127
|
+
expect(parentLog[method]).toHaveBeenCalledWith(logEntry);
|
|
128
|
+
});
|
|
129
|
+
describe.each(['endpoint', 'storageKey'])('when log uses default %s', key => {
|
|
130
|
+
beforeEach(() => (logConfig[key] = defaultLogConfig[key]));
|
|
131
|
+
test('throws error', () => {
|
|
132
|
+
expect(() => subject()).toThrow(/cannot use default configuration/);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
//# sourceMappingURL=log.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|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GAAG,KAAK,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACzD,OAAO,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;YAEhC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAC7D,CAAC,CACJ,CAAC;QAEF,QAAQ,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,YAAY,CAAwB,CAAC,CAC5D,0BAA0B,EAC1B,GAAG,CAAC,EAAE;YACF,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAE3D,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE;gBACtB,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC;YACxE,CAAC,CAAC,CAAC;QACP,CAAC,CACJ,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize-with-metadata.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/serialize-with-metadata.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { serializeWithMetadata } from '../serialize-with-metadata';
|
|
2
|
+
class Abc {
|
|
3
|
+
constructor() {
|
|
4
|
+
Object.defineProperty(this, "a", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: 1
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const cyclicObject = { a: { b: {} } };
|
|
13
|
+
cyclicObject.a.b = cyclicObject;
|
|
14
|
+
test.each([
|
|
15
|
+
[new Error('Error')],
|
|
16
|
+
[new Abc()],
|
|
17
|
+
[{ b: 1 }],
|
|
18
|
+
[null],
|
|
19
|
+
[undefined],
|
|
20
|
+
[function abc() { }],
|
|
21
|
+
[123],
|
|
22
|
+
[new Event('MyEvent')],
|
|
23
|
+
[cyclicObject],
|
|
24
|
+
])('Serialize with metadata %#', error => {
|
|
25
|
+
expect(serializeWithMetadata(error)).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=serialize-with-metadata.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize-with-metadata.test.js","sourceRoot":"","sources":["../../src/__tests__/serialize-with-metadata.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,MAAM,GAAG;IAAT;QACI;;;;mBAAI,CAAC;WAAC;IACV,CAAC;CAAA;AAED,MAAM,YAAY,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;AACtC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;AAEhC,IAAI,CAAC,IAAI,CAAC;IACN,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC,IAAI,GAAG,EAAE,CAAC;IACX,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACV,CAAC,IAAI,CAAC;IACN,CAAC,SAAS,CAAC;IACX,CAAC,SAAS,GAAG,KAAI,CAAC,CAAC;IACnB,CAAC,GAAG,CAAC;IACL,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;IACtB,CAAC,YAAY,CAAC;CACjB,CAAC,CAAC,4BAA4B,EAAE,KAAK,CAAC,EAAE;IACrC,MAAM,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;AAC3D,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/log-service",
|
|
3
|
-
"version": "28.
|
|
3
|
+
"version": "28.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/log-service",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@servicetitan/react-ioc": "28.
|
|
19
|
+
"@servicetitan/react-ioc": "28.2.0",
|
|
20
20
|
"@testing-library/dom": "^10.4.0",
|
|
21
21
|
"@testing-library/react": "^16.0.1",
|
|
22
22
|
"@types/lodash.throttle": "~4.1.6",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"react": "~18.3.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@servicetitan/react-ioc": "28.
|
|
28
|
+
"@servicetitan/react-ioc": "28.2.0",
|
|
29
29
|
"axios": "~0.28.1",
|
|
30
30
|
"mobx": ">=6.13.5",
|
|
31
31
|
"react": ">=17.0.2"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"cli": {
|
|
40
40
|
"webpack": false
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "df48bdf4994bce3971c7e4f099eeb11ebb4945e6"
|
|
43
43
|
}
|