From bc76ceafafa5c2d0ae4d01fe72514904a2467842 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Thu, 12 Feb 2026 18:35:09 +0000 Subject: [PATCH] Add test to check that OfflineFeatures doesn't use the API client --- src/feature-flags/offline-features.test.ts | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/feature-flags/offline-features.test.ts diff --git a/src/feature-flags/offline-features.test.ts b/src/feature-flags/offline-features.test.ts new file mode 100644 index 000000000..fac7686fa --- /dev/null +++ b/src/feature-flags/offline-features.test.ts @@ -0,0 +1,37 @@ +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 { initializeEnvironment, withTmpDir } from "../util"; + +import { + getFeatureIncludingCodeQlIfRequired, + setUpFeatureFlagTests, +} from "./testing-util"; + +setupTests(test); + +test.beforeEach(() => { + initializeEnvironment("1.2.3"); + mockCCR(); +}); + +test("OfflineFeatures makes no API requests", async (t) => { + await withTmpDir(async (tmpDir) => { + const features = setUpFeatureFlagTests(tmpDir); + 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, + ); + } + }); +});