11/* eslint-disable @typescript-eslint/no-unused-vars */
2- import { nanoid } from 'nanoid' ;
32import {
43 EventSource ,
54 EventSourceInitDict ,
@@ -13,6 +12,8 @@ import {
1312 ClientContext ,
1413 Context ,
1514 internal ,
15+ Hmac ,
16+ Hasher ,
1617} from '@launchdarkly/js-sdk-common' ;
1718import DiagnosticsManager from '../../src/events/DiagnosticsManager' ;
1819import Configuration from '../../src/options/Configuration' ;
@@ -29,11 +30,6 @@ interface RequestState {
2930 requestsMade : Array < { url : string ; options : Options } > ;
3031}
3132
32- // Mock the nanoid module so we can replace the implementation in specific tests.
33- jest . mock ( 'nanoid' , ( ) => ( {
34- nanoid : jest . fn ( ( ) => jest . requireActual ( 'nanoid' ) . nanoid ( ) ) ,
35- } ) ) ;
36-
3733function makePlatform ( requestState : RequestState ) {
3834 const info : Info = {
3935 platformData ( ) : PlatformData {
@@ -114,14 +110,27 @@ function makePlatform(requestState: RequestState) {
114110 throw new Error ( 'Function not implemented.' ) ;
115111 } ,
116112 } ;
117- return { info, requests, waitForMessages } ;
113+ return {
114+ info,
115+ requests,
116+ waitForMessages,
117+ crypto : {
118+ createHash ( algorithm : string ) : Hasher {
119+ // Not used for this test.
120+ throw new Error ( `Function not implemented.${ algorithm } ` ) ;
121+ } ,
122+ createHmac ( algorithm : string , key : string ) : Hmac {
123+ // Not used for this test.
124+ throw new Error ( `Function not implemented.${ algorithm } ${ key } ` ) ;
125+ } ,
126+ randomUUID : ( ) => '9-ypf7NswGfZ3CN2WpTix' ,
127+ } ,
128+ } ;
118129}
119130
120131const user = { key : 'userKey' , name : 'Red' } ;
121132
122133describe ( 'given an event processor with diagnostics manager' , ( ) => {
123- jest . mock ( 'nanoid' , ( ) => ( { nanoid : ( ) => '9-ypf7NswGfZ3CN2WpTix' } ) ) ;
124-
125134 let eventProcessor : internal . EventProcessor ;
126135
127136 const requestState : RequestState = {
@@ -145,12 +154,11 @@ describe('given an event processor with diagnostics manager', () => {
145154 let waitForMessages : ( count : number ) => Promise < number > ;
146155
147156 beforeEach ( ( ) => {
148- // @ts -ignore
149- nanoid . mockImplementation ( ( ) => '9-ypf7NswGfZ3CN2WpTix' ) ;
150-
151157 const platform = makePlatform ( requestState ) ;
158+
152159 info = platform . info ;
153160 requests = platform . requests ;
161+ const { crypto } = platform ;
154162 waitForMessages = platform . waitForMessages ;
155163
156164 resetRequestState ( ) ;
@@ -171,6 +179,7 @@ describe('given an event processor with diagnostics manager', () => {
171179 // Replace info and requests.
172180 info,
173181 requests,
182+ crypto,
174183 } ,
175184 store
176185 ) ;
0 commit comments