Skip to content

Commit 7af50a4

Browse files
committed
Restore test improvements from previous PR
1 parent 60dee3d commit 7af50a4

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

src/feature-flags.test.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import {
1414
setUpFeatureFlagTests,
1515
getFeatureIncludingCodeQlIfRequired,
1616
assertAllFeaturesUndefinedInApi,
17+
assertAllFeaturesHaveDefaultValues,
1718
} from "./feature-flags/testing-util";
1819
import {
20+
checkExpectedLogMessages,
1921
getRecordingLogger,
2022
initializeFeatures,
2123
LoggedMessage,
@@ -33,7 +35,7 @@ test.beforeEach(() => {
3335
initializeEnvironment("1.2.3");
3436
});
3537

36-
test(`All features are disabled if running against GHES`, async (t) => {
38+
test(`All features use default values if running against GHES`, async (t) => {
3739
await withTmpDir(async (tmpDir) => {
3840
const loggedMessages = [];
3941
const features = setUpFeatureFlagTests(
@@ -42,21 +44,10 @@ test(`All features are disabled if running against GHES`, async (t) => {
4244
{ type: GitHubVariant.GHES, version: "3.0.0" },
4345
);
4446

45-
for (const feature of Object.values(Feature)) {
46-
t.deepEqual(
47-
await getFeatureIncludingCodeQlIfRequired(features, feature),
48-
featureConfig[feature].defaultValue,
49-
);
50-
}
51-
52-
t.assert(
53-
loggedMessages.find(
54-
(v: LoggedMessage) =>
55-
v.type === "debug" &&
56-
v.message ===
57-
"Not running against github.com. Disabling all toggleable features.",
58-
) !== undefined,
59-
);
47+
await assertAllFeaturesHaveDefaultValues(t, features);
48+
checkExpectedLogMessages(t, loggedMessages, [
49+
"Not running against github.com. Using default values for all features.",
50+
]);
6051
});
6152
});
6253

src/feature-flags/offline-features.test.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import test from "ava";
22
import * as sinon from "sinon";
33

44
import * as apiClient from "../api-client";
5-
import { Feature, featureConfig } from "../feature-flags";
6-
import { mockCCR, setupTests } from "../testing-utils";
5+
import {
6+
checkExpectedLogMessages,
7+
getRecordingLogger,
8+
LoggedMessage,
9+
mockCCR,
10+
setupTests,
11+
} from "../testing-utils";
712
import { initializeEnvironment, withTmpDir } from "../util";
813

914
import {
10-
getFeatureIncludingCodeQlIfRequired,
15+
assertAllFeaturesHaveDefaultValues,
1116
setUpFeatureFlagTests,
1217
} from "./testing-util";
1318

@@ -20,18 +25,18 @@ test.beforeEach(() => {
2025

2126
test("OfflineFeatures makes no API requests", async (t) => {
2227
await withTmpDir(async (tmpDir) => {
23-
const features = setUpFeatureFlagTests(tmpDir);
28+
const loggedMessages: LoggedMessage[] = [];
29+
const logger = getRecordingLogger(loggedMessages);
30+
const features = setUpFeatureFlagTests(tmpDir, logger);
2431
t.is("OfflineFeatures", features.constructor.name);
2532

2633
sinon
2734
.stub(apiClient, "getApiClient")
2835
.throws(new Error("Should not have called getApiClient"));
2936

30-
for (const feature of Object.values(Feature)) {
31-
t.deepEqual(
32-
await getFeatureIncludingCodeQlIfRequired(features, feature),
33-
featureConfig[feature].defaultValue,
34-
);
35-
}
37+
await assertAllFeaturesHaveDefaultValues(t, features);
38+
checkExpectedLogMessages(t, loggedMessages, [
39+
"Querying feature flags is not currently supported in Copilot Code Review. Using offline data for all features.",
40+
]);
3641
});
3742
});

src/feature-flags/testing-util.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ import * as util from "../util";
2121

2222
const testRepositoryNwo = parseRepositoryNwo("github/example");
2323

24+
export async function assertAllFeaturesHaveDefaultValues(
25+
t: ExecutionContext<unknown>,
26+
features: FeatureEnablement,
27+
) {
28+
for (const feature of Object.values(Feature)) {
29+
t.deepEqual(
30+
await getFeatureIncludingCodeQlIfRequired(features, feature),
31+
featureConfig[feature].defaultValue,
32+
);
33+
}
34+
}
35+
2436
export function assertAllFeaturesUndefinedInApi(
2537
t: ExecutionContext<unknown>,
2638
loggedMessages: LoggedMessage[],

0 commit comments

Comments
 (0)