11import { expect } from 'chai' ;
22import { beforeEach , describe , it } from 'mocha' ;
3- import { ExceptionlessClient } from 'src/ExceptionlessClient' ;
4- import { EventPluginContext } from 'src/plugins/EventPluginContext' ;
5- import { DuplicateCheckerPlugin } from 'src/plugins/default/DuplicateCheckerPlugin' ;
6- import { IInnerError } from "src/models/IInnerError" ;
7- import { IStackFrame } from "src/models/IStackFrame" ;
3+ import { ExceptionlessClient } from '../../../src/ExceptionlessClient' ;
4+ import { EventPluginContext } from '../../../src/plugins/EventPluginContext' ;
5+ import { DuplicateCheckerPlugin } from '../../../src/plugins/default/DuplicateCheckerPlugin' ;
6+ import { IInnerError } from "../../../src/models/IInnerError" ;
7+ import { IStackFrame } from "../../../src/models/IStackFrame" ;
8+
9+ const Exception1StackTrace = [
10+ {
11+ file_name : "index.js" ,
12+ line_number : 0 ,
13+ column : 50 ,
14+ is_signature_target : true ,
15+ name : "createException" ,
16+ } ,
17+ {
18+ file_name : "index.js" ,
19+ line_number : 5 ,
20+ column : 25 ,
21+ is_signature_target : false ,
22+ name : "throwError" ,
23+ }
24+ ] ;
25+
26+ const Exception2StackTrace = [
27+ {
28+ file_name : "index.js" ,
29+ line_number : 0 ,
30+ column : 50 ,
31+ is_signature_target : true ,
32+ name : "createException2" ,
33+ } ,
34+ {
35+ file_name : "index.js" ,
36+ line_number : 5 ,
37+ column : 25 ,
38+ is_signature_target : false ,
39+ name : "throwError2" ,
40+ }
41+ ] ;
842
943describe ( 'DuplicateCheckerPlugin' , ( ) => {
1044 let now : number = 0 ;
@@ -34,10 +68,9 @@ describe('DuplicateCheckerPlugin', () => {
3468 }
3569
3670 it ( 'should ignore duplicate within window' , ( done ) => {
37- const exception = createException ( ) ;
38- run ( exception ) ;
71+ run ( Exception1StackTrace ) ;
3972
40- const contextOfSecondRun = run ( exception ) ;
73+ const contextOfSecondRun = run ( Exception1StackTrace ) ;
4174 expect ( contextOfSecondRun . cancelled ) . to . be . true ;
4275 setTimeout ( ( ) => {
4376 expect ( contextOfSecondRun . event . count ) . to . equal ( 1 ) ;
@@ -47,51 +80,23 @@ describe('DuplicateCheckerPlugin', () => {
4780 } ) ;
4881
4982 it ( 'should ignore error without stack' , ( ) => {
50- const exception = new ReferenceError ( 'This is a test' ) ;
51- delete exception . stack ;
52-
53- run ( exception ) ;
54- const contextOfSecondRun = run ( exception ) ;
83+ run ( ) ;
84+ const contextOfSecondRun = run ( ) ;
5585 expect ( contextOfSecondRun . cancelled ) . to . be . true ;
5686 } ) ;
5787
5888 it ( 'shouldn\'t ignore different stack within window' , ( ) => {
59- const exception1 = createException ( ) ;
60- run ( exception1 ) ;
61- const exception2 = createException2 ( ) ;
62- const contextOfSecondRun = run ( exception2 ) ;
89+ run ( Exception1StackTrace ) ;
90+ const contextOfSecondRun = run ( Exception2StackTrace ) ;
6391
6492 expect ( contextOfSecondRun . cancelled ) . not . to . be . true ;
6593 } ) ;
6694
6795 it ( 'shouldn\'t ignore duplicate after window' , ( ) => {
68- const exception = createException ( ) ;
69- run ( exception ) ;
96+ run ( Exception1StackTrace ) ;
7097
7198 now = 3000 ;
72- const contextOfSecondRun = run ( exception ) ;
99+ const contextOfSecondRun = run ( Exception1StackTrace ) ;
73100 expect ( contextOfSecondRun . cancelled ) . not . to . be . true ;
74101 } ) ;
75102} ) ;
76-
77- function createException ( ) {
78- function throwError ( ) {
79- throw new ReferenceError ( 'This is a test' ) ;
80- }
81- try {
82- throwError ( ) ;
83- } catch ( e ) {
84- return e ;
85- }
86- }
87-
88- function createException2 ( ) {
89- function throwError2 ( ) {
90- throw new ReferenceError ( 'This is a test' ) ;
91- }
92- try {
93- throwError2 ( ) ;
94- } catch ( e ) {
95- return e ;
96- }
97- }
0 commit comments