From 3bd746aa5a12cfdf00e172c21a2506d630b1f895 Mon Sep 17 00:00:00 2001 From: Jonathan Norris Date: Fri, 26 Jan 2024 14:34:37 -0500 Subject: [PATCH] feat: change to not await onInitialized --- examples/openfeature-nodejs/src/main.ts | 6 ++---- sdk/nodejs/__tests__/initialize.spec.ts | 10 +++++++--- sdk/nodejs/src/client.ts | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/openfeature-nodejs/src/main.ts b/examples/openfeature-nodejs/src/main.ts index d96d1718e..d22786314 100644 --- a/examples/openfeature-nodejs/src/main.ts +++ b/examples/openfeature-nodejs/src/main.ts @@ -7,10 +7,8 @@ const DEVCYCLE_SERVER_SDK_KEY = let openFeatureClient: Client async function startDevCycle() { - OpenFeature.setProvider( - await initializeDevCycle( - DEVCYCLE_SERVER_SDK_KEY, - ).getOpenFeatureProvider(), + await OpenFeature.setProviderAndWait( + initializeDevCycle(DEVCYCLE_SERVER_SDK_KEY).getOpenFeatureProvider(), ) openFeatureClient = OpenFeature.getClient() diff --git a/sdk/nodejs/__tests__/initialize.spec.ts b/sdk/nodejs/__tests__/initialize.spec.ts index 726c87b5a..42a4701cb 100644 --- a/sdk/nodejs/__tests__/initialize.spec.ts +++ b/sdk/nodejs/__tests__/initialize.spec.ts @@ -1,4 +1,5 @@ import { DevCycleCloudClient, initializeDevCycle } from '../src/index' +import { OpenFeature } from '@openfeature/server-sdk' jest.mock('../src/bucketing') jest.mock('@devcycle/config-manager') @@ -16,11 +17,14 @@ describe('NodeJS SDK Initialize', () => { }) it('successfully creates a OpenFeature provider', async () => { - const provider = await initializeDevCycle( - 'dvc_server_token', - ).getOpenFeatureProvider() + const provider = + initializeDevCycle('dvc_server_token').getOpenFeatureProvider() expect(provider).toBeDefined() + expect(provider.status).toBe('NOT READY') + await OpenFeature.setProviderAndWait(provider) expect(provider.status).toBe('READY') + const client = OpenFeature.getClient() + expect(client).toBeDefined() }) it('fails to initialize in Local Bucketing mode when no token is provided', () => { diff --git a/sdk/nodejs/src/client.ts b/sdk/nodejs/src/client.ts index 224d1cc93..b6cffbcb7 100644 --- a/sdk/nodejs/src/client.ts +++ b/sdk/nodejs/src/client.ts @@ -125,10 +125,9 @@ export class DevCycleClient { }) } - async getOpenFeatureProvider(): Promise { + getOpenFeatureProvider(): DevCycleProvider { if (this.openFeatureProvider) return this.openFeatureProvider - await this.onInitialized this.openFeatureProvider = new DevCycleProvider(this) return this.openFeatureProvider }