diff --git a/src/feature-flags.test.ts b/src/feature-flags.test.ts index da4b09719..96e019347 100644 --- a/src/feature-flags.test.ts +++ b/src/feature-flags.test.ts @@ -14,8 +14,10 @@ import { setUpFeatureFlagTests, getFeatureIncludingCodeQlIfRequired, assertAllFeaturesUndefinedInApi, + assertAllFeaturesHaveDefaultValues, } from "./feature-flags/testing-util"; import { + checkExpectedLogMessages, getRecordingLogger, initializeFeatures, LoggedMessage, @@ -33,7 +35,7 @@ test.beforeEach(() => { initializeEnvironment("1.2.3"); }); -test(`All features are disabled if running against GHES`, async (t) => { +test(`All features use default values if running against GHES`, async (t) => { await withTmpDir(async (tmpDir) => { const loggedMessages = []; const features = setUpFeatureFlagTests( @@ -42,21 +44,10 @@ test(`All features are disabled if running against GHES`, async (t) => { { type: GitHubVariant.GHES, version: "3.0.0" }, ); - for (const feature of Object.values(Feature)) { - t.deepEqual( - await getFeatureIncludingCodeQlIfRequired(features, feature), - featureConfig[feature].defaultValue, - ); - } - - t.assert( - loggedMessages.find( - (v: LoggedMessage) => - v.type === "debug" && - v.message === - "Not running against github.com. Disabling all toggleable features.", - ) !== undefined, - ); + await assertAllFeaturesHaveDefaultValues(t, features); + checkExpectedLogMessages(t, loggedMessages, [ + "Not running against github.com. Using default values for all features.", + ]); }); }); diff --git a/src/feature-flags/offline-features.test.ts b/src/feature-flags/offline-features.test.ts index fac7686fa..433d80644 100644 --- a/src/feature-flags/offline-features.test.ts +++ b/src/feature-flags/offline-features.test.ts @@ -2,12 +2,17 @@ import test from "ava"; import * as sinon from "sinon"; import * as apiClient from "../api-client"; -import { Feature, featureConfig } from "../feature-flags"; -import { mockCCR, setupTests } from "../testing-utils"; +import { + checkExpectedLogMessages, + getRecordingLogger, + LoggedMessage, + mockCCR, + setupTests, +} from "../testing-utils"; import { initializeEnvironment, withTmpDir } from "../util"; import { - getFeatureIncludingCodeQlIfRequired, + assertAllFeaturesHaveDefaultValues, setUpFeatureFlagTests, } from "./testing-util"; @@ -20,18 +25,18 @@ test.beforeEach(() => { test("OfflineFeatures makes no API requests", async (t) => { await withTmpDir(async (tmpDir) => { - const features = setUpFeatureFlagTests(tmpDir); + const loggedMessages: LoggedMessage[] = []; + const logger = getRecordingLogger(loggedMessages); + const features = setUpFeatureFlagTests(tmpDir, logger); t.is("OfflineFeatures", features.constructor.name); sinon .stub(apiClient, "getApiClient") .throws(new Error("Should not have called getApiClient")); - for (const feature of Object.values(Feature)) { - t.deepEqual( - await getFeatureIncludingCodeQlIfRequired(features, feature), - featureConfig[feature].defaultValue, - ); - } + await assertAllFeaturesHaveDefaultValues(t, features); + checkExpectedLogMessages(t, loggedMessages, [ + "Querying feature flags is not currently supported in Copilot Code Review. Using offline data for all features.", + ]); }); }); diff --git a/src/feature-flags/testing-util.ts b/src/feature-flags/testing-util.ts index 91596c416..202f2c97b 100644 --- a/src/feature-flags/testing-util.ts +++ b/src/feature-flags/testing-util.ts @@ -21,6 +21,18 @@ import * as util from "../util"; const testRepositoryNwo = parseRepositoryNwo("github/example"); +export async function assertAllFeaturesHaveDefaultValues( + t: ExecutionContext, + features: FeatureEnablement, +) { + for (const feature of Object.values(Feature)) { + t.deepEqual( + await getFeatureIncludingCodeQlIfRequired(features, feature), + featureConfig[feature].defaultValue, + ); + } +} + export function assertAllFeaturesUndefinedInApi( t: ExecutionContext, loggedMessages: LoggedMessage[],