diff --git a/packages/plugin-e2e/src/fixtures/isFeatureToggleEnabled.ts b/packages/plugin-e2e/src/fixtures/isFeatureToggleEnabled.ts index 10a670826..6ba9f2c46 100644 --- a/packages/plugin-e2e/src/fixtures/isFeatureToggleEnabled.ts +++ b/packages/plugin-e2e/src/fixtures/isFeatureToggleEnabled.ts @@ -7,7 +7,7 @@ type FeatureToggleFixture = TestFixture< PluginFixture & PluginOptions & PlaywrightCombinedArgs >; -const isFeatureToggleEnabled: FeatureToggleFixture = async ({ page }, use) => { +const isFeatureToggleEnabled: FeatureToggleFixture = async ({ page, grafanaVersion }, use) => { await use(async (featureToggle: keyof T) => { const featureToggles: T = await page.evaluate('window.grafanaBootData.settings.featureToggles'); return Boolean(featureToggles[featureToggle]); diff --git a/packages/plugin-e2e/src/fixtures/page.ts b/packages/plugin-e2e/src/fixtures/page.ts index 79ef9bafa..23b8b4828 100644 --- a/packages/plugin-e2e/src/fixtures/page.ts +++ b/packages/plugin-e2e/src/fixtures/page.ts @@ -24,6 +24,7 @@ const page: PageFixture = async ({ page, featureToggles }, use) => { console.error('Failed to set feature toggles', error); } } + await page.goto('/'); await use(page); }; diff --git a/packages/plugin-e2e/src/fixtures/scripts/overrideFeatureToggles.js b/packages/plugin-e2e/src/fixtures/scripts/overrideFeatureToggles.js index fc1dd7053..8eec03a66 100644 --- a/packages/plugin-e2e/src/fixtures/scripts/overrideFeatureToggles.js +++ b/packages/plugin-e2e/src/fixtures/scripts/overrideFeatureToggles.js @@ -1,7 +1,6 @@ // this script is evaluated in the browser context, so we cannot use typescript export const overrideFeatureToggles = (featureToggles) => { const timeout = 5; - const localStorageKey = 'grafana.featureToggles'; const waitForGrafanaBootData = (cb) => { if (window.grafanaBootData) { @@ -11,28 +10,14 @@ export const overrideFeatureToggles = (featureToggles) => { } }; - const versionGte = (version, major, minor) => { - const [majorVersion, minorVersion] = version.split('.'); - return Number(majorVersion) >= major && Number(minorVersion) >= minor; - }; - // wait for Grafana boot data to be added to the window object waitForGrafanaBootData(() => { const version = window?.grafanaBootData?.settings?.buildInfo?.version; - // since Grafana 10.1.0, Grafana reads feature toggles from localStorage - // since this script runs in the browser context, we don't have access to semver.gte function that is used in other places of this package - if (versionGte(version, 10, 1)) { - const value = Object.entries(featureToggles) - .map(([key, value]) => `${key}=${value}`) - .join(','); - localStorage.setItem(localStorageKey, value); - } else { - // override feature toggles with the ones provided by the test - window.grafanaBootData.settings.featureToggles = { - ...window.grafanaBootData.settings.featureToggles, - ...featureToggles, - }; - } + // override feature toggles with the ones provided by the test + window.grafanaBootData.settings.featureToggles = { + ...window.grafanaBootData.settings.featureToggles, + ...featureToggles, + }; }); }; diff --git a/packages/plugin-e2e/tests/datasource/feature-toggles/queryEditor.async.spec.ts b/packages/plugin-e2e/tests/datasource/feature-toggles/queryEditor.async.spec.ts index 93fa9e668..ecac98b1d 100644 --- a/packages/plugin-e2e/tests/datasource/feature-toggles/queryEditor.async.spec.ts +++ b/packages/plugin-e2e/tests/datasource/feature-toggles/queryEditor.async.spec.ts @@ -1,13 +1,22 @@ import { expect, test } from '../../../src'; import { ProvisionFile } from '../../../src/types'; +const TRUTHY_CUSTOM_TOGGLE = 'custom_toggle1'; +const FALSY_CUSTOM_TOGGLE = 'custom_toggle2'; // override the feature toggles defined in playwright.config.ts only for tests in this file test.use({ featureToggles: { redshiftAsyncQueryDataSupport: true, + [TRUTHY_CUSTOM_TOGGLE]: true, + [FALSY_CUSTOM_TOGGLE]: false, }, }); +test('should set feature toggles correctly', async ({ isFeatureToggleEnabled }) => { + expect(await isFeatureToggleEnabled(TRUTHY_CUSTOM_TOGGLE)).toBeTruthy(); + expect(await isFeatureToggleEnabled(FALSY_CUSTOM_TOGGLE)).toBeFalsy(); +}); + test('async query data handler should return a `finished` status', async ({ selectors, panelEditPage,