1+ import { Schema } from '../../core/dist/types/config'
12import BugsnagIpcMain from '../bugsnag-ipc-main'
23import { Client , User , Plugin , Event , FeatureFlag } from '@bugsnag/core'
34
@@ -14,17 +15,20 @@ const Notifier = {
1415 url : 'https://github.com/bugsnag/bugsnag-js'
1516}
1617
18+ // @ts -expect-error invalid schema expected for testing
19+ const testSchema : Schema = { }
20+
1721describe ( 'BugsnagIpcMain' , ( ) => {
1822 describe ( 'constructor()' , ( ) => {
1923 it ( 'should throw if the state manager plugin is not loaded first' , ( ) => {
20- const client = new Client ( { apiKey : '123' } , { } , [ ] , Notifier )
24+ const client = new Client ( { apiKey : '123' } , testSchema , [ ] , Notifier )
2125 expect ( ( ) => {
2226 // eslint-disable-next-line @typescript-eslint/no-unused-vars
2327 const bugsnagIpcMain = new BugsnagIpcMain ( client )
2428 } ) . toThrowError ( 'Expected @bugsnag/plugin-electron-client-state-manager to be loaded first' )
2529 } )
2630 it ( 'should work when the state manager plugin is loaded first' , ( ) => {
27- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
31+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
2832 expect ( ( ) => {
2933 // eslint-disable-next-line @typescript-eslint/no-unused-vars
3034 const bugsnagIpcMain = new BugsnagIpcMain ( client )
@@ -34,15 +38,15 @@ describe('BugsnagIpcMain', () => {
3438
3539 describe ( 'handle()' , ( ) => {
3640 it ( 'works for updating context' , ( ) => {
37- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
41+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
3842 client . setContext = jest . fn ( )
3943 const bugsnagIpcMain = new BugsnagIpcMain ( client )
4044 bugsnagIpcMain . handle ( { } , 'setContext' , JSON . stringify ( 'new context' ) )
4145 expect ( client . setContext ) . toHaveBeenCalledWith ( 'new context' )
4246 } )
4347
4448 it ( 'returns the current context' , ( ) => {
45- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
49+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
4650 client . setContext ( 'today' )
4751 const bugsnagIpcMain = new BugsnagIpcMain ( client )
4852 const event = { returnValue : undefined }
@@ -51,7 +55,7 @@ describe('BugsnagIpcMain', () => {
5155 } )
5256
5357 it ( 'works for updating user' , ( ) => {
54- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
58+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
5559 client . setUser = jest . fn ( )
5660 const bugsnagIpcMain = new BugsnagIpcMain ( client )
5761 // all fields set
@@ -63,7 +67,7 @@ describe('BugsnagIpcMain', () => {
6367 } )
6468
6569 it ( 'returns the current user' , ( ) => {
66- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
70+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
6771 client . setUser ( '81676' , undefined , 'Cal' )
6872 const bugsnagIpcMain = new BugsnagIpcMain ( client )
6973 const event = { returnValue : undefined }
@@ -72,7 +76,7 @@ describe('BugsnagIpcMain', () => {
7276 } )
7377
7478 it ( 'works for adding metadata' , ( ) => {
75- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
79+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
7680 client . addMetadata = jest . fn ( )
7781 const bugsnagIpcMain = new BugsnagIpcMain ( client )
7882 const stubWebContents = { /* this would be a WebContents instance */ }
@@ -82,15 +86,15 @@ describe('BugsnagIpcMain', () => {
8286 } )
8387
8488 it ( 'works for removing metadata' , ( ) => {
85- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
89+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
8690 client . clearMetadata = jest . fn ( )
8791 const bugsnagIpcMain = new BugsnagIpcMain ( client )
8892 bugsnagIpcMain . handle ( { } , 'clearMetadata' , JSON . stringify ( 'section' ) )
8993 expect ( client . clearMetadata ) . toHaveBeenCalledWith ( 'section' )
9094 } )
9195
9296 it ( 'returns metadata content' , ( ) => {
93- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
97+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
9498 client . addMetadata ( 'section' , 'content' , 'X' )
9599 const bugsnagIpcMain = new BugsnagIpcMain ( client )
96100 const event = { returnValue : undefined }
@@ -104,7 +108,7 @@ describe('BugsnagIpcMain', () => {
104108 } )
105109
106110 it ( 'works for adding a single feature flag' , ( ) => {
107- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
111+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
108112 client . addFeatureFlag = jest . fn ( )
109113
110114 const bugsnagIpcMain = new BugsnagIpcMain ( client )
@@ -116,7 +120,7 @@ describe('BugsnagIpcMain', () => {
116120 } )
117121
118122 it ( 'works for adding multiple feature flags' , ( ) => {
119- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
123+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
120124 client . addFeatureFlags = jest . fn ( )
121125
122126 const bugsnagIpcMain = new BugsnagIpcMain ( client )
@@ -136,7 +140,7 @@ describe('BugsnagIpcMain', () => {
136140 } )
137141
138142 it ( 'works for clearing a single feature flag' , ( ) => {
139- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
143+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
140144 client . clearFeatureFlag = jest . fn ( )
141145
142146 const bugsnagIpcMain = new BugsnagIpcMain ( client )
@@ -148,7 +152,7 @@ describe('BugsnagIpcMain', () => {
148152 } )
149153
150154 it ( 'works for clearing all feature flags' , ( ) => {
151- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
155+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
152156 client . clearFeatureFlags = jest . fn ( )
153157
154158 const bugsnagIpcMain = new BugsnagIpcMain ( client )
@@ -160,7 +164,7 @@ describe('BugsnagIpcMain', () => {
160164 } )
161165
162166 it ( 'works for managing sessions' , ( ) => {
163- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
167+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
164168 client . _sessionDelegate = { startSession : jest . fn ( ) , resumeSession : jest . fn ( ) , pauseSession : jest . fn ( ) }
165169 const bugsnagIpcMain = new BugsnagIpcMain ( client )
166170 // start
@@ -175,7 +179,7 @@ describe('BugsnagIpcMain', () => {
175179 } )
176180
177181 it ( 'works for breadcrumbs' , ( done ) => {
178- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
182+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
179183 client . addOnBreadcrumb ( b => {
180184 expect ( b . message ) . toBe ( 'hi IPC' )
181185 expect ( b . type ) . toBe ( 'manual' )
@@ -191,7 +195,7 @@ describe('BugsnagIpcMain', () => {
191195 } )
192196
193197 it ( 'works for bulk updates' , done => {
194- const client = new Client ( { apiKey : '123' } , { } , [ {
198+ const client = new Client ( { apiKey : '123' } , testSchema , [ {
195199 name : 'clientStateManager' ,
196200 load : ( ) => ( {
197201 bulkUpdate : ( { context, user, metadata, features } : { context ?: string , user ?: User , metadata : Record < string , unknown > , features : FeatureFlag | null [ ] } ) => {
@@ -219,13 +223,13 @@ describe('BugsnagIpcMain', () => {
219223 } )
220224
221225 it ( 'is resilient to unknown methods' , ( ) => {
222- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
226+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
223227 const bugsnagIpcMain = new BugsnagIpcMain ( client )
224228 expect ( ( ) => bugsnagIpcMain . handle ( { } , 'explodePlease' , JSON . stringify ( { data : 123 } ) ) ) . not . toThrowError ( )
225229 } )
226230
227231 it ( 'is resilient to bad JSON' , ( ) => {
228- const client = new Client ( { apiKey : '123' } , { } , [ mockClientStateManagerPlugin ] , Notifier )
232+ const client = new Client ( { apiKey : '123' } , testSchema , [ mockClientStateManagerPlugin ] , Notifier )
229233 const bugsnagIpcMain = new BugsnagIpcMain ( client )
230234 expect ( ( ) => bugsnagIpcMain . handle ( { } , 'leaveBreadcrumb' , 'not json' ) ) . not . toThrowError ( )
231235 } )
0 commit comments