@etsoo/shared 1.2.33 → 1.2.34

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,6 +1,7 @@
1
1
  import { DomUtils } from '../src/DomUtils';
2
2
  import { DataTypes } from '../src/DataTypes';
3
3
  import { DateUtils } from '../src/DateUtils';
4
+ import { ErrorData } from '../src/types/ErrorData';
4
5
 
5
6
  // Implement for tests
6
7
  class Rect implements DOMRect {
@@ -302,12 +303,12 @@ test('Tests for setFocus', () => {
302
303
  container.append(input);
303
304
 
304
305
  DomUtils.setFocus('test');
305
- expect(focus).toBeCalledTimes(1);
306
+ expect(focus).toHaveBeenCalledTimes(1);
306
307
 
307
308
  input.blur();
308
309
 
309
310
  DomUtils.setFocus({ test: 'No content' }, container);
310
- expect(focus).toBeCalledTimes(2);
311
+ expect(focus).toHaveBeenCalledTimes(2);
311
312
  });
312
313
 
313
314
  test('Tests for getInputValue', () => {
@@ -327,9 +328,11 @@ test('Tests for getInputValue', () => {
327
328
  }
328
329
  });
329
330
 
330
- test('Tests for setupLogging', () => {
331
+ test('Tests for setupLogging', async () => {
331
332
  // Arrange
332
- const action = jest.fn();
333
+ const action = jest.fn((data: ErrorData) => {
334
+ expect(data.message).toBe('Test');
335
+ });
333
336
  DomUtils.setupLogging(action, true);
334
337
 
335
338
  // Act
@@ -49,28 +49,28 @@ test('Tests for events', () => {
49
49
  history.on('navigate', navigatorFn, { capture: true, once: true });
50
50
 
51
51
  history.clear();
52
- expect(clearFn).toBeCalled();
52
+ expect(clearFn).toHaveBeenCalled();
53
53
 
54
54
  history.pushState(1);
55
- expect(pushFn).toBeCalled();
55
+ expect(pushFn).toHaveBeenCalled();
56
56
 
57
57
  history.replaceState(11);
58
- expect(replaceFn).toBeCalled();
58
+ expect(replaceFn).toHaveBeenCalled();
59
59
 
60
60
  history.pushState(2);
61
61
  history.back();
62
- expect(navigatorFn).toBeCalledTimes(3);
62
+ expect(navigatorFn).toHaveBeenCalledTimes(3);
63
63
 
64
64
  history.forward();
65
65
  // Once handler was removed
66
- expect(navigatorFn).toBeCalledTimes(5);
66
+ expect(navigatorFn).toHaveBeenCalledTimes(5);
67
67
 
68
68
  history.on('navigate', navigatorStopFn, { capture: true });
69
69
  history.go(-1);
70
- expect(navigatorStopFn).toBeCalled();
70
+ expect(navigatorStopFn).toHaveBeenCalled();
71
71
 
72
72
  // Previous handler stopped propagation
73
- expect(navigatorFn).toBeCalledTimes(5);
73
+ expect(navigatorFn).toHaveBeenCalledTimes(5);
74
74
 
75
75
  history.pushState(3);
76
76
  history.pushState(4);
@@ -34,7 +34,7 @@ test('Tests for delayedExecutor', () => {
34
34
 
35
35
  e.call(2, true, 'b');
36
36
 
37
- expect(f).toBeCalledTimes(0);
37
+ expect(f).toHaveBeenCalledTimes(0);
38
38
  e.clear();
39
39
  expect(e.isRunning()).toBeFalsy();
40
40
  });
@@ -2,6 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
4
  "module": "ESNext",
5
+ "moduleResolution": "Node10",
5
6
  "allowJs": false,
6
7
  "skipLibCheck": true,
7
8
  "esModuleInterop": true,
@@ -523,7 +523,7 @@ var DomUtils;
523
523
  else {
524
524
  data = {
525
525
  type: 'error',
526
- eventType: message.type,
526
+ subType: message.type,
527
527
  message: error?.message ??
528
528
  `${message.currentTarget} event error`,
529
529
  source,
@@ -541,14 +541,25 @@ var DomUtils;
541
541
  if (rejectionPD)
542
542
  event.preventDefault();
543
543
  const reason = event.reason;
544
- const data = {
545
- type: 'unhandledrejection',
546
- eventType: event.type,
547
- message: typeof reason === 'string'
548
- ? reason
549
- : JSON.stringify(reason),
550
- source: globalThis.location.href
551
- };
544
+ let data;
545
+ if (reason instanceof Error) {
546
+ data = {
547
+ type: 'unhandledrejection',
548
+ subType: reason.name,
549
+ message: reason.message,
550
+ stack: reason.stack,
551
+ source: globalThis.location.href
552
+ };
553
+ }
554
+ else {
555
+ data = {
556
+ type: 'unhandledrejection',
557
+ message: typeof reason === 'string'
558
+ ? reason
559
+ : JSON.stringify(reason),
560
+ source: globalThis.location.href
561
+ };
562
+ }
552
563
  action(data);
553
564
  };
554
565
  const localConsole = (type, orgin) => {
@@ -1,7 +1,7 @@
1
1
  export type ErrorType = 'error' | 'unhandledrejection' | 'consoleWarn' | 'consoleError';
2
2
  export type ErrorData = {
3
3
  type: ErrorType;
4
- eventType?: string;
4
+ subType?: string;
5
5
  message: string;
6
6
  source?: string;
7
7
  lineNo?: number;
@@ -520,7 +520,7 @@ export var DomUtils;
520
520
  else {
521
521
  data = {
522
522
  type: 'error',
523
- eventType: message.type,
523
+ subType: message.type,
524
524
  message: error?.message ??
525
525
  `${message.currentTarget} event error`,
526
526
  source,
@@ -538,14 +538,25 @@ export var DomUtils;
538
538
  if (rejectionPD)
539
539
  event.preventDefault();
540
540
  const reason = event.reason;
541
- const data = {
542
- type: 'unhandledrejection',
543
- eventType: event.type,
544
- message: typeof reason === 'string'
545
- ? reason
546
- : JSON.stringify(reason),
547
- source: globalThis.location.href
548
- };
541
+ let data;
542
+ if (reason instanceof Error) {
543
+ data = {
544
+ type: 'unhandledrejection',
545
+ subType: reason.name,
546
+ message: reason.message,
547
+ stack: reason.stack,
548
+ source: globalThis.location.href
549
+ };
550
+ }
551
+ else {
552
+ data = {
553
+ type: 'unhandledrejection',
554
+ message: typeof reason === 'string'
555
+ ? reason
556
+ : JSON.stringify(reason),
557
+ source: globalThis.location.href
558
+ };
559
+ }
549
560
  action(data);
550
561
  };
551
562
  const localConsole = (type, orgin) => {
@@ -1,7 +1,7 @@
1
1
  export type ErrorType = 'error' | 'unhandledrejection' | 'consoleWarn' | 'consoleError';
2
2
  export type ErrorData = {
3
3
  type: ErrorType;
4
- eventType?: string;
4
+ subType?: string;
5
5
  message: string;
6
6
  source?: string;
7
7
  lineNo?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.2.33",
3
+ "version": "1.2.34",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
package/src/DomUtils.ts CHANGED
@@ -630,7 +630,7 @@ export namespace DomUtils {
630
630
  } else {
631
631
  data = {
632
632
  type: 'error',
633
- eventType: message.type,
633
+ subType: message.type,
634
634
  message:
635
635
  error?.message ??
636
636
  `${message.currentTarget} event error`,
@@ -652,15 +652,26 @@ export namespace DomUtils {
652
652
  if (rejectionPD) event.preventDefault();
653
653
 
654
654
  const reason = event.reason;
655
- const data: ErrorData = {
656
- type: 'unhandledrejection',
657
- eventType: event.type,
658
- message:
659
- typeof reason === 'string'
660
- ? reason
661
- : JSON.stringify(reason),
662
- source: globalThis.location.href
663
- };
655
+ let data: ErrorData;
656
+
657
+ if (reason instanceof Error) {
658
+ data = {
659
+ type: 'unhandledrejection',
660
+ subType: reason.name,
661
+ message: reason.message,
662
+ stack: reason.stack,
663
+ source: globalThis.location.href
664
+ };
665
+ } else {
666
+ data = {
667
+ type: 'unhandledrejection',
668
+ message:
669
+ typeof reason === 'string'
670
+ ? reason
671
+ : JSON.stringify(reason),
672
+ source: globalThis.location.href
673
+ };
674
+ }
664
675
 
665
676
  action(data);
666
677
  };
@@ -6,7 +6,7 @@ export type ErrorType =
6
6
 
7
7
  export type ErrorData = {
8
8
  type: ErrorType;
9
- eventType?: string;
9
+ subType?: string;
10
10
  message: string;
11
11
  source?: string;
12
12
  lineNo?: number;