From ed37356ee3194a7c7f3253a868cd3fc53b11e9f5 Mon Sep 17 00:00:00 2001 From: simeng-li Date: Mon, 17 Jun 2024 10:30:16 +0800 Subject: [PATCH] refactor(console,experience,test): decouple isDevFeatureEnabled with isIntegrationTest (#6012) * refactor(console,experience,test): decouple isDevFeatureEnabled with isIntegrationTest decouple isDevFeatureEnabled with isIntegrationTest ENV variables * chore: update environment variable get method update environment variable get method --- .../alteration-compatibility-integration-test.yml | 2 ++ .github/workflows/integration-test.yml | 2 ++ packages/console/src/consts/env.ts | 1 - packages/experience/src/constants/env.ts | 4 +--- packages/integration-tests/src/constants.ts | 6 ++++-- .../integration-tests/src/tests/console/bootstrap.test.ts | 7 +++++++ packages/shared/src/node/env/GlobalValues.ts | 3 +-- 7 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/alteration-compatibility-integration-test.yml b/.github/workflows/alteration-compatibility-integration-test.yml index 2b06b877c..b4334641a 100644 --- a/.github/workflows/alteration-compatibility-integration-test.yml +++ b/.github/workflows/alteration-compatibility-integration-test.yml @@ -50,6 +50,7 @@ jobs: if: ${{needs.check-alteration-changes.outputs.has-alteration-changes == 'true'}} env: INTEGRATION_TEST: true + DEV_FEATURES_ENABLED: true steps: - uses: logto-io/actions-package-logto-artifact@v2 with: @@ -66,6 +67,7 @@ jobs: runs-on: ubuntu-latest env: INTEGRATION_TEST: true + DEV_FEATURES_ENABLED: true DB_URL: postgres://postgres:postgres@localhost:5432/postgres steps: diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 0fd1557db..ec47c5a7e 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -16,6 +16,7 @@ jobs: runs-on: ubuntu-latest env: INTEGRATION_TEST: true + DEV_FEATURES_ENABLED: true steps: - uses: logto-io/actions-package-logto-artifact@v2 @@ -32,6 +33,7 @@ jobs: runs-on: ubuntu-latest env: INTEGRATION_TEST: true + DEV_FEATURES_ENABLED: true DB_URL: postgres://postgres:postgres@localhost:5432/postgres steps: diff --git a/packages/console/src/consts/env.ts b/packages/console/src/consts/env.ts index 11da2ead1..7b26d4d59 100644 --- a/packages/console/src/consts/env.ts +++ b/packages/console/src/consts/env.ts @@ -9,5 +9,4 @@ export const adminEndpoint = process.env.ADMIN_ENDPOINT; export const isDevFeaturesEnabled = !isProduction || yes(process.env.DEV_FEATURES_ENABLED) || - yes(process.env.INTEGRATION_TEST) || yes(localStorage.getItem(storageKeys.isDevFeaturesEnabled)); diff --git a/packages/experience/src/constants/env.ts b/packages/experience/src/constants/env.ts index 85636912e..d30c92c95 100644 --- a/packages/experience/src/constants/env.ts +++ b/packages/experience/src/constants/env.ts @@ -1,6 +1,4 @@ import { yes } from '@silverhand/essentials'; export const isDevFeaturesEnabled = - process.env.NODE_ENV !== 'production' || - yes(process.env.DEV_FEATURES_ENABLED) || - yes(process.env.INTEGRATION_TEST); + process.env.NODE_ENV !== 'production' || yes(process.env.DEV_FEATURES_ENABLED); diff --git a/packages/integration-tests/src/constants.ts b/packages/integration-tests/src/constants.ts index a947f4548..9b8232ebd 100644 --- a/packages/integration-tests/src/constants.ts +++ b/packages/integration-tests/src/constants.ts @@ -1,10 +1,10 @@ import { - type CreateSsoConnector, SignInIdentifier, SsoProviderName, demoAppApplicationId, + type CreateSsoConnector, } from '@logto/schemas'; -import { appendPath, getEnv } from '@silverhand/essentials'; +import { appendPath, getEnv, yes } from '@silverhand/essentials'; export const logtoUrl = getEnv('INTEGRATION_TESTS_LOGTO_URL', 'http://localhost:3001'); export const logtoOidcUrl = appendPath(new URL(logtoUrl), 'oidc').toString(); @@ -47,3 +47,5 @@ export const newOidcSsoConnectorPayload = { issuer: `${logtoUrl}/oidc`, }, } satisfies Partial; + +export const isDevFeaturesEnabled = yes(getEnv('DEV_FEATURES_ENABLED')); diff --git a/packages/integration-tests/src/tests/console/bootstrap.test.ts b/packages/integration-tests/src/tests/console/bootstrap.test.ts index aafb73769..103872cee 100644 --- a/packages/integration-tests/src/tests/console/bootstrap.test.ts +++ b/packages/integration-tests/src/tests/console/bootstrap.test.ts @@ -5,6 +5,7 @@ import { authedAdminTenantApi } from '#src/api/api.js'; import { consolePassword, consoleUsername, + isDevFeaturesEnabled, logtoConsoleUrl as logtoConsoleUrlString, } from '#src/constants.js'; import { appendPathname, cls, dcls, expectNavigation, waitFor } from '#src/utils.js'; @@ -135,4 +136,10 @@ describe('smoke testing for console admin account creation and sign-in', () => { ); await expect(page).toMatchElement(activeSelector, { text: 'Dashboard', visible: true }); }); + + it(`should ${isDevFeaturesEnabled ? '' : 'not '}show the dev features label`, async () => { + await (isDevFeaturesEnabled + ? expect(page).toMatchElement('div', { text: 'Dev features enabled' }) + : expect(page).not.toMatchElement('div', { text: 'Dev features enabled' })); + }); }); diff --git a/packages/shared/src/node/env/GlobalValues.ts b/packages/shared/src/node/env/GlobalValues.ts index 4ad50bb34..3ccd58895 100644 --- a/packages/shared/src/node/env/GlobalValues.ts +++ b/packages/shared/src/node/env/GlobalValues.ts @@ -7,8 +7,7 @@ export default class GlobalValues { public readonly isProduction = getEnv('NODE_ENV') === 'production'; public readonly isIntegrationTest = yes(getEnv('INTEGRATION_TEST')); public readonly isUnitTest = getEnv('NODE_ENV') === 'test'; - public readonly isDevFeaturesEnabled = - !this.isProduction || yes(getEnv('DEV_FEATURES_ENABLED')) || this.isIntegrationTest; + public readonly isDevFeaturesEnabled = !this.isProduction || yes(getEnv('DEV_FEATURES_ENABLED')); public readonly httpsCert = process.env.HTTPS_CERT_PATH; public readonly httpsKey = process.env.HTTPS_KEY_PATH;