Add test to check that OfflineFeatures doesn't use the API client

This commit is contained in:
Michael B. Gale
2026-02-12 18:35:09 +00:00
parent 377300bcda
commit bc76ceafaf
@@ -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,
);
}
});
});