@@ -3,6 +3,7 @@ import { expect, test, describe, vi, beforeEach, afterEach } from 'vitest';
33
44// Create mocks in hoisted scope
55const mockLDClient = {
6+ start : vi . fn ( ) ,
67 waitForInitialization : vi . fn ( ) ,
78 variation : vi . fn ( ) ,
89 identify : vi . fn ( ) ,
@@ -12,9 +13,9 @@ const mockLDClient = {
1213 track : vi . fn ( ) ,
1314} ;
1415
15- vi . mock ( 'launchdarkly- js-client-sdk' , ( ) => {
16+ vi . mock ( '@ launchdarkly/ js-client-sdk' , ( ) => {
1617 return {
17- initialize : vi . fn ( ) ,
18+ createClient : vi . fn ( ) ,
1819 } ;
1920} ) ;
2021
@@ -65,18 +66,19 @@ vi.mock('@launchdarkly/session-replay', () => {
6566 } ;
6667} ) ;
6768
69+ import React from 'react' ;
6870import {
6971 InternalClientProvider ,
7072 useInternalClient ,
7173 useInternalClientInstance ,
7274} from '../ui/Toolbar/context/telemetry/InternalClientProvider' ;
7375import { setToolbarFlagClient } from '../../flags/createToolbarFlagFunction' ;
7476import * as toolbarFlagClient from '../../flags/createToolbarFlagFunction' ;
75- import { initialize } from 'launchdarkly- js-client-sdk' ;
77+ import { createClient } from '@ launchdarkly/ js-client-sdk' ;
7678import { LDObserve } from '@launchdarkly/observability' ;
7779import { LDRecord } from '@launchdarkly/session-replay' ;
7880
79- const mockInitialize = vi . mocked ( initialize ) ;
81+ const mockCreateClient = vi . mocked ( createClient ) ;
8082const mockLDObserveMethods = vi . mocked ( LDObserve ) ;
8183const mockLDRecordMethods = vi . mocked ( LDRecord ) ;
8284
@@ -108,6 +110,7 @@ describe('InternalClientProvider', () => {
108110 beforeEach ( ( ) => {
109111 vi . clearAllMocks ( ) ;
110112
113+ mockLDClient . start . mockResolvedValue ( undefined ) ;
111114 mockLDClient . waitForInitialization . mockResolvedValue ( undefined ) ;
112115 mockLDClient . identify . mockResolvedValue ( undefined ) ;
113116 // Return false for session replay flag by default to prevent it from starting
@@ -117,7 +120,7 @@ describe('InternalClientProvider', () => {
117120 mockLDClient . off . mockImplementation ( ( ) => { } ) ;
118121 mockLDClient . track . mockImplementation ( ( ) => { } ) ;
119122
120- mockInitialize . mockReturnValue ( mockLDClient ) ;
123+ mockCreateClient . mockReturnValue ( mockLDClient as any ) ;
121124
122125 mockLDObserveMethods . start . mockClear ( ) ;
123126 mockLDObserveMethods . stop . mockClear ( ) ;
@@ -173,7 +176,7 @@ describe('InternalClientProvider', () => {
173176 ) ;
174177
175178 await waitFor ( ( ) => {
176- expect ( mockInitialize ) . toHaveBeenCalledWith (
179+ expect ( mockCreateClient ) . toHaveBeenCalledWith (
177180 'test-client-id-123' ,
178181 {
179182 kind : 'user' ,
@@ -201,7 +204,7 @@ describe('InternalClientProvider', () => {
201204 ) ;
202205
203206 await waitFor ( ( ) => {
204- expect ( mockInitialize ) . toHaveBeenCalledWith (
207+ expect ( mockCreateClient ) . toHaveBeenCalledWith (
205208 'test-client-id-123' ,
206209 customContext ,
207210 expect . objectContaining ( {
@@ -261,15 +264,15 @@ describe('InternalClientProvider', () => {
261264 ) ;
262265
263266 await waitFor ( ( ) => {
264- expect ( mockInitialize ) . toHaveBeenCalledWith (
267+ expect ( mockCreateClient ) . toHaveBeenCalledWith (
265268 'test-client-id-123' ,
266269 expect . objectContaining ( {
267270 kind : 'user' ,
268271 key : 'toolbar-anonymous' ,
269272 anonymous : true ,
270273 } ) ,
271274 expect . objectContaining ( {
272- baseUrl : 'https://app.ld.catamorphic.com' ,
275+ baseUri : 'https://app.ld.catamorphic.com' ,
273276 plugins : expect . any ( Array ) ,
274277 } ) ,
275278 ) ;
@@ -284,7 +287,7 @@ describe('InternalClientProvider', () => {
284287 ) ;
285288
286289 await waitFor ( ( ) => {
287- expect ( mockInitialize ) . toHaveBeenCalledWith (
290+ expect ( mockCreateClient ) . toHaveBeenCalledWith (
288291 'test-client-id-123' ,
289292 expect . any ( Object ) ,
290293 expect . objectContaining ( {
0 commit comments