0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

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
This commit is contained in:
simeng-li 2024-06-17 10:30:16 +08:00 committed by GitHub
parent a02c20a664
commit ed37356ee3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 17 additions and 8 deletions

View file

@ -50,6 +50,7 @@ jobs:
if: ${{needs.check-alteration-changes.outputs.has-alteration-changes == 'true'}} if: ${{needs.check-alteration-changes.outputs.has-alteration-changes == 'true'}}
env: env:
INTEGRATION_TEST: true INTEGRATION_TEST: true
DEV_FEATURES_ENABLED: true
steps: steps:
- uses: logto-io/actions-package-logto-artifact@v2 - uses: logto-io/actions-package-logto-artifact@v2
with: with:
@ -66,6 +67,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
INTEGRATION_TEST: true INTEGRATION_TEST: true
DEV_FEATURES_ENABLED: true
DB_URL: postgres://postgres:postgres@localhost:5432/postgres DB_URL: postgres://postgres:postgres@localhost:5432/postgres
steps: steps:

View file

@ -16,6 +16,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
INTEGRATION_TEST: true INTEGRATION_TEST: true
DEV_FEATURES_ENABLED: true
steps: steps:
- uses: logto-io/actions-package-logto-artifact@v2 - uses: logto-io/actions-package-logto-artifact@v2
@ -32,6 +33,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
INTEGRATION_TEST: true INTEGRATION_TEST: true
DEV_FEATURES_ENABLED: true
DB_URL: postgres://postgres:postgres@localhost:5432/postgres DB_URL: postgres://postgres:postgres@localhost:5432/postgres
steps: steps:

View file

@ -9,5 +9,4 @@ export const adminEndpoint = process.env.ADMIN_ENDPOINT;
export const isDevFeaturesEnabled = export const isDevFeaturesEnabled =
!isProduction || !isProduction ||
yes(process.env.DEV_FEATURES_ENABLED) || yes(process.env.DEV_FEATURES_ENABLED) ||
yes(process.env.INTEGRATION_TEST) ||
yes(localStorage.getItem(storageKeys.isDevFeaturesEnabled)); yes(localStorage.getItem(storageKeys.isDevFeaturesEnabled));

View file

@ -1,6 +1,4 @@
import { yes } from '@silverhand/essentials'; import { yes } from '@silverhand/essentials';
export const isDevFeaturesEnabled = export const isDevFeaturesEnabled =
process.env.NODE_ENV !== 'production' || process.env.NODE_ENV !== 'production' || yes(process.env.DEV_FEATURES_ENABLED);
yes(process.env.DEV_FEATURES_ENABLED) ||
yes(process.env.INTEGRATION_TEST);

View file

@ -1,10 +1,10 @@
import { import {
type CreateSsoConnector,
SignInIdentifier, SignInIdentifier,
SsoProviderName, SsoProviderName,
demoAppApplicationId, demoAppApplicationId,
type CreateSsoConnector,
} from '@logto/schemas'; } 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 logtoUrl = getEnv('INTEGRATION_TESTS_LOGTO_URL', 'http://localhost:3001');
export const logtoOidcUrl = appendPath(new URL(logtoUrl), 'oidc').toString(); export const logtoOidcUrl = appendPath(new URL(logtoUrl), 'oidc').toString();
@ -47,3 +47,5 @@ export const newOidcSsoConnectorPayload = {
issuer: `${logtoUrl}/oidc`, issuer: `${logtoUrl}/oidc`,
}, },
} satisfies Partial<CreateSsoConnector>; } satisfies Partial<CreateSsoConnector>;
export const isDevFeaturesEnabled = yes(getEnv('DEV_FEATURES_ENABLED'));

View file

@ -5,6 +5,7 @@ import { authedAdminTenantApi } from '#src/api/api.js';
import { import {
consolePassword, consolePassword,
consoleUsername, consoleUsername,
isDevFeaturesEnabled,
logtoConsoleUrl as logtoConsoleUrlString, logtoConsoleUrl as logtoConsoleUrlString,
} from '#src/constants.js'; } from '#src/constants.js';
import { appendPathname, cls, dcls, expectNavigation, waitFor } from '#src/utils.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 }); 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' }));
});
}); });

View file

@ -7,8 +7,7 @@ export default class GlobalValues {
public readonly isProduction = getEnv('NODE_ENV') === 'production'; public readonly isProduction = getEnv('NODE_ENV') === 'production';
public readonly isIntegrationTest = yes(getEnv('INTEGRATION_TEST')); public readonly isIntegrationTest = yes(getEnv('INTEGRATION_TEST'));
public readonly isUnitTest = getEnv('NODE_ENV') === 'test'; public readonly isUnitTest = getEnv('NODE_ENV') === 'test';
public readonly isDevFeaturesEnabled = public readonly isDevFeaturesEnabled = !this.isProduction || yes(getEnv('DEV_FEATURES_ENABLED'));
!this.isProduction || yes(getEnv('DEV_FEATURES_ENABLED')) || this.isIntegrationTest;
public readonly httpsCert = process.env.HTTPS_CERT_PATH; public readonly httpsCert = process.env.HTTPS_CERT_PATH;
public readonly httpsKey = process.env.HTTPS_KEY_PATH; public readonly httpsKey = process.env.HTTPS_KEY_PATH;