Restore test improvements from previous PR

This commit is contained in:
Michael B. Gale
2026-02-15 15:57:02 +00:00
parent 60dee3dbd3
commit 7af50a43c1
3 changed files with 34 additions and 26 deletions
+7 -16
View File
@@ -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.",
]);
});
});
+15 -10
View File
@@ -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.",
]);
});
});
+12
View File
@@ -21,6 +21,18 @@ import * as util from "../util";
const testRepositoryNwo = parseRepositoryNwo("github/example");
export async function assertAllFeaturesHaveDefaultValues(
t: ExecutionContext<unknown>,
features: FeatureEnablement,
) {
for (const feature of Object.values(Feature)) {
t.deepEqual(
await getFeatureIncludingCodeQlIfRequired(features, feature),
featureConfig[feature].defaultValue,
);
}
}
export function assertAllFeaturesUndefinedInApi(
t: ExecutionContext<unknown>,
loggedMessages: LoggedMessage[],